use of mods.railcraft.common.core.RailcraftConstants.IS_REVERSED_VARIABLE_INDEX in project Railcraft by Railcraft.
the class MinecartHooks method onMinecartUpdate.
@SuppressWarnings("unused")
@SubscribeEvent
public void onMinecartUpdate(MinecartUpdateEvent event) {
EntityMinecart cart = event.getMinecart();
NBTTagCompound data = cart.getEntityData();
// Fix flip
float distance = MathTools.getDistanceBetweenAngles(cart.rotationYaw, cart.prevRotationYaw);
float cutoff = 120F;
if (distance < -cutoff || distance >= cutoff) {
cart.rotationYaw += 180.0F;
boolean reverse = ObfuscationReflectionHelper.getPrivateValue(EntityMinecart.class, cart, IS_REVERSED_VARIABLE_INDEX);
ObfuscationReflectionHelper.setPrivateValue(EntityMinecart.class, cart, !reverse, IS_REVERSED_VARIABLE_INDEX);
cart.rotationYaw = cart.rotationYaw % 360.0F;
}
// } else
if (data.getBoolean("ghost")) {
cart.setGlowing(false);
data.setBoolean("ghost", false);
}
// Code Added by Yopu to replace vanilla carts, deemed incomplete and unnecessary, pursuing other solutions
// if (classReplacements.containsKey(cart.getClass())) {
// cart.setDead();
// if (Game.isHost(cart.worldObj)) {
// EnumCart enumCart = classReplacements.get(cart.getClass());
// GameProfile cartOwner = CartTools.getCartOwner(cart);
// int x = MathHelper.floor_double(cart.posX);
// int y = MathHelper.floor_double(cart.posY);
// int z = MathHelper.floor_double(cart.posZ);
// CartUtils.placeCart(enumCart, cartOwner, enumCart.getCartItem(), cart.worldObj, x, y, z);
// }
// return;
// }
Block block = WorldPlugin.getBlock(cart.worldObj, event.getPos());
int launched = data.getInteger("Launched");
if (TrackTools.isRailBlock(block)) {
cart.fallDistance = 0;
if (cart.isBeingRidden())
cart.getPassengers().forEach(p -> p.fallDistance = 0);
if (launched > 1)
land(cart);
} else if (launched == 1) {
data.setInteger("Launched", 2);
cart.setCanUseRail(true);
} else if (launched > 1 && (cart.onGround || cart.isInsideOfMaterial(Material.CIRCUITS)))
land(cart);
int mountPrevention = data.getInteger("MountPrevention");
if (mountPrevention > 0) {
mountPrevention--;
data.setInteger("MountPrevention", mountPrevention);
}
byte elevator = data.getByte("elevator");
if (elevator < BlockTrackElevator.ELEVATOR_TIMER) {
cart.setNoGravity(false);
}
if (elevator > 0) {
elevator--;
data.setByte("elevator", elevator);
}
byte derail = data.getByte("derail");
if (derail > 0) {
derail--;
data.setByte("derail", derail);
}
if (data.getBoolean("explode")) {
cart.getEntityData().setBoolean("explode", false);
CartTools.explodeCart(cart);
}
if (data.getBoolean(CartTools.HIGH_SPEED_TAG))
if (CartTools.cartVelocityIsLessThan(cart, HighSpeedTools.SPEED_CUTOFF))
data.setBoolean(CartTools.HIGH_SPEED_TAG, false);
else if (data.getInteger("Launched") == 0)
HighSpeedTools.checkSafetyAndExplode(cart.worldObj, event.getPos(), cart);
cart.motionX = Math.copySign(Math.min(Math.abs(cart.motionX), 9.5), cart.motionX);
cart.motionY = Math.copySign(Math.min(Math.abs(cart.motionY), 9.5), cart.motionY);
cart.motionZ = Math.copySign(Math.min(Math.abs(cart.motionZ), 9.5), cart.motionZ);
// List entities = cart.worldObj.getEntitiesWithinAABB(EntityLiving.class, getMinecartCollisionBox(cart, COLLISION_EXPANSION));
//
// if (entities != null) {
// for (Entity entity : (List<Entity>) entities) {
// if (entity != cart.riddenByEntity && entity.canBePushed()) {
// cart.applyEntityCollision(entity);
// }
// }
// }
}
Aggregations