| 1 | package net.minecraft.entity.item;
|
| 2 |
|
| 3 | import net.minecraft.block.BlockFurnace;
|
| 4 | import net.minecraft.block.state.IBlockState;
|
| 5 | import net.minecraft.entity.player.EntityPlayer;
|
| 6 | import net.minecraft.init.Blocks;
|
| 7 | import net.minecraft.init.Items;
|
| 8 | import net.minecraft.item.ItemStack;
|
| 9 | import net.minecraft.nbt.NBTTagCompound;
|
| 10 | import net.minecraft.util.BlockPos;
|
| 11 | import net.minecraft.util.DamageSource;
|
| 12 | import net.minecraft.util.EnumFacing;
|
| 13 | import net.minecraft.util.EnumParticleTypes;
|
| 14 | import net.minecraft.util.MathHelper;
|
| 15 | import net.minecraft.world.World;
|
| 16 |
|
| 17 | public class EntityMinecartFurnace extends EntityMinecart
|
| 18 | {
|
| 19 | private int fuel;
|
| 20 | public double pushX;
|
| 21 | public double pushZ;
|
| 22 |
|
| 23 | public EntityMinecartFurnace(World worldIn)
|
| 24 | {
|
| 25 | super(worldIn);
|
| 26 | }
|
| 27 |
|
| 28 | public EntityMinecartFurnace(World worldIn, double x, double y, double z)
|
| 29 | {
|
| 30 | super(worldIn, x, y, z);
|
| 31 | }
|
| 32 |
|
| 33 | public EntityMinecart.EnumMinecartType getMinecartType()
|
| 34 | {
|
| 35 | return EntityMinecart.EnumMinecartType.FURNACE;
|
| 36 | }
|
| 37 |
|
| 38 | protected void entityInit()
|
| 39 | {
|
| 40 | super.entityInit();
|
| 41 | this.dataWatcher.addObject(16, new Byte((byte)0));
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Called to update the entity's position/logic.
|
| 46 | */
|
| 47 | public void onUpdate()
|
| 48 | {
|
| 49 | super.onUpdate();
|
| 50 |
|
| 51 | if (this.fuel > 0)
|
| 52 | {
|
| 53 | --this.fuel;
|
| 54 | }
|
| 55 |
|
| 56 | if (this.fuel <= 0)
|
| 57 | {
|
| 58 | this.pushX = this.pushZ = 0.0D;
|
| 59 | }
|
| 60 |
|
| 61 | this.setMinecartPowered(this.fuel > 0);
|
| 62 |
|
| 63 | if (this.isMinecartPowered() && this.rand.nextInt(4) == 0)
|
| 64 | {
|
| 65 | this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_LARGE, this.posX, this.posY + 0.8D, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | /**
|
| 70 | * Get's the maximum speed for a minecart
|
| 71 | */
|
| 72 | protected double getMaximumSpeed()
|
| 73 | {
|
| 74 | return 0.2D;
|
| 75 | }
|
| 76 |
|
| 77 | public void killMinecart(DamageSource source)
|
| 78 | {
|
| 79 | super.killMinecart(source);
|
| 80 |
|
| 81 | if (!source.isExplosion() && this.worldObj.getGameRules().getBoolean("doEntityDrops"))
|
| 82 | {
|
| 83 | this.entityDropItem(new ItemStack(Blocks.furnace, 1), 0.0F);
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 | protected void func_180460_a(BlockPos p_180460_1_, IBlockState p_180460_2_)
|
| 88 | {
|
| 89 | super.func_180460_a(p_180460_1_, p_180460_2_);
|
| 90 | double d0 = this.pushX * this.pushX + this.pushZ * this.pushZ;
|
| 91 |
|
| 92 | if (d0 > 1.0E-4D && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.001D)
|
| 93 | {
|
| 94 | d0 = (double)MathHelper.sqrt_double(d0);
|
| 95 | this.pushX /= d0;
|
| 96 | this.pushZ /= d0;
|
| 97 |
|
| 98 | if (this.pushX * this.motionX + this.pushZ * this.motionZ < 0.0D)
|
| 99 | {
|
| 100 | this.pushX = 0.0D;
|
| 101 | this.pushZ = 0.0D;
|
| 102 | }
|
| 103 | else
|
| 104 | {
|
| 105 | double d1 = d0 / this.getMaximumSpeed();
|
| 106 | this.pushX *= d1;
|
| 107 | this.pushZ *= d1;
|
| 108 | }
|
| 109 | }
|
| 110 | }
|
| 111 |
|
| 112 | protected void applyDrag()
|
| 113 | {
|
| 114 | double d0 = this.pushX * this.pushX + this.pushZ * this.pushZ;
|
| 115 |
|
| 116 | if (d0 > 1.0E-4D)
|
| 117 | {
|
| 118 | d0 = (double)MathHelper.sqrt_double(d0);
|
| 119 | this.pushX /= d0;
|
| 120 | this.pushZ /= d0;
|
| 121 | double d1 = 1.0D;
|
| 122 | this.motionX *= 0.800000011920929D;
|
| 123 | this.motionY *= 0.0D;
|
| 124 | this.motionZ *= 0.800000011920929D;
|
| 125 | this.motionX += this.pushX * d1;
|
| 126 | this.motionZ += this.pushZ * d1;
|
| 127 | }
|
| 128 | else
|
| 129 | {
|
| 130 | this.motionX *= 0.9800000190734863D;
|
| 131 | this.motionY *= 0.0D;
|
| 132 | this.motionZ *= 0.9800000190734863D;
|
| 133 | }
|
| 134 |
|
| 135 | super.applyDrag();
|
| 136 | }
|
| 137 |
|
| 138 | /**
|
| 139 | * First layer of player interaction
|
| 140 | */
|
| 141 | public boolean interactFirst(EntityPlayer playerIn)
|
| 142 | {
|
| 143 | ItemStack itemstack = playerIn.inventory.getCurrentItem();
|
| 144 |
|
| 145 | if (itemstack != null && itemstack.getItem() == Items.coal)
|
| 146 | {
|
| 147 | if (!playerIn.capabilities.isCreativeMode && --itemstack.stackSize == 0)
|
| 148 | {
|
| 149 | playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, (ItemStack)null);
|
| 150 | }
|
| 151 |
|
| 152 | this.fuel += 3600;
|
| 153 | }
|
| 154 |
|
| 155 | this.pushX = this.posX - playerIn.posX;
|
| 156 | this.pushZ = this.posZ - playerIn.posZ;
|
| 157 | return true;
|
| 158 | }
|
| 159 |
|
| 160 | /**
|
| 161 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 162 | */
|
| 163 | protected void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 164 | {
|
| 165 | super.writeEntityToNBT(tagCompound);
|
| 166 | tagCompound.setDouble("PushX", this.pushX);
|
| 167 | tagCompound.setDouble("PushZ", this.pushZ);
|
| 168 | tagCompound.setShort("Fuel", (short)this.fuel);
|
| 169 | }
|
| 170 |
|
| 171 | /**
|
| 172 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 173 | */
|
| 174 | protected void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 175 | {
|
| 176 | super.readEntityFromNBT(tagCompund);
|
| 177 | this.pushX = tagCompund.getDouble("PushX");
|
| 178 | this.pushZ = tagCompund.getDouble("PushZ");
|
| 179 | this.fuel = tagCompund.getShort("Fuel");
|
| 180 | }
|
| 181 |
|
| 182 | protected boolean isMinecartPowered()
|
| 183 | {
|
| 184 | return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
|
| 185 | }
|
| 186 |
|
| 187 | protected void setMinecartPowered(boolean p_94107_1_)
|
| 188 | {
|
| 189 | if (p_94107_1_)
|
| 190 | {
|
| 191 | this.dataWatcher.updateObject(16, Byte.valueOf((byte)(this.dataWatcher.getWatchableObjectByte(16) | 1)));
|
| 192 | }
|
| 193 | else
|
| 194 | {
|
| 195 | this.dataWatcher.updateObject(16, Byte.valueOf((byte)(this.dataWatcher.getWatchableObjectByte(16) & -2)));
|
| 196 | }
|
| 197 | }
|
| 198 |
|
| 199 | public IBlockState getDefaultDisplayTile()
|
| 200 | {
|
| 201 | return (this.isMinecartPowered() ? Blocks.lit_furnace : Blocks.furnace).getDefaultState().withProperty(BlockFurnace.FACING, EnumFacing.NORTH);
|
| 202 | }
|
| 203 | }
|
| 204 |
|