mirror of
https://github.com/chylex/Hardcore-Ender-Expansion-2.git
synced 2025-04-11 03:15:44 +02:00
Implement Token Holder charge & special territory-based behaviors
This commit is contained in:
parent
583a161276
commit
33cdadcf42
src/main/java/chylex/hee
client/render/entity
game
entity/item
world/territory
@ -13,6 +13,7 @@ import net.minecraft.client.renderer.entity.RenderManager
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraftforge.fml.relauncher.Side
|
||||
import net.minecraftforge.fml.relauncher.SideOnly
|
||||
import kotlin.math.pow
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
class RenderEntityTokenHolder(manager: RenderManager) : Render<EntityTokenHolder>(manager){
|
||||
@ -25,17 +26,21 @@ class RenderEntityTokenHolder(manager: RenderManager) : Render<EntityTokenHolder
|
||||
private val model = ModelEntityTokenHolder()
|
||||
|
||||
override fun doRender(entity: EntityTokenHolder, x: Double, y: Double, z: Double, rotationYaw: Float, partialTicks: Float){
|
||||
val charge = entity.renderCharge.get(partialTicks)
|
||||
val scale = 0.25F + (0.25F * charge.pow(1.5F))
|
||||
val alpha = 0.35F + (0.475F * charge.pow(5.5F))
|
||||
|
||||
GL.pushMatrix()
|
||||
GL.translate(x, y + (entity.height * 0.5F), z)
|
||||
|
||||
GL.pushMatrix()
|
||||
GL.scale(0.5F, 0.5F, 0.5F)
|
||||
GL.scale(scale, scale, scale)
|
||||
GL.rotate(entity.renderRotation.get(partialTicks), 0F, 1F, 0F)
|
||||
GL.rotate(55F, 1F, 0F, 1F)
|
||||
|
||||
GL.enableBlend()
|
||||
GL.blendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA)
|
||||
GL.color(1F, 1F, 1F, 0.825F)
|
||||
GL.color(1F, 1F, 1F, alpha)
|
||||
|
||||
bindEntityTexture(entity)
|
||||
model.render()
|
||||
|
@ -1,5 +1,7 @@
|
||||
package chylex.hee.game.entity.item
|
||||
import chylex.hee.game.entity.util.EntityData
|
||||
import chylex.hee.game.item.ItemPortalToken.TokenType
|
||||
import chylex.hee.game.world.territory.TerritoryInstance
|
||||
import chylex.hee.game.world.territory.TerritoryType
|
||||
import chylex.hee.init.ModItems
|
||||
import chylex.hee.network.client.PacketClientLaunchInstantly
|
||||
@ -17,6 +19,7 @@ import io.netty.buffer.ByteBuf
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.network.datasync.DataSerializers
|
||||
import net.minecraft.util.DamageSource
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.World
|
||||
@ -31,12 +34,20 @@ class EntityTokenHolder(world: World) : Entity(world), IEntityAdditionalSpawnDat
|
||||
this.territoryType = territoryType
|
||||
}
|
||||
|
||||
private companion object{
|
||||
private val DATA_CHARGE = EntityData.register<EntityTokenHolder, Float>(DataSerializers.FLOAT)
|
||||
}
|
||||
|
||||
val renderRotation = LerpedFloat(world.totalWorldTime * 3F)
|
||||
val renderCharge = LerpedFloat(1F)
|
||||
|
||||
var tokenType = TokenType.NORMAL
|
||||
private set
|
||||
|
||||
private var territoryType: TerritoryType? = null
|
||||
var territoryType: TerritoryType? = null
|
||||
private set
|
||||
|
||||
var currentCharge by EntityData(DATA_CHARGE)
|
||||
|
||||
init{
|
||||
setSize(0.55F, 0.675F)
|
||||
@ -44,14 +55,20 @@ class EntityTokenHolder(world: World) : Entity(world), IEntityAdditionalSpawnDat
|
||||
setNoGravity(true)
|
||||
}
|
||||
|
||||
override fun entityInit(){}
|
||||
override fun entityInit(){
|
||||
dataManager.register(DATA_CHARGE, 1F)
|
||||
}
|
||||
|
||||
override fun writeSpawnData(buffer: ByteBuf) = buffer.use {
|
||||
writeByte(tokenType.ordinal)
|
||||
writeShort(territoryType?.ordinal ?: -1)
|
||||
writeFloat(currentCharge)
|
||||
}
|
||||
|
||||
override fun readSpawnData(buffer: ByteBuf) = buffer.use {
|
||||
tokenType = TokenType.values().getOrElse(readByte().toInt()){ TokenType.NORMAL }
|
||||
territoryType = TerritoryType.values().getOrNull(readShort().toInt())
|
||||
renderCharge.updateImmediately(readFloat())
|
||||
}
|
||||
|
||||
override fun onUpdate(){
|
||||
@ -59,17 +76,26 @@ class EntityTokenHolder(world: World) : Entity(world), IEntityAdditionalSpawnDat
|
||||
|
||||
if (world.isRemote){
|
||||
renderRotation.update(world.totalWorldTime * 3F)
|
||||
renderCharge.update(currentCharge)
|
||||
}
|
||||
else{
|
||||
TerritoryInstance.fromPos(this)?.let { it.territory.desc.tokenHolders.onTick(this, it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun attackEntityFrom(source: DamageSource, amount: Float): Boolean{
|
||||
if (world.isRemote){
|
||||
if (world.isRemote || currentCharge < 1F){
|
||||
return false
|
||||
}
|
||||
|
||||
val player = source.immediateSource as? EntityPlayer
|
||||
|
||||
if (player != null){
|
||||
if (player.capabilities.isCreativeMode && player.isSneaking){
|
||||
setDead()
|
||||
return false
|
||||
}
|
||||
|
||||
val droppedToken = territoryType?.let { entityDropItem(ModItems.PORTAL_TOKEN.forTerritory(tokenType, it), (height * 0.5F) - 0.25F) }
|
||||
|
||||
if (droppedToken != null){
|
||||
@ -81,7 +107,7 @@ class EntityTokenHolder(world: World) : Entity(world), IEntityAdditionalSpawnDat
|
||||
}
|
||||
|
||||
// TODO fx
|
||||
setDead()
|
||||
TerritoryInstance.fromPos(this)?.let { it.territory.desc.tokenHolders.afterUse(this, it) }
|
||||
}
|
||||
|
||||
return false
|
||||
@ -90,11 +116,13 @@ class EntityTokenHolder(world: World) : Entity(world), IEntityAdditionalSpawnDat
|
||||
override fun writeEntityToNBT(nbt: NBTTagCompound) = with(nbt.heeTag){
|
||||
setEnum("Type", tokenType)
|
||||
setEnum("Territory", territoryType)
|
||||
setFloat("Charge", currentCharge)
|
||||
}
|
||||
|
||||
override fun readEntityFromNBT(nbt: NBTTagCompound) = with(nbt.heeTag){
|
||||
tokenType = getEnum<TokenType>("Type") ?: TokenType.NORMAL
|
||||
territoryType = getEnum<TerritoryType>("Territory")
|
||||
currentCharge = getFloat("Charge")
|
||||
}
|
||||
|
||||
override fun doesEntityNotTriggerPressurePlate() = true
|
||||
|
@ -1,8 +1,13 @@
|
||||
package chylex.hee.game.world.territory
|
||||
import chylex.hee.game.world.territory.properties.TerritoryColors
|
||||
import chylex.hee.game.world.territory.properties.TerritoryEnvironment
|
||||
import chylex.hee.game.world.territory.properties.TerritoryTokenHolders
|
||||
|
||||
interface ITerritoryDescription{
|
||||
val colors: TerritoryColors
|
||||
val environment: TerritoryEnvironment
|
||||
|
||||
@JvmDefault
|
||||
val tokenHolders: TerritoryTokenHolders
|
||||
get() = TerritoryTokenHolders.Default
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package chylex.hee.game.world.territory.properties
|
||||
import chylex.hee.game.entity.item.EntityTokenHolder
|
||||
import chylex.hee.game.world.territory.TerritoryInstance
|
||||
|
||||
abstract class TerritoryTokenHolders{
|
||||
object Default : TerritoryTokenHolders()
|
||||
|
||||
open fun onTick(holder: EntityTokenHolder, instance: TerritoryInstance){}
|
||||
|
||||
open fun afterUse(holder: EntityTokenHolder, instance: TerritoryInstance){
|
||||
holder.setDead()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user