| 1 | package net.minecraft.entity.item;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import net.minecraft.block.Block;
|
| 6 | import net.minecraft.block.BlockRailBase;
|
| 7 | import net.minecraft.block.BlockRailPowered;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.entity.Entity;
|
| 10 | import net.minecraft.entity.EntityLivingBase;
|
| 11 | import net.minecraft.entity.EntityMinecartCommandBlock;
|
| 12 | import net.minecraft.entity.ai.EntityMinecartMobSpawner;
|
| 13 | import net.minecraft.entity.monster.EntityIronGolem;
|
| 14 | import net.minecraft.entity.player.EntityPlayer;
|
| 15 | import net.minecraft.init.Blocks;
|
| 16 | import net.minecraft.init.Items;
|
| 17 | import net.minecraft.item.ItemStack;
|
| 18 | import net.minecraft.nbt.NBTTagCompound;
|
| 19 | import net.minecraft.server.MinecraftServer;
|
| 20 | import net.minecraft.util.AxisAlignedBB;
|
| 21 | import net.minecraft.util.BlockPos;
|
| 22 | import net.minecraft.util.ChatComponentText;
|
| 23 | import net.minecraft.util.ChatComponentTranslation;
|
| 24 | import net.minecraft.util.DamageSource;
|
| 25 | import net.minecraft.util.IChatComponent;
|
| 26 | import net.minecraft.util.MathHelper;
|
| 27 | import net.minecraft.util.ResourceLocation;
|
| 28 | import net.minecraft.util.Vec3;
|
| 29 | import net.minecraft.world.IWorldNameable;
|
| 30 | import net.minecraft.world.World;
|
| 31 | import net.minecraft.world.WorldServer;
|
| 32 |
|
| 33 | public abstract class EntityMinecart extends Entity implements IWorldNameable
|
| 34 | {
|
| 35 | private boolean isInReverse;
|
| 36 | private String entityName;
|
| 37 |
|
| 38 | /** Minecart rotational logic matrix */
|
| 39 | private static final int[][][] matrix = new int[][][] {{{0, 0, -1}, {0, 0, 1}}, {{ -1, 0, 0}, {1, 0, 0}}, {{ -1, -1, 0}, {1, 0, 0}}, {{ -1, 0, 0}, {1, -1, 0}}, {{0, 0, -1}, {0, -1, 1}}, {{0, -1, -1}, {0, 0, 1}}, {{0, 0, 1}, {1, 0, 0}}, {{0, 0, 1}, { -1, 0, 0}}, {{0, 0, -1}, { -1, 0, 0}}, {{0, 0, -1}, {1, 0, 0}}};
|
| 40 |
|
| 41 | /** appears to be the progress of the turn */
|
| 42 | private int turnProgress;
|
| 43 | private double minecartX;
|
| 44 | private double minecartY;
|
| 45 | private double minecartZ;
|
| 46 | private double minecartYaw;
|
| 47 | private double minecartPitch;
|
| 48 | private double velocityX;
|
| 49 | private double velocityY;
|
| 50 | private double velocityZ;
|
| 51 |
|
| 52 | public EntityMinecart(World worldIn)
|
| 53 | {
|
| 54 | super(worldIn);
|
| 55 | this.preventEntitySpawning = true;
|
| 56 | this.setSize(0.98F, 0.7F);
|
| 57 | }
|
| 58 |
|
| 59 | public static EntityMinecart getMinecart(World worldIn, double x, double y, double z, EntityMinecart.EnumMinecartType type)
|
| 60 | {
|
| 61 | switch (type)
|
| 62 | {
|
| 63 | case CHEST:
|
| 64 | return new EntityMinecartChest(worldIn, x, y, z);
|
| 65 |
|
| 66 | case FURNACE:
|
| 67 | return new EntityMinecartFurnace(worldIn, x, y, z);
|
| 68 |
|
| 69 | case TNT:
|
| 70 | return new EntityMinecartTNT(worldIn, x, y, z);
|
| 71 |
|
| 72 | case SPAWNER:
|
| 73 | return new EntityMinecartMobSpawner(worldIn, x, y, z);
|
| 74 |
|
| 75 | case HOPPER:
|
| 76 | return new EntityMinecartHopper(worldIn, x, y, z);
|
| 77 |
|
| 78 | case COMMAND_BLOCK:
|
| 79 | return new EntityMinecartCommandBlock(worldIn, x, y, z);
|
| 80 |
|
| 81 | default:
|
| 82 | return new EntityMinecartEmpty(worldIn, x, y, z);
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | /**
|
| 87 | * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
|
| 88 | * prevent them from trampling crops
|
| 89 | */
|
| 90 | protected boolean canTriggerWalking()
|
| 91 | {
|
| 92 | return false;
|
| 93 | }
|
| 94 |
|
| 95 | protected void entityInit()
|
| 96 | {
|
| 97 | this.dataWatcher.addObject(17, new Integer(0));
|
| 98 | this.dataWatcher.addObject(18, new Integer(1));
|
| 99 | this.dataWatcher.addObject(19, new Float(0.0F));
|
| 100 | this.dataWatcher.addObject(20, new Integer(0));
|
| 101 | this.dataWatcher.addObject(21, new Integer(6));
|
| 102 | this.dataWatcher.addObject(22, Byte.valueOf((byte)0));
|
| 103 | }
|
| 104 |
|
| 105 | /**
|
| 106 | * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
|
| 107 | * pushable on contact, like boats or minecarts.
|
| 108 | */
|
| 109 | public AxisAlignedBB getCollisionBox(Entity entityIn)
|
| 110 | {
|
| 111 | return entityIn.canBePushed() ? entityIn.getEntityBoundingBox() : null;
|
| 112 | }
|
| 113 |
|
| 114 | /**
|
| 115 | * Returns the collision bounding box for this entity
|
| 116 | */
|
| 117 | public AxisAlignedBB getCollisionBoundingBox()
|
| 118 | {
|
| 119 | return null;
|
| 120 | }
|
| 121 |
|
| 122 | /**
|
| 123 | * Returns true if this entity should push and be pushed by other entities when colliding.
|
| 124 | */
|
| 125 | public boolean canBePushed()
|
| 126 | {
|
| 127 | return true;
|
| 128 | }
|
| 129 |
|
| 130 | public EntityMinecart(World worldIn, double x, double y, double z)
|
| 131 | {
|
| 132 | this(worldIn);
|
| 133 | this.setPosition(x, y, z);
|
| 134 | this.motionX = 0.0D;
|
| 135 | this.motionY = 0.0D;
|
| 136 | this.motionZ = 0.0D;
|
| 137 | this.prevPosX = x;
|
| 138 | this.prevPosY = y;
|
| 139 | this.prevPosZ = z;
|
| 140 | }
|
| 141 |
|
| 142 | /**
|
| 143 | * Returns the Y offset from the entity's position for any entity riding this one.
|
| 144 | */
|
| 145 | public double getMountedYOffset()
|
| 146 | {
|
| 147 | return 0.0D;
|
| 148 | }
|
| 149 |
|
| 150 | /**
|
| 151 | * Called when the entity is attacked.
|
| 152 | */
|
| 153 | public boolean attackEntityFrom(DamageSource source, float amount)
|
| 154 | {
|
| 155 | if (!this.worldObj.isRemote && !this.isDead)
|
| 156 | {
|
| 157 | if (this.isEntityInvulnerable(source))
|
| 158 | {
|
| 159 | return false;
|
| 160 | }
|
| 161 | else
|
| 162 | {
|
| 163 | this.setRollingDirection(-this.getRollingDirection());
|
| 164 | this.setRollingAmplitude(10);
|
| 165 | this.setBeenAttacked();
|
| 166 | this.setDamage(this.getDamage() + amount * 10.0F);
|
| 167 | boolean flag = source.getEntity() instanceof EntityPlayer && ((EntityPlayer)source.getEntity()).capabilities.isCreativeMode;
|
| 168 |
|
| 169 | if (flag || this.getDamage() > 40.0F)
|
| 170 | {
|
| 171 | if (this.riddenByEntity != null)
|
| 172 | {
|
| 173 | this.riddenByEntity.mountEntity((Entity)null);
|
| 174 | }
|
| 175 |
|
| 176 | if (flag && !this.hasCustomName())
|
| 177 | {
|
| 178 | this.setDead();
|
| 179 | }
|
| 180 | else
|
| 181 | {
|
| 182 | this.killMinecart(source);
|
| 183 | }
|
| 184 | }
|
| 185 |
|
| 186 | return true;
|
| 187 | }
|
| 188 | }
|
| 189 | else
|
| 190 | {
|
| 191 | return true;
|
| 192 | }
|
| 193 | }
|
| 194 |
|
| 195 | public void killMinecart(DamageSource source)
|
| 196 | {
|
| 197 | this.setDead();
|
| 198 |
|
| 199 | if (this.worldObj.getGameRules().getBoolean("doEntityDrops"))
|
| 200 | {
|
| 201 | ItemStack itemstack = new ItemStack(Items.minecart, 1);
|
| 202 |
|
| 203 | if (this.entityName != null)
|
| 204 | {
|
| 205 | itemstack.setStackDisplayName(this.entityName);
|
| 206 | }
|
| 207 |
|
| 208 | this.entityDropItem(itemstack, 0.0F);
|
| 209 | }
|
| 210 | }
|
| 211 |
|
| 212 | /**
|
| 213 | * Setups the entity to do the hurt animation. Only used by packets in multiplayer.
|
| 214 | */
|
| 215 | public void performHurtAnimation()
|
| 216 | {
|
| 217 | this.setRollingDirection(-this.getRollingDirection());
|
| 218 | this.setRollingAmplitude(10);
|
| 219 | this.setDamage(this.getDamage() + this.getDamage() * 10.0F);
|
| 220 | }
|
| 221 |
|
| 222 | /**
|
| 223 | * Returns true if other Entities should be prevented from moving through this Entity.
|
| 224 | */
|
| 225 | public boolean canBeCollidedWith()
|
| 226 | {
|
| 227 | return !this.isDead;
|
| 228 | }
|
| 229 |
|
| 230 | /**
|
| 231 | * Will get destroyed next tick.
|
| 232 | */
|
| 233 | public void setDead()
|
| 234 | {
|
| 235 | super.setDead();
|
| 236 | }
|
| 237 |
|
| 238 | /**
|
| 239 | * Called to update the entity's position/logic.
|
| 240 | */
|
| 241 | public void onUpdate()
|
| 242 | {
|
| 243 | if (this.getRollingAmplitude() > 0)
|
| 244 | {
|
| 245 | this.setRollingAmplitude(this.getRollingAmplitude() - 1);
|
| 246 | }
|
| 247 |
|
| 248 | if (this.getDamage() > 0.0F)
|
| 249 | {
|
| 250 | this.setDamage(this.getDamage() - 1.0F);
|
| 251 | }
|
| 252 |
|
| 253 | if (this.posY < -64.0D)
|
| 254 | {
|
| 255 | this.kill();
|
| 256 | }
|
| 257 |
|
| 258 | if (!this.worldObj.isRemote && this.worldObj instanceof WorldServer)
|
| 259 | {
|
| 260 | this.worldObj.theProfiler.startSection("portal");
|
| 261 | MinecraftServer minecraftserver = ((WorldServer)this.worldObj).getMinecraftServer();
|
| 262 | int i = this.getMaxInPortalTime();
|
| 263 |
|
| 264 | if (this.inPortal)
|
| 265 | {
|
| 266 | if (minecraftserver.getAllowNether())
|
| 267 | {
|
| 268 | if (this.ridingEntity == null && this.portalCounter++ >= i)
|
| 269 | {
|
| 270 | this.portalCounter = i;
|
| 271 | this.timeUntilPortal = this.getPortalCooldown();
|
| 272 | int j;
|
| 273 |
|
| 274 | if (this.worldObj.provider.getDimensionId() == -1)
|
| 275 | {
|
| 276 | j = 0;
|
| 277 | }
|
| 278 | else
|
| 279 | {
|
| 280 | j = -1;
|
| 281 | }
|
| 282 |
|
| 283 | this.travelToDimension(j);
|
| 284 | }
|
| 285 |
|
| 286 | this.inPortal = false;
|
| 287 | }
|
| 288 | }
|
| 289 | else
|
| 290 | {
|
| 291 | if (this.portalCounter > 0)
|
| 292 | {
|
| 293 | this.portalCounter -= 4;
|
| 294 | }
|
| 295 |
|
| 296 | if (this.portalCounter < 0)
|
| 297 | {
|
| 298 | this.portalCounter = 0;
|
| 299 | }
|
| 300 | }
|
| 301 |
|
| 302 | if (this.timeUntilPortal > 0)
|
| 303 | {
|
| 304 | --this.timeUntilPortal;
|
| 305 | }
|
| 306 |
|
| 307 | this.worldObj.theProfiler.endSection();
|
| 308 | }
|
| 309 |
|
| 310 | if (this.worldObj.isRemote)
|
| 311 | {
|
| 312 | if (this.turnProgress > 0)
|
| 313 | {
|
| 314 | double d4 = this.posX + (this.minecartX - this.posX) / (double)this.turnProgress;
|
| 315 | double d5 = this.posY + (this.minecartY - this.posY) / (double)this.turnProgress;
|
| 316 | double d6 = this.posZ + (this.minecartZ - this.posZ) / (double)this.turnProgress;
|
| 317 | double d1 = MathHelper.wrapAngleTo180_double(this.minecartYaw - (double)this.rotationYaw);
|
| 318 | this.rotationYaw = (float)((double)this.rotationYaw + d1 / (double)this.turnProgress);
|
| 319 | this.rotationPitch = (float)((double)this.rotationPitch + (this.minecartPitch - (double)this.rotationPitch) / (double)this.turnProgress);
|
| 320 | --this.turnProgress;
|
| 321 | this.setPosition(d4, d5, d6);
|
| 322 | this.setRotation(this.rotationYaw, this.rotationPitch);
|
| 323 | }
|
| 324 | else
|
| 325 | {
|
| 326 | this.setPosition(this.posX, this.posY, this.posZ);
|
| 327 | this.setRotation(this.rotationYaw, this.rotationPitch);
|
| 328 | }
|
| 329 | }
|
| 330 | else
|
| 331 | {
|
| 332 | this.prevPosX = this.posX;
|
| 333 | this.prevPosY = this.posY;
|
| 334 | this.prevPosZ = this.posZ;
|
| 335 | this.motionY -= 0.03999999910593033D;
|
| 336 | int k = MathHelper.floor_double(this.posX);
|
| 337 | int l = MathHelper.floor_double(this.posY);
|
| 338 | int i1 = MathHelper.floor_double(this.posZ);
|
| 339 |
|
| 340 | if (BlockRailBase.isRailBlock(this.worldObj, new BlockPos(k, l - 1, i1)))
|
| 341 | {
|
| 342 | --l;
|
| 343 | }
|
| 344 |
|
| 345 | BlockPos blockpos = new BlockPos(k, l, i1);
|
| 346 | IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
|
| 347 |
|
| 348 | if (BlockRailBase.isRailBlock(iblockstate))
|
| 349 | {
|
| 350 | this.func_180460_a(blockpos, iblockstate);
|
| 351 |
|
| 352 | if (iblockstate.getBlock() == Blocks.activator_rail)
|
| 353 | {
|
| 354 | this.onActivatorRailPass(k, l, i1, ((Boolean)iblockstate.getValue(BlockRailPowered.POWERED)).booleanValue());
|
| 355 | }
|
| 356 | }
|
| 357 | else
|
| 358 | {
|
| 359 | this.moveDerailedMinecart();
|
| 360 | }
|
| 361 |
|
| 362 | this.doBlockCollisions();
|
| 363 | this.rotationPitch = 0.0F;
|
| 364 | double d0 = this.prevPosX - this.posX;
|
| 365 | double d2 = this.prevPosZ - this.posZ;
|
| 366 |
|
| 367 | if (d0 * d0 + d2 * d2 > 0.001D)
|
| 368 | {
|
| 369 | this.rotationYaw = (float)(MathHelper.atan2(d2, d0) * 180.0D / Math.PI);
|
| 370 |
|
| 371 | if (this.isInReverse)
|
| 372 | {
|
| 373 | this.rotationYaw += 180.0F;
|
| 374 | }
|
| 375 | }
|
| 376 |
|
| 377 | double d3 = (double)MathHelper.wrapAngleTo180_float(this.rotationYaw - this.prevRotationYaw);
|
| 378 |
|
| 379 | if (d3 < -170.0D || d3 >= 170.0D)
|
| 380 | {
|
| 381 | this.rotationYaw += 180.0F;
|
| 382 | this.isInReverse = !this.isInReverse;
|
| 383 | }
|
| 384 |
|
| 385 | this.setRotation(this.rotationYaw, this.rotationPitch);
|
| 386 |
|
| 387 | for (Entity entity : this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(0.20000000298023224D, 0.0D, 0.20000000298023224D)))
|
| 388 | {
|
| 389 | if (entity != this.riddenByEntity && entity.canBePushed() && entity instanceof EntityMinecart)
|
| 390 | {
|
| 391 | entity.applyEntityCollision(this);
|
| 392 | }
|
| 393 | }
|
| 394 |
|
| 395 | if (this.riddenByEntity != null && this.riddenByEntity.isDead)
|
| 396 | {
|
| 397 | if (this.riddenByEntity.ridingEntity == this)
|
| 398 | {
|
| 399 | this.riddenByEntity.ridingEntity = null;
|
| 400 | }
|
| 401 |
|
| 402 | this.riddenByEntity = null;
|
| 403 | }
|
| 404 |
|
| 405 | this.handleWaterMovement();
|
| 406 | }
|
| 407 | }
|
| 408 |
|
| 409 | /**
|
| 410 | * Get's the maximum speed for a minecart
|
| 411 | */
|
| 412 | protected double getMaximumSpeed()
|
| 413 | {
|
| 414 | return 0.4D;
|
| 415 | }
|
| 416 |
|
| 417 | /**
|
| 418 | * Called every tick the minecart is on an activator rail. Args: x, y, z, is the rail receiving power
|
| 419 | */
|
| 420 | public void onActivatorRailPass(int x, int y, int z, boolean receivingPower)
|
| 421 | {
|
| 422 | }
|
| 423 |
|
| 424 | /**
|
| 425 | * Moves a minecart that is not attached to a rail
|
| 426 | */
|
| 427 | protected void moveDerailedMinecart()
|
| 428 | {
|
| 429 | double d0 = this.getMaximumSpeed();
|
| 430 | this.motionX = MathHelper.clamp_double(this.motionX, -d0, d0);
|
| 431 | this.motionZ = MathHelper.clamp_double(this.motionZ, -d0, d0);
|
| 432 |
|
| 433 | if (this.onGround)
|
| 434 | {
|
| 435 | this.motionX *= 0.5D;
|
| 436 | this.motionY *= 0.5D;
|
| 437 | this.motionZ *= 0.5D;
|
| 438 | }
|
| 439 |
|
| 440 | this.moveEntity(this.motionX, this.motionY, this.motionZ);
|
| 441 |
|
| 442 | if (!this.onGround)
|
| 443 | {
|
| 444 | this.motionX *= 0.949999988079071D;
|
| 445 | this.motionY *= 0.949999988079071D;
|
| 446 | this.motionZ *= 0.949999988079071D;
|
| 447 | }
|
| 448 | }
|
| 449 |
|
| 450 | @SuppressWarnings("incomplete-switch")
|
| 451 | protected void func_180460_a(BlockPos p_180460_1_, IBlockState p_180460_2_)
|
| 452 | {
|
| 453 | this.fallDistance = 0.0F;
|
| 454 | Vec3 vec3 = this.func_70489_a(this.posX, this.posY, this.posZ);
|
| 455 | this.posY = (double)p_180460_1_.getY();
|
| 456 | boolean flag = false;
|
| 457 | boolean flag1 = false;
|
| 458 | BlockRailBase blockrailbase = (BlockRailBase)p_180460_2_.getBlock();
|
| 459 |
|
| 460 | if (blockrailbase == Blocks.golden_rail)
|
| 461 | {
|
| 462 | flag = ((Boolean)p_180460_2_.getValue(BlockRailPowered.POWERED)).booleanValue();
|
| 463 | flag1 = !flag;
|
| 464 | }
|
| 465 |
|
| 466 | double d0 = 0.0078125D;
|
| 467 | BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)p_180460_2_.getValue(blockrailbase.getShapeProperty());
|
| 468 |
|
| 469 | switch (blockrailbase$enumraildirection)
|
| 470 | {
|
| 471 | case ASCENDING_EAST:
|
| 472 | this.motionX -= 0.0078125D;
|
| 473 | ++this.posY;
|
| 474 | break;
|
| 475 |
|
| 476 | case ASCENDING_WEST:
|
| 477 | this.motionX += 0.0078125D;
|
| 478 | ++this.posY;
|
| 479 | break;
|
| 480 |
|
| 481 | case ASCENDING_NORTH:
|
| 482 | this.motionZ += 0.0078125D;
|
| 483 | ++this.posY;
|
| 484 | break;
|
| 485 |
|
| 486 | case ASCENDING_SOUTH:
|
| 487 | this.motionZ -= 0.0078125D;
|
| 488 | ++this.posY;
|
| 489 | }
|
| 490 |
|
| 491 | int[][] aint = matrix[blockrailbase$enumraildirection.getMetadata()];
|
| 492 | double d1 = (double)(aint[1][0] - aint[0][0]);
|
| 493 | double d2 = (double)(aint[1][2] - aint[0][2]);
|
| 494 | double d3 = Math.sqrt(d1 * d1 + d2 * d2);
|
| 495 | double d4 = this.motionX * d1 + this.motionZ * d2;
|
| 496 |
|
| 497 | if (d4 < 0.0D)
|
| 498 | {
|
| 499 | d1 = -d1;
|
| 500 | d2 = -d2;
|
| 501 | }
|
| 502 |
|
| 503 | double d5 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
| 504 |
|
| 505 | if (d5 > 2.0D)
|
| 506 | {
|
| 507 | d5 = 2.0D;
|
| 508 | }
|
| 509 |
|
| 510 | this.motionX = d5 * d1 / d3;
|
| 511 | this.motionZ = d5 * d2 / d3;
|
| 512 |
|
| 513 | if (this.riddenByEntity instanceof EntityLivingBase)
|
| 514 | {
|
| 515 | double d6 = (double)((EntityLivingBase)this.riddenByEntity).moveForward;
|
| 516 |
|
| 517 | if (d6 > 0.0D)
|
| 518 | {
|
| 519 | double d7 = -Math.sin((double)(this.riddenByEntity.rotationYaw * (float)Math.PI / 180.0F));
|
| 520 | double d8 = Math.cos((double)(this.riddenByEntity.rotationYaw * (float)Math.PI / 180.0F));
|
| 521 | double d9 = this.motionX * this.motionX + this.motionZ * this.motionZ;
|
| 522 |
|
| 523 | if (d9 < 0.01D)
|
| 524 | {
|
| 525 | this.motionX += d7 * 0.1D;
|
| 526 | this.motionZ += d8 * 0.1D;
|
| 527 | flag1 = false;
|
| 528 | }
|
| 529 | }
|
| 530 | }
|
| 531 |
|
| 532 | if (flag1)
|
| 533 | {
|
| 534 | double d17 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
| 535 |
|
| 536 | if (d17 < 0.03D)
|
| 537 | {
|
| 538 | this.motionX *= 0.0D;
|
| 539 | this.motionY *= 0.0D;
|
| 540 | this.motionZ *= 0.0D;
|
| 541 | }
|
| 542 | else
|
| 543 | {
|
| 544 | this.motionX *= 0.5D;
|
| 545 | this.motionY *= 0.0D;
|
| 546 | this.motionZ *= 0.5D;
|
| 547 | }
|
| 548 | }
|
| 549 |
|
| 550 | double d18 = 0.0D;
|
| 551 | double d19 = (double)p_180460_1_.getX() + 0.5D + (double)aint[0][0] * 0.5D;
|
| 552 | double d20 = (double)p_180460_1_.getZ() + 0.5D + (double)aint[0][2] * 0.5D;
|
| 553 | double d21 = (double)p_180460_1_.getX() + 0.5D + (double)aint[1][0] * 0.5D;
|
| 554 | double d10 = (double)p_180460_1_.getZ() + 0.5D + (double)aint[1][2] * 0.5D;
|
| 555 | d1 = d21 - d19;
|
| 556 | d2 = d10 - d20;
|
| 557 |
|
| 558 | if (d1 == 0.0D)
|
| 559 | {
|
| 560 | this.posX = (double)p_180460_1_.getX() + 0.5D;
|
| 561 | d18 = this.posZ - (double)p_180460_1_.getZ();
|
| 562 | }
|
| 563 | else if (d2 == 0.0D)
|
| 564 | {
|
| 565 | this.posZ = (double)p_180460_1_.getZ() + 0.5D;
|
| 566 | d18 = this.posX - (double)p_180460_1_.getX();
|
| 567 | }
|
| 568 | else
|
| 569 | {
|
| 570 | double d11 = this.posX - d19;
|
| 571 | double d12 = this.posZ - d20;
|
| 572 | d18 = (d11 * d1 + d12 * d2) * 2.0D;
|
| 573 | }
|
| 574 |
|
| 575 | this.posX = d19 + d1 * d18;
|
| 576 | this.posZ = d20 + d2 * d18;
|
| 577 | this.setPosition(this.posX, this.posY, this.posZ);
|
| 578 | double d22 = this.motionX;
|
| 579 | double d23 = this.motionZ;
|
| 580 |
|
| 581 | if (this.riddenByEntity != null)
|
| 582 | {
|
| 583 | d22 *= 0.75D;
|
| 584 | d23 *= 0.75D;
|
| 585 | }
|
| 586 |
|
| 587 | double d13 = this.getMaximumSpeed();
|
| 588 | d22 = MathHelper.clamp_double(d22, -d13, d13);
|
| 589 | d23 = MathHelper.clamp_double(d23, -d13, d13);
|
| 590 | this.moveEntity(d22, 0.0D, d23);
|
| 591 |
|
| 592 | if (aint[0][1] != 0 && MathHelper.floor_double(this.posX) - p_180460_1_.getX() == aint[0][0] && MathHelper.floor_double(this.posZ) - p_180460_1_.getZ() == aint[0][2])
|
| 593 | {
|
| 594 | this.setPosition(this.posX, this.posY + (double)aint[0][1], this.posZ);
|
| 595 | }
|
| 596 | else if (aint[1][1] != 0 && MathHelper.floor_double(this.posX) - p_180460_1_.getX() == aint[1][0] && MathHelper.floor_double(this.posZ) - p_180460_1_.getZ() == aint[1][2])
|
| 597 | {
|
| 598 | this.setPosition(this.posX, this.posY + (double)aint[1][1], this.posZ);
|
| 599 | }
|
| 600 |
|
| 601 | this.applyDrag();
|
| 602 | Vec3 vec31 = this.func_70489_a(this.posX, this.posY, this.posZ);
|
| 603 |
|
| 604 | if (vec31 != null && vec3 != null)
|
| 605 | {
|
| 606 | double d14 = (vec3.yCoord - vec31.yCoord) * 0.05D;
|
| 607 | d5 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
| 608 |
|
| 609 | if (d5 > 0.0D)
|
| 610 | {
|
| 611 | this.motionX = this.motionX / d5 * (d5 + d14);
|
| 612 | this.motionZ = this.motionZ / d5 * (d5 + d14);
|
| 613 | }
|
| 614 |
|
| 615 | this.setPosition(this.posX, vec31.yCoord, this.posZ);
|
| 616 | }
|
| 617 |
|
| 618 | int j = MathHelper.floor_double(this.posX);
|
| 619 | int i = MathHelper.floor_double(this.posZ);
|
| 620 |
|
| 621 | if (j != p_180460_1_.getX() || i != p_180460_1_.getZ())
|
| 622 | {
|
| 623 | d5 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
| 624 | this.motionX = d5 * (double)(j - p_180460_1_.getX());
|
| 625 | this.motionZ = d5 * (double)(i - p_180460_1_.getZ());
|
| 626 | }
|
| 627 |
|
| 628 | if (flag)
|
| 629 | {
|
| 630 | double d15 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
| 631 |
|
| 632 | if (d15 > 0.01D)
|
| 633 | {
|
| 634 | double d16 = 0.06D;
|
| 635 | this.motionX += this.motionX / d15 * d16;
|
| 636 | this.motionZ += this.motionZ / d15 * d16;
|
| 637 | }
|
| 638 | else if (blockrailbase$enumraildirection == BlockRailBase.EnumRailDirection.EAST_WEST)
|
| 639 | {
|
| 640 | if (this.worldObj.getBlockState(p_180460_1_.west()).getBlock().isNormalCube())
|
| 641 | {
|
| 642 | this.motionX = 0.02D;
|
| 643 | }
|
| 644 | else if (this.worldObj.getBlockState(p_180460_1_.east()).getBlock().isNormalCube())
|
| 645 | {
|
| 646 | this.motionX = -0.02D;
|
| 647 | }
|
| 648 | }
|
| 649 | else if (blockrailbase$enumraildirection == BlockRailBase.EnumRailDirection.NORTH_SOUTH)
|
| 650 | {
|
| 651 | if (this.worldObj.getBlockState(p_180460_1_.north()).getBlock().isNormalCube())
|
| 652 | {
|
| 653 | this.motionZ = 0.02D;
|
| 654 | }
|
| 655 | else if (this.worldObj.getBlockState(p_180460_1_.south()).getBlock().isNormalCube())
|
| 656 | {
|
| 657 | this.motionZ = -0.02D;
|
| 658 | }
|
| 659 | }
|
| 660 | }
|
| 661 | }
|
| 662 |
|
| 663 | protected void applyDrag()
|
| 664 | {
|
| 665 | if (this.riddenByEntity != null)
|
| 666 | {
|
| 667 | this.motionX *= 0.996999979019165D;
|
| 668 | this.motionY *= 0.0D;
|
| 669 | this.motionZ *= 0.996999979019165D;
|
| 670 | }
|
| 671 | else
|
| 672 | {
|
| 673 | this.motionX *= 0.9599999785423279D;
|
| 674 | this.motionY *= 0.0D;
|
| 675 | this.motionZ *= 0.9599999785423279D;
|
| 676 | }
|
| 677 | }
|
| 678 |
|
| 679 | /**
|
| 680 | * Sets the x,y,z of the entity from the given parameters. Also seems to set up a bounding box.
|
| 681 | */
|
| 682 | public void setPosition(double x, double y, double z)
|
| 683 | {
|
| 684 | this.posX = x;
|
| 685 | this.posY = y;
|
| 686 | this.posZ = z;
|
| 687 | float f = this.width / 2.0F;
|
| 688 | float f1 = this.height;
|
| 689 | this.setEntityBoundingBox(new AxisAlignedBB(x - (double)f, y, z - (double)f, x + (double)f, y + (double)f1, z + (double)f));
|
| 690 | }
|
| 691 |
|
| 692 | public Vec3 func_70495_a(double p_70495_1_, double p_70495_3_, double p_70495_5_, double p_70495_7_)
|
| 693 | {
|
| 694 | int i = MathHelper.floor_double(p_70495_1_);
|
| 695 | int j = MathHelper.floor_double(p_70495_3_);
|
| 696 | int k = MathHelper.floor_double(p_70495_5_);
|
| 697 |
|
| 698 | if (BlockRailBase.isRailBlock(this.worldObj, new BlockPos(i, j - 1, k)))
|
| 699 | {
|
| 700 | --j;
|
| 701 | }
|
| 702 |
|
| 703 | IBlockState iblockstate = this.worldObj.getBlockState(new BlockPos(i, j, k));
|
| 704 |
|
| 705 | if (BlockRailBase.isRailBlock(iblockstate))
|
| 706 | {
|
| 707 | BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty());
|
| 708 | p_70495_3_ = (double)j;
|
| 709 |
|
| 710 | if (blockrailbase$enumraildirection.isAscending())
|
| 711 | {
|
| 712 | p_70495_3_ = (double)(j + 1);
|
| 713 | }
|
| 714 |
|
| 715 | int[][] aint = matrix[blockrailbase$enumraildirection.getMetadata()];
|
| 716 | double d0 = (double)(aint[1][0] - aint[0][0]);
|
| 717 | double d1 = (double)(aint[1][2] - aint[0][2]);
|
| 718 | double d2 = Math.sqrt(d0 * d0 + d1 * d1);
|
| 719 | d0 = d0 / d2;
|
| 720 | d1 = d1 / d2;
|
| 721 | p_70495_1_ = p_70495_1_ + d0 * p_70495_7_;
|
| 722 | p_70495_5_ = p_70495_5_ + d1 * p_70495_7_;
|
| 723 |
|
| 724 | if (aint[0][1] != 0 && MathHelper.floor_double(p_70495_1_) - i == aint[0][0] && MathHelper.floor_double(p_70495_5_) - k == aint[0][2])
|
| 725 | {
|
| 726 | p_70495_3_ += (double)aint[0][1];
|
| 727 | }
|
| 728 | else if (aint[1][1] != 0 && MathHelper.floor_double(p_70495_1_) - i == aint[1][0] && MathHelper.floor_double(p_70495_5_) - k == aint[1][2])
|
| 729 | {
|
| 730 | p_70495_3_ += (double)aint[1][1];
|
| 731 | }
|
| 732 |
|
| 733 | return this.func_70489_a(p_70495_1_, p_70495_3_, p_70495_5_);
|
| 734 | }
|
| 735 | else
|
| 736 | {
|
| 737 | return null;
|
| 738 | }
|
| 739 | }
|
| 740 |
|
| 741 | public Vec3 func_70489_a(double p_70489_1_, double p_70489_3_, double p_70489_5_)
|
| 742 | {
|
| 743 | int i = MathHelper.floor_double(p_70489_1_);
|
| 744 | int j = MathHelper.floor_double(p_70489_3_);
|
| 745 | int k = MathHelper.floor_double(p_70489_5_);
|
| 746 |
|
| 747 | if (BlockRailBase.isRailBlock(this.worldObj, new BlockPos(i, j - 1, k)))
|
| 748 | {
|
| 749 | --j;
|
| 750 | }
|
| 751 |
|
| 752 | IBlockState iblockstate = this.worldObj.getBlockState(new BlockPos(i, j, k));
|
| 753 |
|
| 754 | if (BlockRailBase.isRailBlock(iblockstate))
|
| 755 | {
|
| 756 | BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty());
|
| 757 | int[][] aint = matrix[blockrailbase$enumraildirection.getMetadata()];
|
| 758 | double d0 = 0.0D;
|
| 759 | double d1 = (double)i + 0.5D + (double)aint[0][0] * 0.5D;
|
| 760 | double d2 = (double)j + 0.0625D + (double)aint[0][1] * 0.5D;
|
| 761 | double d3 = (double)k + 0.5D + (double)aint[0][2] * 0.5D;
|
| 762 | double d4 = (double)i + 0.5D + (double)aint[1][0] * 0.5D;
|
| 763 | double d5 = (double)j + 0.0625D + (double)aint[1][1] * 0.5D;
|
| 764 | double d6 = (double)k + 0.5D + (double)aint[1][2] * 0.5D;
|
| 765 | double d7 = d4 - d1;
|
| 766 | double d8 = (d5 - d2) * 2.0D;
|
| 767 | double d9 = d6 - d3;
|
| 768 |
|
| 769 | if (d7 == 0.0D)
|
| 770 | {
|
| 771 | p_70489_1_ = (double)i + 0.5D;
|
| 772 | d0 = p_70489_5_ - (double)k;
|
| 773 | }
|
| 774 | else if (d9 == 0.0D)
|
| 775 | {
|
| 776 | p_70489_5_ = (double)k + 0.5D;
|
| 777 | d0 = p_70489_1_ - (double)i;
|
| 778 | }
|
| 779 | else
|
| 780 | {
|
| 781 | double d10 = p_70489_1_ - d1;
|
| 782 | double d11 = p_70489_5_ - d3;
|
| 783 | d0 = (d10 * d7 + d11 * d9) * 2.0D;
|
| 784 | }
|
| 785 |
|
| 786 | p_70489_1_ = d1 + d7 * d0;
|
| 787 | p_70489_3_ = d2 + d8 * d0;
|
| 788 | p_70489_5_ = d3 + d9 * d0;
|
| 789 |
|
| 790 | if (d8 < 0.0D)
|
| 791 | {
|
| 792 | ++p_70489_3_;
|
| 793 | }
|
| 794 |
|
| 795 | if (d8 > 0.0D)
|
| 796 | {
|
| 797 | p_70489_3_ += 0.5D;
|
| 798 | }
|
| 799 |
|
| 800 | return new Vec3(p_70489_1_, p_70489_3_, p_70489_5_);
|
| 801 | }
|
| 802 | else
|
| 803 | {
|
| 804 | return null;
|
| 805 | }
|
| 806 | }
|
| 807 |
|
| 808 | /**
|
| 809 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 810 | */
|
| 811 | protected void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 812 | {
|
| 813 | if (tagCompund.getBoolean("CustomDisplayTile"))
|
| 814 | {
|
| 815 | int i = tagCompund.getInteger("DisplayData");
|
| 816 |
|
| 817 | if (tagCompund.hasKey("DisplayTile", 8))
|
| 818 | {
|
| 819 | Block block = Block.getBlockFromName(tagCompund.getString("DisplayTile"));
|
| 820 |
|
| 821 | if (block == null)
|
| 822 | {
|
| 823 | this.func_174899_a(Blocks.air.getDefaultState());
|
| 824 | }
|
| 825 | else
|
| 826 | {
|
| 827 | this.func_174899_a(block.getStateFromMeta(i));
|
| 828 | }
|
| 829 | }
|
| 830 | else
|
| 831 | {
|
| 832 | Block block1 = Block.getBlockById(tagCompund.getInteger("DisplayTile"));
|
| 833 |
|
| 834 | if (block1 == null)
|
| 835 | {
|
| 836 | this.func_174899_a(Blocks.air.getDefaultState());
|
| 837 | }
|
| 838 | else
|
| 839 | {
|
| 840 | this.func_174899_a(block1.getStateFromMeta(i));
|
| 841 | }
|
| 842 | }
|
| 843 |
|
| 844 | this.setDisplayTileOffset(tagCompund.getInteger("DisplayOffset"));
|
| 845 | }
|
| 846 |
|
| 847 | if (tagCompund.hasKey("CustomName", 8) && tagCompund.getString("CustomName").length() > 0)
|
| 848 | {
|
| 849 | this.entityName = tagCompund.getString("CustomName");
|
| 850 | }
|
| 851 | }
|
| 852 |
|
| 853 | /**
|
| 854 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 855 | */
|
| 856 | protected void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 857 | {
|
| 858 | if (this.hasDisplayTile())
|
| 859 | {
|
| 860 | tagCompound.setBoolean("CustomDisplayTile", true);
|
| 861 | IBlockState iblockstate = this.getDisplayTile();
|
| 862 | ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(iblockstate.getBlock());
|
| 863 | tagCompound.setString("DisplayTile", resourcelocation == null ? "" : resourcelocation.toString());
|
| 864 | tagCompound.setInteger("DisplayData", iblockstate.getBlock().getMetaFromState(iblockstate));
|
| 865 | tagCompound.setInteger("DisplayOffset", this.getDisplayTileOffset());
|
| 866 | }
|
| 867 |
|
| 868 | if (this.entityName != null && this.entityName.length() > 0)
|
| 869 | {
|
| 870 | tagCompound.setString("CustomName", this.entityName);
|
| 871 | }
|
| 872 | }
|
| 873 |
|
| 874 | /**
|
| 875 | * Applies a velocity to each of the entities pushing them away from each other. Args: entity
|
| 876 | */
|
| 877 | public void applyEntityCollision(Entity entityIn)
|
| 878 | {
|
| 879 | if (!this.worldObj.isRemote)
|
| 880 | {
|
| 881 | if (!entityIn.noClip && !this.noClip)
|
| 882 | {
|
| 883 | if (entityIn != this.riddenByEntity)
|
| 884 | {
|
| 885 | if (entityIn instanceof EntityLivingBase && !(entityIn instanceof EntityPlayer) && !(entityIn instanceof EntityIronGolem) && this.getMinecartType() == EntityMinecart.EnumMinecartType.RIDEABLE && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.01D && this.riddenByEntity == null && entityIn.ridingEntity == null)
|
| 886 | {
|
| 887 | entityIn.mountEntity(this);
|
| 888 | }
|
| 889 |
|
| 890 | double d0 = entityIn.posX - this.posX;
|
| 891 | double d1 = entityIn.posZ - this.posZ;
|
| 892 | double d2 = d0 * d0 + d1 * d1;
|
| 893 |
|
| 894 | if (d2 >= 9.999999747378752E-5D)
|
| 895 | {
|
| 896 | d2 = (double)MathHelper.sqrt_double(d2);
|
| 897 | d0 = d0 / d2;
|
| 898 | d1 = d1 / d2;
|
| 899 | double d3 = 1.0D / d2;
|
| 900 |
|
| 901 | if (d3 > 1.0D)
|
| 902 | {
|
| 903 | d3 = 1.0D;
|
| 904 | }
|
| 905 |
|
| 906 | d0 = d0 * d3;
|
| 907 | d1 = d1 * d3;
|
| 908 | d0 = d0 * 0.10000000149011612D;
|
| 909 | d1 = d1 * 0.10000000149011612D;
|
| 910 | d0 = d0 * (double)(1.0F - this.entityCollisionReduction);
|
| 911 | d1 = d1 * (double)(1.0F - this.entityCollisionReduction);
|
| 912 | d0 = d0 * 0.5D;
|
| 913 | d1 = d1 * 0.5D;
|
| 914 |
|
| 915 | if (entityIn instanceof EntityMinecart)
|
| 916 | {
|
| 917 | double d4 = entityIn.posX - this.posX;
|
| 918 | double d5 = entityIn.posZ - this.posZ;
|
| 919 | Vec3 vec3 = (new Vec3(d4, 0.0D, d5)).normalize();
|
| 920 | Vec3 vec31 = (new Vec3((double)MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F), 0.0D, (double)MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F))).normalize();
|
| 921 | double d6 = Math.abs(vec3.dotProduct(vec31));
|
| 922 |
|
| 923 | if (d6 < 0.800000011920929D)
|
| 924 | {
|
| 925 | return;
|
| 926 | }
|
| 927 |
|
| 928 | double d7 = entityIn.motionX + this.motionX;
|
| 929 | double d8 = entityIn.motionZ + this.motionZ;
|
| 930 |
|
| 931 | if (((EntityMinecart)entityIn).getMinecartType() == EntityMinecart.EnumMinecartType.FURNACE && this.getMinecartType() != EntityMinecart.EnumMinecartType.FURNACE)
|
| 932 | {
|
| 933 | this.motionX *= 0.20000000298023224D;
|
| 934 | this.motionZ *= 0.20000000298023224D;
|
| 935 | this.addVelocity(entityIn.motionX - d0, 0.0D, entityIn.motionZ - d1);
|
| 936 | entityIn.motionX *= 0.949999988079071D;
|
| 937 | entityIn.motionZ *= 0.949999988079071D;
|
| 938 | }
|
| 939 | else if (((EntityMinecart)entityIn).getMinecartType() != EntityMinecart.EnumMinecartType.FURNACE && this.getMinecartType() == EntityMinecart.EnumMinecartType.FURNACE)
|
| 940 | {
|
| 941 | entityIn.motionX *= 0.20000000298023224D;
|
| 942 | entityIn.motionZ *= 0.20000000298023224D;
|
| 943 | entityIn.addVelocity(this.motionX + d0, 0.0D, this.motionZ + d1);
|
| 944 | this.motionX *= 0.949999988079071D;
|
| 945 | this.motionZ *= 0.949999988079071D;
|
| 946 | }
|
| 947 | else
|
| 948 | {
|
| 949 | d7 = d7 / 2.0D;
|
| 950 | d8 = d8 / 2.0D;
|
| 951 | this.motionX *= 0.20000000298023224D;
|
| 952 | this.motionZ *= 0.20000000298023224D;
|
| 953 | this.addVelocity(d7 - d0, 0.0D, d8 - d1);
|
| 954 | entityIn.motionX *= 0.20000000298023224D;
|
| 955 | entityIn.motionZ *= 0.20000000298023224D;
|
| 956 | entityIn.addVelocity(d7 + d0, 0.0D, d8 + d1);
|
| 957 | }
|
| 958 | }
|
| 959 | else
|
| 960 | {
|
| 961 | this.addVelocity(-d0, 0.0D, -d1);
|
| 962 | entityIn.addVelocity(d0 / 4.0D, 0.0D, d1 / 4.0D);
|
| 963 | }
|
| 964 | }
|
| 965 | }
|
| 966 | }
|
| 967 | }
|
| 968 | }
|
| 969 |
|
| 970 | public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean p_180426_10_)
|
| 971 | {
|
| 972 | this.minecartX = x;
|
| 973 | this.minecartY = y;
|
| 974 | this.minecartZ = z;
|
| 975 | this.minecartYaw = (double)yaw;
|
| 976 | this.minecartPitch = (double)pitch;
|
| 977 | this.turnProgress = posRotationIncrements + 2;
|
| 978 | this.motionX = this.velocityX;
|
| 979 | this.motionY = this.velocityY;
|
| 980 | this.motionZ = this.velocityZ;
|
| 981 | }
|
| 982 |
|
| 983 | /**
|
| 984 | * Sets the velocity to the args. Args: x, y, z
|
| 985 | */
|
| 986 | public void setVelocity(double x, double y, double z)
|
| 987 | {
|
| 988 | this.velocityX = this.motionX = x;
|
| 989 | this.velocityY = this.motionY = y;
|
| 990 | this.velocityZ = this.motionZ = z;
|
| 991 | }
|
| 992 |
|
| 993 | /**
|
| 994 | * Sets the current amount of damage the minecart has taken. Decreases over time. The cart breaks when this is over
|
| 995 | * 40.
|
| 996 | */
|
| 997 | public void setDamage(float p_70492_1_)
|
| 998 | {
|
| 999 | this.dataWatcher.updateObject(19, Float.valueOf(p_70492_1_));
|
| 1000 | }
|
| 1001 |
|
| 1002 | /**
|
| 1003 | * Gets the current amount of damage the minecart has taken. Decreases over time. The cart breaks when this is over
|
| 1004 | * 40.
|
| 1005 | */
|
| 1006 | public float getDamage()
|
| 1007 | {
|
| 1008 | return this.dataWatcher.getWatchableObjectFloat(19);
|
| 1009 | }
|
| 1010 |
|
| 1011 | /**
|
| 1012 | * Sets the rolling amplitude the cart rolls while being attacked.
|
| 1013 | */
|
| 1014 | public void setRollingAmplitude(int p_70497_1_)
|
| 1015 | {
|
| 1016 | this.dataWatcher.updateObject(17, Integer.valueOf(p_70497_1_));
|
| 1017 | }
|
| 1018 |
|
| 1019 | /**
|
| 1020 | * Gets the rolling amplitude the cart rolls while being attacked.
|
| 1021 | */
|
| 1022 | public int getRollingAmplitude()
|
| 1023 | {
|
| 1024 | return this.dataWatcher.getWatchableObjectInt(17);
|
| 1025 | }
|
| 1026 |
|
| 1027 | /**
|
| 1028 | * Sets the rolling direction the cart rolls while being attacked. Can be 1 or -1.
|
| 1029 | */
|
| 1030 | public void setRollingDirection(int p_70494_1_)
|
| 1031 | {
|
| 1032 | this.dataWatcher.updateObject(18, Integer.valueOf(p_70494_1_));
|
| 1033 | }
|
| 1034 |
|
| 1035 | /**
|
| 1036 | * Gets the rolling direction the cart rolls while being attacked. Can be 1 or -1.
|
| 1037 | */
|
| 1038 | public int getRollingDirection()
|
| 1039 | {
|
| 1040 | return this.dataWatcher.getWatchableObjectInt(18);
|
| 1041 | }
|
| 1042 |
|
| 1043 | public abstract EntityMinecart.EnumMinecartType getMinecartType();
|
| 1044 |
|
| 1045 | public IBlockState getDisplayTile()
|
| 1046 | {
|
| 1047 | return !this.hasDisplayTile() ? this.getDefaultDisplayTile() : Block.getStateById(this.getDataWatcher().getWatchableObjectInt(20));
|
| 1048 | }
|
| 1049 |
|
| 1050 | public IBlockState getDefaultDisplayTile()
|
| 1051 | {
|
| 1052 | return Blocks.air.getDefaultState();
|
| 1053 | }
|
| 1054 |
|
| 1055 | public int getDisplayTileOffset()
|
| 1056 | {
|
| 1057 | return !this.hasDisplayTile() ? this.getDefaultDisplayTileOffset() : this.getDataWatcher().getWatchableObjectInt(21);
|
| 1058 | }
|
| 1059 |
|
| 1060 | public int getDefaultDisplayTileOffset()
|
| 1061 | {
|
| 1062 | return 6;
|
| 1063 | }
|
| 1064 |
|
| 1065 | public void func_174899_a(IBlockState p_174899_1_)
|
| 1066 | {
|
| 1067 | this.getDataWatcher().updateObject(20, Integer.valueOf(Block.getStateId(p_174899_1_)));
|
| 1068 | this.setHasDisplayTile(true);
|
| 1069 | }
|
| 1070 |
|
| 1071 | public void setDisplayTileOffset(int p_94086_1_)
|
| 1072 | {
|
| 1073 | this.getDataWatcher().updateObject(21, Integer.valueOf(p_94086_1_));
|
| 1074 | this.setHasDisplayTile(true);
|
| 1075 | }
|
| 1076 |
|
| 1077 | public boolean hasDisplayTile()
|
| 1078 | {
|
| 1079 | return this.getDataWatcher().getWatchableObjectByte(22) == 1;
|
| 1080 | }
|
| 1081 |
|
| 1082 | public void setHasDisplayTile(boolean p_94096_1_)
|
| 1083 | {
|
| 1084 | this.getDataWatcher().updateObject(22, Byte.valueOf((byte)(p_94096_1_ ? 1 : 0)));
|
| 1085 | }
|
| 1086 |
|
| 1087 | /**
|
| 1088 | * Sets the custom name tag for this entity
|
| 1089 | */
|
| 1090 | public void setCustomNameTag(String name)
|
| 1091 | {
|
| 1092 | this.entityName = name;
|
| 1093 | }
|
| 1094 |
|
| 1095 | /**
|
| 1096 | * Get the name of this object. For players this returns their username
|
| 1097 | */
|
| 1098 | public String getName()
|
| 1099 | {
|
| 1100 | return this.entityName != null ? this.entityName : super.getName();
|
| 1101 | }
|
| 1102 |
|
| 1103 | /**
|
| 1104 | * Returns true if this thing is named
|
| 1105 | */
|
| 1106 | public boolean hasCustomName()
|
| 1107 | {
|
| 1108 | return this.entityName != null;
|
| 1109 | }
|
| 1110 |
|
| 1111 | public String getCustomNameTag()
|
| 1112 | {
|
| 1113 | return this.entityName;
|
| 1114 | }
|
| 1115 |
|
| 1116 | /**
|
| 1117 | * Get the formatted ChatComponent that will be used for the sender's username in chat
|
| 1118 | */
|
| 1119 | public IChatComponent getDisplayName()
|
| 1120 | {
|
| 1121 | if (this.hasCustomName())
|
| 1122 | {
|
| 1123 | ChatComponentText chatcomponenttext = new ChatComponentText(this.entityName);
|
| 1124 | chatcomponenttext.getChatStyle().setChatHoverEvent(this.getHoverEvent());
|
| 1125 | chatcomponenttext.getChatStyle().setInsertion(this.getUniqueID().toString());
|
| 1126 | return chatcomponenttext;
|
| 1127 | }
|
| 1128 | else
|
| 1129 | {
|
| 1130 | ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation(this.getName(), new Object[0]);
|
| 1131 | chatcomponenttranslation.getChatStyle().setChatHoverEvent(this.getHoverEvent());
|
| 1132 | chatcomponenttranslation.getChatStyle().setInsertion(this.getUniqueID().toString());
|
| 1133 | return chatcomponenttranslation;
|
| 1134 | }
|
| 1135 | }
|
| 1136 |
|
| 1137 | public static enum EnumMinecartType
|
| 1138 | {
|
| 1139 | RIDEABLE(0, "MinecartRideable"),
|
| 1140 | CHEST(1, "MinecartChest"),
|
| 1141 | FURNACE(2, "MinecartFurnace"),
|
| 1142 | TNT(3, "MinecartTNT"),
|
| 1143 | SPAWNER(4, "MinecartSpawner"),
|
| 1144 | HOPPER(5, "MinecartHopper"),
|
| 1145 | COMMAND_BLOCK(6, "MinecartCommandBlock");
|
| 1146 |
|
| 1147 | private static final Map<Integer, EntityMinecart.EnumMinecartType> ID_LOOKUP = Maps.<Integer, EntityMinecart.EnumMinecartType>newHashMap();
|
| 1148 | private final int networkID;
|
| 1149 | private final String name;
|
| 1150 |
|
| 1151 | private EnumMinecartType(int networkID, String name)
|
| 1152 | {
|
| 1153 | this.networkID = networkID;
|
| 1154 | this.name = name;
|
| 1155 | }
|
| 1156 |
|
| 1157 | public int getNetworkID()
|
| 1158 | {
|
| 1159 | return this.networkID;
|
| 1160 | }
|
| 1161 |
|
| 1162 | public String getName()
|
| 1163 | {
|
| 1164 | return this.name;
|
| 1165 | }
|
| 1166 |
|
| 1167 | public static EntityMinecart.EnumMinecartType byNetworkID(int id)
|
| 1168 | {
|
| 1169 | EntityMinecart.EnumMinecartType entityminecart$enumminecarttype = (EntityMinecart.EnumMinecartType)ID_LOOKUP.get(Integer.valueOf(id));
|
| 1170 | return entityminecart$enumminecarttype == null ? RIDEABLE : entityminecart$enumminecarttype;
|
| 1171 | }
|
| 1172 |
|
| 1173 | static {
|
| 1174 | for (EntityMinecart.EnumMinecartType entityminecart$enumminecarttype : values())
|
| 1175 | {
|
| 1176 | ID_LOOKUP.put(Integer.valueOf(entityminecart$enumminecarttype.getNetworkID()), entityminecart$enumminecarttype);
|
| 1177 | }
|
| 1178 | }
|
| 1179 | }
|
| 1180 | }
|
| 1181 |
|