use of mods.railcraft.api.carts.ILinkableCart in project Railcraft by Railcraft.
the class CrowbarHandler method onEntityInteract.
@SubscribeEvent
public void onEntityInteract(MinecartInteractEvent event) {
EntityPlayer thePlayer = event.getPlayer();
Entity entity = event.getEntity();
EnumHand hand = event.getHand();
if (event.getItem() != null && event.getItem().getItem() instanceof IToolCrowbar)
event.setCanceled(true);
ItemStack stack = event.getItem();
if (!InvTools.isEmpty(stack) && stack.getItem() instanceof IToolCrowbar) {
thePlayer.swingArm(event.getHand());
event.setCanceled(true);
} else
return;
if (Game.isClient(thePlayer.worldObj))
return;
boolean used = false;
IToolCrowbar crowbar = (IToolCrowbar) stack.getItem();
if (entity instanceof EntityMinecart) {
EntityMinecart cart = (EntityMinecart) entity;
if (RailcraftModuleManager.isModuleEnabled(ModuleTrain.class) && crowbar.canLink(thePlayer, hand, stack, cart)) {
boolean linkable = cart instanceof ILinkableCart;
if (!linkable || ((ILinkableCart) cart).isLinkable()) {
EntityMinecart last = linkMap.remove(thePlayer);
if (last != null && last.isEntityAlive()) {
LinkageManager lm = LinkageManager.instance();
if (lm.areLinked(cart, last, false)) {
lm.breakLink(cart, last);
used = true;
ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.broken");
LinkageManager.printDebug("Reason For Broken Link: User removed link.");
} else {
used = lm.createLink(last, (EntityMinecart) entity);
if (used)
ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.created");
}
if (!used)
ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.failed");
} else {
linkMap.put(thePlayer, (EntityMinecart) entity);
ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.started");
}
}
if (used)
crowbar.onLink(thePlayer, hand, stack, cart);
} else if (crowbar.canBoost(thePlayer, hand, stack, cart)) {
thePlayer.addExhaustion(1F);
//noinspection StatementWithEmptyBody
if (thePlayer.getRidingEntity() != null) {
// NOOP
} else //noinspection StatementWithEmptyBody
if (cart instanceof EntityTunnelBore) {
// NOOP
} else if (cart instanceof IDirectionalCart)
((IDirectionalCart) cart).reverse();
else {
int lvl = RailcraftEnchantments.SMACK.getLevel(stack);
if (lvl == 0) {
CartTools.smackCart(cart, thePlayer, SMACK_VELOCITY);
}
float smackVelocity = SMACK_VELOCITY * (float) Math.pow(1.7, lvl);
Train train = Train.getTrain(cart);
smackVelocity /= (float) Math.pow(train.size(), 1D / (1 + lvl));
for (EntityMinecart each : train) {
CartTools.smackCart(cart, each, thePlayer, smackVelocity);
}
}
crowbar.onBoost(thePlayer, hand, stack, cart);
}
}
}
use of mods.railcraft.api.carts.ILinkableCart in project Railcraft by Railcraft.
the class LinkageManager method breakLink.
@Nullable
private EntityMinecart breakLink(EntityMinecart cart, LinkType linkType) {
Train.deleteTrain(cart);
UUID link = getLink(cart, linkType);
removeLinkTags(cart, linkType);
EntityMinecart other = CartTools.getCartFromUUID(cart.worldObj, link);
if (other != null) {
breakLink(other, cart);
}
if (cart instanceof ILinkableCart)
((ILinkableCart) cart).onLinkBroken(other);
printDebug("Carts {0}({1}) and {2}({3}) unlinked ({4}).", getLinkageId(cart), cart, link, other != null ? other : "null", linkType.name());
return other;
}
Aggregations