From 2fcc67e8765071275f60293edbff4dcead4a834c Mon Sep 17 00:00:00 2001 From: Arthur Uzulin Date: Mon, 28 Oct 2013 23:12:41 +1100 Subject: [PATCH] Custom firework rocket for landmines (WIP) - Made the firework rocket impossible to dismount - Made the firework rocket inflict a large amount of damage to the player upon explosion - Moved DamageSourceLandmine to it's appropriate place - Fixed the landmine death localization *blames Sunstrike* --- resources/assets/tinker/lang/en_US.lang | 3 + src/tconstruct/client/TProxyClient.java | 4 +- src/tconstruct/common/TContent.java | 5 +- .../entity/item/EntityLandmineFirework.java | 215 ++++++++++++++++++ .../util/DamageSourceFireworkExplode.java | 21 ++ .../{network => }/DamageSourceLandmine.java | 2 +- .../landmine/behavior/BehaviorDefault.java | 3 +- .../landmine/behavior/BehaviorFirework.java | 10 +- 8 files changed, 253 insertions(+), 10 deletions(-) create mode 100644 src/tconstruct/entity/item/EntityLandmineFirework.java create mode 100644 src/tconstruct/util/DamageSourceFireworkExplode.java rename src/tconstruct/util/{network => }/DamageSourceLandmine.java (93%) diff --git a/resources/assets/tinker/lang/en_US.lang b/resources/assets/tinker/lang/en_US.lang index 92d5ed31..88ab1940 100644 --- a/resources/assets/tinker/lang/en_US.lang +++ b/resources/assets/tinker/lang/en_US.lang @@ -488,6 +488,9 @@ death.two.smeltery=%1$s has fused with the Smeltery death.three.smeltery=%1$s will be a stepping stone for our revolution! death.four.smeltery=%1$s thought swimming in hot liquids was a good idea +death.attack.Landmine=%1$s watched their legs get blown off by a landmine +death.attack.FireworkExplode=%1$s was torn apart by a wild firework explosion + parttype.wood=Wooden parttype.stone=Stone parttype.iron=Iron diff --git a/src/tconstruct/client/TProxyClient.java b/src/tconstruct/client/TProxyClient.java index ae1cb298..9985b8d7 100644 --- a/src/tconstruct/client/TProxyClient.java +++ b/src/tconstruct/client/TProxyClient.java @@ -14,7 +14,7 @@ import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.model.ModelSlime; import net.minecraft.client.particle.*; import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.*; import net.minecraft.client.settings.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.*; @@ -36,6 +36,7 @@ import tconstruct.client.pages.*; import tconstruct.client.tabs.*; import tconstruct.common.*; import tconstruct.entity.*; +import tconstruct.entity.item.EntityLandmineFirework; import tconstruct.entity.projectile.*; import tconstruct.inventory.ContainerLandmine; import tconstruct.library.TConstructRegistry; @@ -230,6 +231,7 @@ public class TProxyClient extends TProxyCommon RenderingRegistry.registerEntityRenderingHandler(LaunchedPotion.class, new LaunchedItemRender(Item.potion, 16384)); RenderingRegistry.registerEntityRenderingHandler(DaggerEntity.class, new DaggerRenderCustom()); RenderingRegistry.registerEntityRenderingHandler(ArrowEntity.class, new ArrowRenderCustom()); + RenderingRegistry.registerEntityRenderingHandler(EntityLandmineFirework.class, new RenderSnowball(Item.firework)); // RenderingRegistry.registerEntityRenderingHandler(net.minecraft.entity.player.EntityPlayer.class, // new PlayerArmorRender()); // <-- Works, woo! diff --git a/src/tconstruct/common/TContent.java b/src/tconstruct/common/TContent.java index 89d9dcc1..1ae61aff 100644 --- a/src/tconstruct/common/TContent.java +++ b/src/tconstruct/common/TContent.java @@ -3,10 +3,8 @@ package tconstruct.common; import cpw.mods.fml.common.*; import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.registry.*; - import java.lang.reflect.Field; import java.util.*; - import net.minecraft.block.*; import net.minecraft.block.material.*; import net.minecraft.creativetab.CreativeTabs; @@ -26,13 +24,13 @@ import tconstruct.blocks.slime.*; import tconstruct.blocks.traps.*; import tconstruct.client.StepSoundSlime; import tconstruct.entity.*; +import tconstruct.entity.item.EntityLandmineFirework; import tconstruct.entity.projectile.*; import tconstruct.items.*; import tconstruct.items.armor.*; import tconstruct.items.blocks.*; import tconstruct.items.tools.*; import tconstruct.library.TConstructRegistry; -import tconstruct.library.armor.EnumArmorPart; import tconstruct.library.client.*; import tconstruct.library.client.FluidRenderProperties.Applications; import tconstruct.library.crafting.*; @@ -299,6 +297,7 @@ public class TContent implements IFuelHandler EntityRegistry.registerModEntity(Crystal.class, "Crystal", 2, TConstruct.instance, 32, 3, true); EntityRegistry.registerModEntity(LaunchedPotion.class, "Launched Potion", 3, TConstruct.instance, 32, 3, true); EntityRegistry.registerModEntity(ArrowEntity.class, "Arrow", 4, TConstruct.instance, 32, 5, true); + EntityRegistry.registerModEntity(EntityLandmineFirework.class, "LandmineFirework", 5, TConstruct.instance, 32, 5, true); //EntityRegistry.registerModEntity(CartEntity.class, "Small Wagon", 1, TConstruct.instance, 32, 5, true); EntityRegistry.registerModEntity(BlueSlime.class, "EdibleSlime", 12, TConstruct.instance, 64, 5, true); diff --git a/src/tconstruct/entity/item/EntityLandmineFirework.java b/src/tconstruct/entity/item/EntityLandmineFirework.java new file mode 100644 index 00000000..f5014ab1 --- /dev/null +++ b/src/tconstruct/entity/item/EntityLandmineFirework.java @@ -0,0 +1,215 @@ +package tconstruct.entity.item; + +import tconstruct.util.DamageSourceFireworkExplode; + +import cpw.mods.fml.relauncher.*; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +public class EntityLandmineFirework extends Entity { + /** The age of the firework in ticks. */ + private int fireworkAge; + + /** + * The lifetime of the firework in ticks. When the age reaches the lifetime the firework explodes. + */ + private int lifetime; + + private Entity rider; + + private int moveDirection = 0; + + public EntityLandmineFirework(World par1World) { + super(par1World); + this.setSize(0.25F, 0.25F); + } + + protected void entityInit() { + this.dataWatcher.addObjectByDataType(8, 5); + } + + public EntityLandmineFirework setRider(Entity entity){ + rider = entity; + return this; + } + + @SideOnly(Side.CLIENT) + /** + * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge + * length * 64 * renderDistanceWeight Args: distance + */ + public boolean isInRangeToRenderDist(double par1) { + return par1 < 4096.0D; + } + + public EntityLandmineFirework(World par1World, double par2, double par4, double par6, ItemStack par8ItemStack, int moveDirection) { + super(par1World); + this.fireworkAge = 0; + this.setSize(0.25F, 0.25F); + this.setPosition(par2, par4, par6); + this.yOffset = 0.0F; + int i = 1; + + if (par8ItemStack != null && par8ItemStack.hasTagCompound()) { + this.dataWatcher.updateObject(8, par8ItemStack); + NBTTagCompound nbttagcompound = par8ItemStack.getTagCompound(); + NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("Fireworks"); + + if (nbttagcompound1 != null) { + i += nbttagcompound1.getByte("Flight"); + } + } + + this.motionX = this.rand.nextGaussian() * 0.001D; + this.motionZ = this.rand.nextGaussian() * 0.001D; + this.motionY = 0.05D; + this.lifetime = 10 * i + this.rand.nextInt(6) + this.rand.nextInt(7); + this.moveDirection = moveDirection; + } + + @SideOnly(Side.CLIENT) + /** + * Sets the velocity to the args. Args: x, y, z + */ + public void setVelocity(double par1, double par3, double par5) { + this.motionX = par1; + this.motionY = par3; + this.motionZ = par5; + + if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { + float f = MathHelper.sqrt_double(par1 * par1 + par5 * par5); + this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(par1, par5) * 180.0D / Math.PI); + this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(par3, (double) f) * 180.0D / Math.PI); + } + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() { + if(this.riddenByEntity == null && this.rider != null){ + this.rider.mountEntity(this); + } + + this.lastTickPosX = this.posX; + this.lastTickPosY = this.posY; + this.lastTickPosZ = this.posZ; + super.onUpdate(); + this.motionX *= 1.15D; + this.motionZ *= 1.15D; + this.motionY += 0.04D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); + this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); + + for (this.rotationPitch = (float) (Math.atan2(this.motionY, (double) f) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { + ; + } + + while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { + this.prevRotationPitch += 360.0F; + } + + while (this.rotationYaw - this.prevRotationYaw < -180.0F) { + this.prevRotationYaw -= 360.0F; + } + + while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { + this.prevRotationYaw += 360.0F; + } + + this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; + this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; + + if (this.fireworkAge == 0) { + this.worldObj.playSoundAtEntity(this, "fireworks.launch", 3.0F, 1.0F); + } + + ++this.fireworkAge; + + if (this.worldObj.isRemote && this.fireworkAge % 2 < 2) { + this.worldObj.spawnParticle("fireworksSpark", this.posX, this.posY - 0.3D, this.posZ, this.rand.nextGaussian() * 0.05D, -this.motionY * 0.5D, this.rand.nextGaussian() * 0.05D); + } + + if (!this.worldObj.isRemote && this.fireworkAge > this.lifetime) { + this.worldObj.setEntityState(this, (byte) 17); + this.rider.attackEntityFrom(new DamageSourceFireworkExplode("FireworkExplode"), 200F); + this.setDead(); + } + } + + @SideOnly(Side.CLIENT) + public void handleHealthUpdate(byte par1) { + if (par1 == 17 && this.worldObj.isRemote) { + ItemStack itemstack = this.dataWatcher.getWatchableObjectItemStack(8); + NBTTagCompound nbttagcompound = null; + + if (itemstack != null && itemstack.hasTagCompound()) { + nbttagcompound = itemstack.getTagCompound().getCompoundTag("Fireworks"); + } + + this.worldObj.func_92088_a(this.posX, this.posY, this.posZ, this.motionX, this.motionY, this.motionZ, nbttagcompound); + } + + super.handleHealthUpdate(par1); + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { + par1NBTTagCompound.setInteger("Life", this.fireworkAge); + par1NBTTagCompound.setInteger("LifeTime", this.lifetime); + ItemStack itemstack = this.dataWatcher.getWatchableObjectItemStack(8); + + if (itemstack != null) { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + itemstack.writeToNBT(nbttagcompound1); + par1NBTTagCompound.setCompoundTag("FireworksItem", nbttagcompound1); + } + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { + this.fireworkAge = par1NBTTagCompound.getInteger("Life"); + this.lifetime = par1NBTTagCompound.getInteger("LifeTime"); + NBTTagCompound nbttagcompound1 = par1NBTTagCompound.getCompoundTag("FireworksItem"); + + if (nbttagcompound1 != null) { + ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound1); + + if (itemstack != null) { + this.dataWatcher.updateObject(8, itemstack); + } + } + } + + @SideOnly(Side.CLIENT) + public float getShadowSize() { + return 0.0F; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float par1) { + return super.getBrightness(par1); + } + + @SideOnly(Side.CLIENT) + public int getBrightnessForRender(float par1) { + return super.getBrightnessForRender(par1); + } + + /** + * If returns false, the item will not inflict any damage against entities. + */ + public boolean canAttackWithItem() { + return false; + } +} diff --git a/src/tconstruct/util/DamageSourceFireworkExplode.java b/src/tconstruct/util/DamageSourceFireworkExplode.java new file mode 100644 index 00000000..e465d36f --- /dev/null +++ b/src/tconstruct/util/DamageSourceFireworkExplode.java @@ -0,0 +1,21 @@ +package tconstruct.util; + +import net.minecraft.util.DamageSource; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ChatMessageComponent; + +public class DamageSourceFireworkExplode extends DamageSource{ + + public DamageSourceFireworkExplode(String s) + { + super(s); + this.setDamageBypassesArmor(); + } + + public ChatMessageComponent getDeathMessage (EntityLivingBase par1EntityLivingBase) + { + return super.getDeathMessage(par1EntityLivingBase); + } + +} diff --git a/src/tconstruct/util/network/DamageSourceLandmine.java b/src/tconstruct/util/DamageSourceLandmine.java similarity index 93% rename from src/tconstruct/util/network/DamageSourceLandmine.java rename to src/tconstruct/util/DamageSourceLandmine.java index 2d20557d..234bf4ae 100644 --- a/src/tconstruct/util/network/DamageSourceLandmine.java +++ b/src/tconstruct/util/DamageSourceLandmine.java @@ -1,4 +1,4 @@ -package tconstruct.util.network; +package tconstruct.util; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.ChatMessageComponent; diff --git a/src/tconstruct/util/landmine/behavior/BehaviorDefault.java b/src/tconstruct/util/landmine/behavior/BehaviorDefault.java index dfae8852..55603a94 100644 --- a/src/tconstruct/util/landmine/behavior/BehaviorDefault.java +++ b/src/tconstruct/util/landmine/behavior/BehaviorDefault.java @@ -1,9 +1,10 @@ package tconstruct.util.landmine.behavior; +import tconstruct.util.DamageSourceLandmine; + import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import tconstruct.util.network.DamageSourceLandmine; public class BehaviorDefault extends Behavior { diff --git a/src/tconstruct/util/landmine/behavior/BehaviorFirework.java b/src/tconstruct/util/landmine/behavior/BehaviorFirework.java index 9c60fc4e..d6e8a7a7 100644 --- a/src/tconstruct/util/landmine/behavior/BehaviorFirework.java +++ b/src/tconstruct/util/landmine/behavior/BehaviorFirework.java @@ -1,13 +1,12 @@ package tconstruct.util.landmine.behavior; -import java.util.List; +import net.minecraft.util.EnumFacing; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityFireworkRocket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import tconstruct.entity.item.EntityLandmineFirework; /** * @@ -20,9 +19,12 @@ public class BehaviorFirework extends Behavior @Override public void executeLogic (World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) { + EnumFacing facing = getFacing(par1World, par2, par3, par4); + for (int i = 0; i < par5ItemStack.stackSize; i++) { - EntityFireworkRocket entityfireworkrocket = new EntityFireworkRocket(par1World, (double) par2, (double) par3, (double) par4, par5ItemStack); + //TODO entity registration and stuffs + EntityLandmineFirework entityfireworkrocket = new EntityLandmineFirework(par1World, (double) par2, (double) par3, (double) par4, par5ItemStack, facing.ordinal()).setRider(i == 0 ? triggerer : null); par1World.spawnEntityInWorld(entityfireworkrocket); boolean shouldRun = true;