mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 02:20:01 +03:00
748 lines
28 KiB
Diff
748 lines
28 KiB
Diff
--- ../src-base/minecraft/net/minecraft/entity/item/EntityMinecart.java
|
|
+++ ../src-work/minecraft/net/minecraft/entity/item/EntityMinecart.java
|
|
@@ -20,7 +20,6 @@
|
|
import net.minecraft.network.datasync.DataParameter;
|
|
import net.minecraft.network.datasync.DataSerializers;
|
|
import net.minecraft.network.datasync.EntityDataManager;
|
|
-import net.minecraft.server.MinecraftServer;
|
|
import net.minecraft.util.DamageSource;
|
|
import net.minecraft.util.EntitySelectors;
|
|
import net.minecraft.util.EnumFacing;
|
|
@@ -32,10 +31,16 @@
|
|
import net.minecraft.util.math.Vec3d;
|
|
import net.minecraft.world.IWorldNameable;
|
|
import net.minecraft.world.World;
|
|
-import net.minecraft.world.WorldServer;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.entity.Vehicle;
|
|
+import org.bukkit.event.vehicle.VehicleDamageEvent;
|
|
+import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
|
+import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
|
|
+import org.bukkit.util.Vector;
|
|
|
|
+// TODO: Improve compatibility between Forge and CraftBukkit variables
|
|
public abstract class EntityMinecart extends Entity implements IWorldNameable
|
|
{
|
|
private static final DataParameter<Integer> ROLLING_AMPLITUDE = EntityDataManager.<Integer>createKey(EntityMinecart.class, DataSerializers.VARINT);
|
|
@@ -59,6 +64,31 @@
|
|
@SideOnly(Side.CLIENT)
|
|
private double velocityZ;
|
|
|
|
+ /* Forge: Minecart Compatibility Layer Integration. */
|
|
+ public static float defaultMaxSpeedAirLateral = 0.4f;
|
|
+ public static float defaultMaxSpeedAirVertical = -1f;
|
|
+ public static double defaultDragAir = 0.94999998807907104D;
|
|
+ protected boolean canUseRail = true;
|
|
+ protected boolean canBePushed = true;
|
|
+ private static net.minecraftforge.common.IMinecartCollisionHandler collisionHandler = null;
|
|
+
|
|
+ /* Instance versions of the above physics properties */
|
|
+ private float currentSpeedRail = getMaxCartSpeedOnRail();
|
|
+ protected float maxSpeedAirLateral = defaultMaxSpeedAirLateral;
|
|
+ protected float maxSpeedAirVertical = defaultMaxSpeedAirVertical;
|
|
+ protected double dragAir = defaultDragAir;
|
|
+
|
|
+ // CraftBukkit start - Use Forge vars from above
|
|
+ public boolean slowWhenEmpty = true;
|
|
+ private double derailedX = 0.5;
|
|
+ private double derailedY = 0.5;
|
|
+ private double derailedZ = 0.5;
|
|
+ private double flyingX = dragAir;
|
|
+ private double flyingY = dragAir;
|
|
+ private double flyingZ = dragAir;
|
|
+ public double maxSpeed = 0.4D;
|
|
+ // CraftBukkit end
|
|
+
|
|
public EntityMinecart(World worldIn)
|
|
{
|
|
super(worldIn);
|
|
@@ -66,7 +96,7 @@
|
|
this.setSize(0.98F, 0.7F);
|
|
}
|
|
|
|
- public static EntityMinecart create(World worldIn, double x, double y, double z, EntityMinecart.Type typeIn)
|
|
+ public static EntityMinecart create(World worldIn, double x, double y, double z, Type typeIn)
|
|
{
|
|
switch (typeIn)
|
|
{
|
|
@@ -105,18 +135,20 @@
|
|
@Nullable
|
|
public AxisAlignedBB getCollisionBox(Entity entityIn)
|
|
{
|
|
+ if (getCollisionHandler() != null) return getCollisionHandler().getCollisionBox(this, entityIn);
|
|
return entityIn.canBePushed() ? entityIn.getEntityBoundingBox() : null;
|
|
}
|
|
|
|
@Nullable
|
|
public AxisAlignedBB getCollisionBoundingBox()
|
|
{
|
|
+ if (getCollisionHandler() != null) return getCollisionHandler().getBoundingBox(this);
|
|
return null;
|
|
}
|
|
|
|
public boolean canBePushed()
|
|
{
|
|
- return true;
|
|
+ return canBePushed;
|
|
}
|
|
|
|
public EntityMinecart(World worldIn, double x, double y, double z)
|
|
@@ -146,6 +178,17 @@
|
|
}
|
|
else
|
|
{
|
|
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
|
|
+ org.bukkit.entity.Entity passenger = (source.getTrueSource() == null) ? null : source.getTrueSource().getBukkitEntity();
|
|
+
|
|
+ VehicleDamageEvent event = new VehicleDamageEvent(vehicle, passenger, amount);
|
|
+ this.world.getServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ amount = (float) event.getDamage();
|
|
this.setRollingDirection(-this.getRollingDirection());
|
|
this.setRollingAmplitude(10);
|
|
this.markVelocityChanged();
|
|
@@ -154,6 +197,13 @@
|
|
|
|
if (flag || this.getDamage() > 40.0F)
|
|
{
|
|
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, passenger);
|
|
+ this.world.getServer().getPluginManager().callEvent(destroyEvent);
|
|
+
|
|
+ if (destroyEvent.isCancelled()) {
|
|
+ this.setDamage(40); // Maximize damage so this doesn't get triggered again right away
|
|
+ return true;
|
|
+ }
|
|
this.removePassengers();
|
|
|
|
if (flag && !this.hasCustomName())
|
|
@@ -212,6 +262,11 @@
|
|
|
|
public void onUpdate()
|
|
{
|
|
+ double prevX = this.posX;
|
|
+ double prevY = this.posY;
|
|
+ double prevZ = this.posZ;
|
|
+ float prevYaw = this.rotationYaw;
|
|
+ float prevPitch = this.rotationPitch;
|
|
if (this.getRollingAmplitude() > 0)
|
|
{
|
|
this.setRollingAmplitude(this.getRollingAmplitude() - 1);
|
|
@@ -226,7 +281,8 @@
|
|
{
|
|
this.outOfWorld();
|
|
}
|
|
-
|
|
+ // CraftBukkit - handled in postTick
|
|
+ /*
|
|
if (!this.world.isRemote && this.world instanceof WorldServer)
|
|
{
|
|
this.world.profiler.startSection("portal");
|
|
@@ -278,6 +334,7 @@
|
|
|
|
this.world.profiler.endSection();
|
|
}
|
|
+ */
|
|
|
|
if (this.world.isRemote)
|
|
{
|
|
@@ -322,7 +379,7 @@
|
|
BlockPos blockpos = new BlockPos(k, l, i1);
|
|
IBlockState iblockstate = this.world.getBlockState(blockpos);
|
|
|
|
- if (BlockRailBase.isRailBlock(iblockstate))
|
|
+ if (canUseRail() && BlockRailBase.isRailBlock(iblockstate))
|
|
{
|
|
this.moveAlongTrack(blockpos, iblockstate);
|
|
|
|
@@ -361,9 +418,23 @@
|
|
|
|
this.setRotation(this.rotationYaw, this.rotationPitch);
|
|
|
|
- if (this.getType() == EntityMinecart.Type.RIDEABLE && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.01D)
|
|
+ AxisAlignedBB box;
|
|
+ if (getCollisionHandler() != null) box = getCollisionHandler().getMinecartCollisionBox(this);
|
|
+ else box = this.getEntityBoundingBox().grow(0.20000000298023224D, 0.0D, 0.20000000298023224D);
|
|
+
|
|
+ org.bukkit.World bworld = this.world.getWorld();
|
|
+ Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
|
|
+ Location to = new Location(bworld, this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
|
|
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
|
|
+
|
|
+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
|
|
+
|
|
+ if (!from.equals(to)) {
|
|
+ this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to));
|
|
+ }
|
|
+ if (canBeRidden() && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.01D)
|
|
{
|
|
- List<Entity> list = this.world.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().grow(0.20000000298023224D, 0.0D, 0.20000000298023224D), EntitySelectors.getTeamCollisionPredicate(this));
|
|
+ List<Entity> list = this.world.getEntitiesInAABBexcluding(this, box, EntitySelectors.getTeamCollisionPredicate(this));
|
|
|
|
if (!list.isEmpty())
|
|
{
|
|
@@ -373,10 +444,22 @@
|
|
|
|
if (!(entity1 instanceof EntityPlayer) && !(entity1 instanceof EntityIronGolem) && !(entity1 instanceof EntityMinecart) && !this.isBeingRidden() && !entity1.isRiding())
|
|
{
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity1.getBukkitEntity());
|
|
+ this.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
+
|
|
+ if (collisionEvent.isCancelled()) {
|
|
+ continue;
|
|
+ }
|
|
entity1.startRiding(this);
|
|
}
|
|
else
|
|
{
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity1.getBukkitEntity());
|
|
+ this.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
+
|
|
+ if (collisionEvent.isCancelled()) {
|
|
+ continue;
|
|
+ }
|
|
entity1.applyEntityCollision(this);
|
|
}
|
|
}
|
|
@@ -384,22 +467,30 @@
|
|
}
|
|
else
|
|
{
|
|
- for (Entity entity : this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().grow(0.20000000298023224D, 0.0D, 0.20000000298023224D)))
|
|
+ for (Entity entity : this.world.getEntitiesWithinAABBExcludingEntity(this, box))
|
|
{
|
|
if (!this.isPassenger(entity) && entity.canBePushed() && entity instanceof EntityMinecart)
|
|
{
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity());
|
|
+ this.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
+
|
|
+ if (collisionEvent.isCancelled()) {
|
|
+ continue;
|
|
+ }
|
|
entity.applyEntityCollision(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
this.handleWaterMovement();
|
|
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.minecart.MinecartUpdateEvent(this, this.getCurrentRailPosition()));
|
|
}
|
|
}
|
|
|
|
protected double getMaximumSpeed()
|
|
{
|
|
- return 0.4D;
|
|
+ // return 0.4D;
|
|
+ return this.maxSpeed;
|
|
}
|
|
|
|
public void onActivatorRailPass(int x, int y, int z, boolean receivingPower)
|
|
@@ -408,24 +499,45 @@
|
|
|
|
protected void moveDerailedMinecart()
|
|
{
|
|
- double d0 = this.getMaximumSpeed();
|
|
+ double d0 = onGround ? this.getMaximumSpeed() : getMaxSpeedAirLateral();
|
|
this.motionX = MathHelper.clamp(this.motionX, -d0, d0);
|
|
this.motionZ = MathHelper.clamp(this.motionZ, -d0, d0);
|
|
|
|
+ double moveY = motionY;
|
|
+ if(getMaxSpeedAirVertical() > 0 && motionY > getMaxSpeedAirVertical())
|
|
+ {
|
|
+ moveY = getMaxSpeedAirVertical();
|
|
+ if(Math.abs(motionX) < 0.3f && Math.abs(motionZ) < 0.3f)
|
|
+ {
|
|
+ moveY = 0.15f;
|
|
+ motionY = moveY;
|
|
+ }
|
|
+ }
|
|
+
|
|
if (this.onGround)
|
|
{
|
|
- this.motionX *= 0.5D;
|
|
- this.motionY *= 0.5D;
|
|
- this.motionZ *= 0.5D;
|
|
+ // CraftBukkit start - replace magic numbers with our variables
|
|
+ // this.motionX *= 0.5D;
|
|
+ // this.motionY *= 0.5D;
|
|
+ // this.motionZ *= 0.5D;
|
|
+ this.motionX *= this.derailedX;
|
|
+ this.motionY *= this.derailedY;
|
|
+ this.motionZ *= this.derailedZ;
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
- this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
|
|
+ this.move(MoverType.SELF, this.motionX, moveY, this.motionZ);
|
|
|
|
if (!this.onGround)
|
|
{
|
|
- this.motionX *= 0.949999988079071D;
|
|
- this.motionY *= 0.949999988079071D;
|
|
- this.motionZ *= 0.949999988079071D;
|
|
+ // CraftBukkit start - replace magic numbers with our variables
|
|
+ // this.motionX *= getDragAir();
|
|
+ // this.motionY *= getDragAir();
|
|
+ // this.motionZ *= getDragAir();
|
|
+ this.motionX *= this.flyingX;
|
|
+ this.motionY *= this.flyingY;
|
|
+ this.motionZ *= this.flyingZ;
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
@@ -445,25 +557,25 @@
|
|
flag1 = !flag;
|
|
}
|
|
|
|
- double d0 = 0.0078125D;
|
|
- BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)state.getValue(blockrailbase.getShapeProperty());
|
|
+ double slopeAdjustment = getSlopeAdjustment();
|
|
+ BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = blockrailbase.getRailDirection(world, pos, state, this);
|
|
|
|
switch (blockrailbase$enumraildirection)
|
|
{
|
|
case ASCENDING_EAST:
|
|
- this.motionX -= 0.0078125D;
|
|
+ this.motionX -= slopeAdjustment;
|
|
++this.posY;
|
|
break;
|
|
case ASCENDING_WEST:
|
|
- this.motionX += 0.0078125D;
|
|
+ this.motionX += slopeAdjustment;
|
|
++this.posY;
|
|
break;
|
|
case ASCENDING_NORTH:
|
|
- this.motionZ += 0.0078125D;
|
|
+ this.motionZ += slopeAdjustment;
|
|
++this.posY;
|
|
break;
|
|
case ASCENDING_SOUTH:
|
|
- this.motionZ -= 0.0078125D;
|
|
+ this.motionZ -= slopeAdjustment;
|
|
++this.posY;
|
|
}
|
|
|
|
@@ -509,7 +621,7 @@
|
|
}
|
|
}
|
|
|
|
- if (flag1)
|
|
+ if (flag1 && shouldDoRailFunctions())
|
|
{
|
|
double d17 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
|
|
|
@@ -555,20 +667,8 @@
|
|
this.posX = d18 + d1 * d10;
|
|
this.posZ = d19 + d2 * d10;
|
|
this.setPosition(this.posX, this.posY, this.posZ);
|
|
- double d22 = this.motionX;
|
|
- double d23 = this.motionZ;
|
|
+ this.moveMinecartOnRail(pos);
|
|
|
|
- if (this.isBeingRidden())
|
|
- {
|
|
- d22 *= 0.75D;
|
|
- d23 *= 0.75D;
|
|
- }
|
|
-
|
|
- double d13 = this.getMaximumSpeed();
|
|
- d22 = MathHelper.clamp(d22, -d13, d13);
|
|
- d23 = MathHelper.clamp(d23, -d13, d13);
|
|
- this.move(MoverType.SELF, d22, 0.0D, d23);
|
|
-
|
|
if (aint[0][1] != 0 && MathHelper.floor(this.posX) - pos.getX() == aint[0][0] && MathHelper.floor(this.posZ) - pos.getZ() == aint[0][2])
|
|
{
|
|
this.setPosition(this.posX, this.posY + (double)aint[0][1], this.posZ);
|
|
@@ -605,8 +705,14 @@
|
|
this.motionZ = d5 * (double)(i - pos.getZ());
|
|
}
|
|
|
|
- if (flag)
|
|
+
|
|
+ if(shouldDoRailFunctions())
|
|
{
|
|
+ ((BlockRailBase)state.getBlock()).onMinecartPass(world, this, pos);
|
|
+ }
|
|
+
|
|
+ if (flag && shouldDoRailFunctions())
|
|
+ {
|
|
double d15 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
|
|
|
if (d15 > 0.01D)
|
|
@@ -642,7 +748,7 @@
|
|
|
|
protected void applyDrag()
|
|
{
|
|
- if (this.isBeingRidden())
|
|
+ if (this.isBeingRidden() || !this.slowWhenEmpty)
|
|
{
|
|
this.motionX *= 0.996999979019165D;
|
|
this.motionY *= 0.0D;
|
|
@@ -683,7 +789,7 @@
|
|
|
|
if (BlockRailBase.isRailBlock(iblockstate))
|
|
{
|
|
- BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty());
|
|
+ BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = ((BlockRailBase)iblockstate.getBlock()).getRailDirection(world, new BlockPos(i, j, k), iblockstate, this);
|
|
y = (double)j;
|
|
|
|
if (blockrailbase$enumraildirection.isAscending())
|
|
@@ -733,7 +839,7 @@
|
|
|
|
if (BlockRailBase.isRailBlock(iblockstate))
|
|
{
|
|
- BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty());
|
|
+ BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = ((BlockRailBase)iblockstate.getBlock()).getRailDirection(world, new BlockPos(i, j, k), iblockstate, this);
|
|
int[][] aint = MATRIX[blockrailbase$enumraildirection.getMetadata()];
|
|
double d0 = (double)i + 0.5D + (double)aint[0][0] * 0.5D;
|
|
double d1 = (double)j + 0.0625D + (double)aint[0][1] * 0.5D;
|
|
@@ -830,12 +936,24 @@
|
|
|
|
public void applyEntityCollision(Entity entityIn)
|
|
{
|
|
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.minecart.MinecartCollisionEvent(this, entityIn));
|
|
+ if (getCollisionHandler() != null)
|
|
+ {
|
|
+ getCollisionHandler().onEntityCollision(this, entityIn);
|
|
+ return;
|
|
+ }
|
|
if (!this.world.isRemote)
|
|
{
|
|
if (!entityIn.noClip && !this.noClip)
|
|
{
|
|
if (!this.isPassenger(entityIn))
|
|
{
|
|
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entityIn.getBukkitEntity());
|
|
+ this.world.getServer().getPluginManager().callEvent(collisionEvent);
|
|
+
|
|
+ if (collisionEvent.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
double d0 = entityIn.posX - this.posX;
|
|
double d1 = entityIn.posZ - this.posZ;
|
|
double d2 = d0 * d0 + d1 * d1;
|
|
@@ -877,7 +995,7 @@
|
|
double d7 = entityIn.motionX + this.motionX;
|
|
double d8 = entityIn.motionZ + this.motionZ;
|
|
|
|
- if (((EntityMinecart)entityIn).getType() == EntityMinecart.Type.FURNACE && this.getType() != EntityMinecart.Type.FURNACE)
|
|
+ if (((EntityMinecart)entityIn).isPoweredCart() && !isPoweredCart())
|
|
{
|
|
this.motionX *= 0.20000000298023224D;
|
|
this.motionZ *= 0.20000000298023224D;
|
|
@@ -885,7 +1003,7 @@
|
|
entityIn.motionX *= 0.949999988079071D;
|
|
entityIn.motionZ *= 0.949999988079071D;
|
|
}
|
|
- else if (((EntityMinecart)entityIn).getType() != EntityMinecart.Type.FURNACE && this.getType() == EntityMinecart.Type.FURNACE)
|
|
+ else if (!((EntityMinecart)entityIn).isPoweredCart() && isPoweredCart())
|
|
{
|
|
entityIn.motionX *= 0.20000000298023224D;
|
|
entityIn.motionZ *= 0.20000000298023224D;
|
|
@@ -971,7 +1089,7 @@
|
|
return ((Integer)this.dataManager.get(ROLLING_DIRECTION)).intValue();
|
|
}
|
|
|
|
- public abstract EntityMinecart.Type getType();
|
|
+ public abstract Type getType();
|
|
|
|
public IBlockState getDisplayTile()
|
|
{
|
|
@@ -1014,7 +1132,240 @@
|
|
{
|
|
this.getDataManager().set(SHOW_BLOCK, Boolean.valueOf(showBlock));
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public boolean processInitialInteract(EntityPlayer player, net.minecraft.util.EnumHand hand)
|
|
+ {
|
|
+ return net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.minecart.MinecartInteractEvent(this, player, hand));
|
|
+ }
|
|
|
|
+ /* =================================== FORGE START ===========================================*/
|
|
+ private BlockPos getCurrentRailPosition()
|
|
+ {
|
|
+ int x = MathHelper.floor(this.posX);
|
|
+ int y = MathHelper.floor(this.posY);
|
|
+ int z = MathHelper.floor(this.posZ);
|
|
+
|
|
+ if (BlockRailBase.isRailBlock(this.world, new BlockPos(x, y - 1, z))) y--;
|
|
+ return new BlockPos(x, y, z);
|
|
+ }
|
|
+
|
|
+ protected double getMaxSpeed()
|
|
+ {
|
|
+ if (!canUseRail()) return getMaximumSpeed();
|
|
+ BlockPos pos = this.getCurrentRailPosition();
|
|
+ IBlockState state = this.world.getBlockState(pos);
|
|
+ if (!BlockRailBase.isRailBlock(state)) return getMaximumSpeed();
|
|
+
|
|
+ float railMaxSpeed = ((BlockRailBase)state.getBlock()).getRailMaxSpeed(world, this, pos);
|
|
+ return Math.min(railMaxSpeed, getCurrentCartSpeedCapOnRail());
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Moved to allow overrides.
|
|
+ * This code handles minecart movement and speed capping when on a rail.
|
|
+ */
|
|
+ public void moveMinecartOnRail(BlockPos pos)
|
|
+ {
|
|
+ double mX = this.motionX;
|
|
+ double mZ = this.motionZ;
|
|
+
|
|
+ if (this.isBeingRidden())
|
|
+ {
|
|
+ mX *= 0.75D;
|
|
+ mZ *= 0.75D;
|
|
+ }
|
|
+
|
|
+ double max = this.getMaxSpeed();
|
|
+ mX = MathHelper.clamp(mX, -max, max);
|
|
+ mZ = MathHelper.clamp(mZ, -max, max);
|
|
+ this.move(MoverType.SELF, mX, 0.0D, mZ);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the current global Minecart Collision handler if none
|
|
+ * is registered, returns null
|
|
+ * @return The collision handler or null
|
|
+ */
|
|
+ @Nullable
|
|
+ public static net.minecraftforge.common.IMinecartCollisionHandler getCollisionHandler()
|
|
+ {
|
|
+ return collisionHandler;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets the global Minecart Collision handler, overwrites any
|
|
+ * that is currently set.
|
|
+ * @param handler The new handler
|
|
+ */
|
|
+ public static void setCollisionHandler(net.minecraftforge.common.IMinecartCollisionHandler handler)
|
|
+ {
|
|
+ collisionHandler = handler;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * This function returns an ItemStack that represents this cart.
|
|
+ * This should be an ItemStack that can be used by the player to place the cart,
|
|
+ * but is not necessary the item the cart drops when destroyed.
|
|
+ * @return An ItemStack that can be used to place the cart.
|
|
+ */
|
|
+ public ItemStack getCartItem()
|
|
+ {
|
|
+ if (this instanceof EntityMinecartFurnace)
|
|
+ {
|
|
+ return new ItemStack(Items.FURNACE_MINECART);
|
|
+ }
|
|
+ else if (this instanceof EntityMinecartChest)
|
|
+ {
|
|
+ return new ItemStack(Items.CHEST_MINECART);
|
|
+ }
|
|
+ else if (this instanceof EntityMinecartTNT)
|
|
+ {
|
|
+ return new ItemStack(Items.TNT_MINECART);
|
|
+ }
|
|
+ else if (this instanceof EntityMinecartHopper)
|
|
+ {
|
|
+ return new ItemStack(Items.HOPPER_MINECART);
|
|
+ }
|
|
+ else if (this instanceof EntityMinecartCommandBlock)
|
|
+ {
|
|
+ return new ItemStack(Items.COMMAND_BLOCK_MINECART);
|
|
+ }
|
|
+ return new ItemStack(Items.MINECART);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns true if this cart can currently use rails.
|
|
+ * This function is mainly used to gracefully detach a minecart from a rail.
|
|
+ * @return True if the minecart can use rails.
|
|
+ */
|
|
+ public boolean canUseRail()
|
|
+ {
|
|
+ return canUseRail;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Set whether the minecart can use rails.
|
|
+ * This function is mainly used to gracefully detach a minecart from a rail.
|
|
+ * @param use Whether the minecart can currently use rails.
|
|
+ */
|
|
+ public void setCanUseRail(boolean use)
|
|
+ {
|
|
+ canUseRail = use;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Return false if this cart should not call onMinecartPass() and should ignore Powered Rails.
|
|
+ * @return True if this cart should call onMinecartPass().
|
|
+ */
|
|
+ public boolean shouldDoRailFunctions()
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns true if this cart is self propelled.
|
|
+ * @return True if powered.
|
|
+ */
|
|
+ public boolean isPoweredCart()
|
|
+ {
|
|
+ return getType() == Type.FURNACE;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns true if this cart can be ridden by an Entity.
|
|
+ * @return True if this cart can be ridden.
|
|
+ */
|
|
+ public boolean canBeRidden()
|
|
+ {
|
|
+ return this.getType() == Type.RIDEABLE;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Getters/setters for physics variables
|
|
+ */
|
|
+
|
|
+ /**
|
|
+ * Returns the carts max speed when traveling on rails. Carts going faster
|
|
+ * than 1.1 cause issues with chunk loading. Carts cant traverse slopes or
|
|
+ * corners at greater than 0.5 - 0.6. This value is compared with the rails
|
|
+ * max speed and the carts current speed cap to determine the carts current
|
|
+ * max speed. A normal rail's max speed is 0.4.
|
|
+ *
|
|
+ * @return Carts max speed.
|
|
+ */
|
|
+ public float getMaxCartSpeedOnRail()
|
|
+ {
|
|
+ return 1.2f;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns the current speed cap for the cart when traveling on rails. This
|
|
+ * functions differs from getMaxCartSpeedOnRail() in that it controls
|
|
+ * current movement and cannot be overridden. The value however can never be
|
|
+ * higher than getMaxCartSpeedOnRail().
|
|
+ *
|
|
+ * @return
|
|
+ */
|
|
+ public final float getCurrentCartSpeedCapOnRail()
|
|
+ {
|
|
+ return currentSpeedRail;
|
|
+ }
|
|
+
|
|
+ public final void setCurrentCartSpeedCapOnRail(float value)
|
|
+ {
|
|
+ value = Math.min(value, getMaxCartSpeedOnRail());
|
|
+ currentSpeedRail = value;
|
|
+ }
|
|
+
|
|
+ public float getMaxSpeedAirLateral()
|
|
+ {
|
|
+ return maxSpeedAirLateral;
|
|
+ }
|
|
+
|
|
+ public void setMaxSpeedAirLateral(float value)
|
|
+ {
|
|
+ maxSpeedAirLateral = value;
|
|
+ }
|
|
+
|
|
+ public float getMaxSpeedAirVertical()
|
|
+ {
|
|
+ return maxSpeedAirVertical;
|
|
+ }
|
|
+
|
|
+ public void setMaxSpeedAirVertical(float value)
|
|
+ {
|
|
+ maxSpeedAirVertical = value;
|
|
+ }
|
|
+
|
|
+ public double getDragAir()
|
|
+ {
|
|
+ return dragAir;
|
|
+ }
|
|
+
|
|
+ public void setDragAir(double value)
|
|
+ {
|
|
+ dragAir = value;
|
|
+ flyingX = dragAir;
|
|
+ flyingY = dragAir;
|
|
+ flyingZ = dragAir;
|
|
+ }
|
|
+
|
|
+ public double getSlopeAdjustment()
|
|
+ {
|
|
+ return 0.0078125D;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called from Detector Rails to retrieve a redstone power level for comparators.
|
|
+ */
|
|
+ public int getComparatorLevel()
|
|
+ {
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ /* =================================== FORGE END ===========================================*/
|
|
+
|
|
public static enum Type
|
|
{
|
|
RIDEABLE(0, "MinecartRideable"),
|
|
@@ -1025,7 +1376,7 @@
|
|
HOPPER(5, "MinecartHopper"),
|
|
COMMAND_BLOCK(6, "MinecartCommandBlock");
|
|
|
|
- private static final Map<Integer, EntityMinecart.Type> BY_ID = Maps.<Integer, EntityMinecart.Type>newHashMap();
|
|
+ private static final Map<Integer, Type> BY_ID = Maps.<Integer, Type>newHashMap();
|
|
private final int id;
|
|
private final String name;
|
|
|
|
@@ -1048,16 +1399,38 @@
|
|
@SideOnly(Side.CLIENT)
|
|
public static EntityMinecart.Type getById(int idIn)
|
|
{
|
|
- EntityMinecart.Type entityminecart$type = BY_ID.get(Integer.valueOf(idIn));
|
|
+ Type entityminecart$type = BY_ID.get(Integer.valueOf(idIn));
|
|
return entityminecart$type == null ? RIDEABLE : entityminecart$type;
|
|
}
|
|
|
|
static
|
|
{
|
|
- for (EntityMinecart.Type entityminecart$type : values())
|
|
+ for (Type entityminecart$type : values())
|
|
{
|
|
BY_ID.put(Integer.valueOf(entityminecart$type.getId()), entityminecart$type);
|
|
}
|
|
}
|
|
}
|
|
+
|
|
+ // CraftBukkit start - Methods for getting and setting flying and derailed velocity modifiers
|
|
+ public Vector getFlyingVelocityMod() {
|
|
+ return new Vector(flyingX, flyingY, flyingZ);
|
|
+ }
|
|
+
|
|
+ public void setFlyingVelocityMod(Vector flying) {
|
|
+ flyingX = flying.getX();
|
|
+ flyingY = flying.getY();
|
|
+ flyingZ = flying.getZ();
|
|
+ }
|
|
+
|
|
+ public Vector getDerailedVelocityMod() {
|
|
+ return new Vector(derailedX, derailedY, derailedZ);
|
|
+ }
|
|
+
|
|
+ public void setDerailedVelocityMod(Vector derailed) {
|
|
+ derailedX = derailed.getX();
|
|
+ derailedY = derailed.getY();
|
|
+ derailedZ = derailed.getZ();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|