if (!ModuleManager.isModuleLoaded(Module.TRAIN))
return;
boolean used = false;
if (stack != null && stack.getItem() instanceof IToolCrowbar) {
IToolCrowbar crowbar = (IToolCrowbar) stack.getItem();
if (entity instanceof EntityMinecart) {
EntityMinecart cart = (EntityMinecart) entity;
if (crowbar.canLink(thePlayer, stack, cart)) {
boolean linkable = cart instanceof ILinkableCart;
if (!linkable || (linkable && ((ILinkableCart) cart).isLinkable()))
if (linkMap.containsKey(thePlayer)) {
ILinkageManager lm = LinkageManager.instance();
EntityMinecart last = linkMap.remove(thePlayer);
if (lm.areLinked(cart, last)) {
lm.breakLink(cart, last);
used = true;
ChatPlugin.sendLocalizedChat(thePlayer, "railcraft.gui.link.broken");
LinkageManager.printDebug("Reason For Broken Link: User removed link.");
} else {
used = lm.createLink((EntityMinecart) entity, (EntityMinecart) last);
if (used)
ChatPlugin.sendLocalizedChat(thePlayer, "railcraft.gui.link.created");
}
if (!used)
ChatPlugin.sendLocalizedChat(thePlayer, "railcraft.gui.link.failed");
} else {
linkMap.put(thePlayer, (EntityMinecart) entity);
ChatPlugin.sendLocalizedChat(thePlayer, "railcraft.gui.link.started");
}
if (used)
crowbar.onLink(thePlayer, stack, cart);
} else if (crowbar.canBoost(thePlayer, stack, cart)) {
thePlayer.addExhaustion(1F);
if (thePlayer.ridingEntity != null) {
// NOOP
} else if (cart instanceof EntityTunnelBore) {
// NOOP
} else if (cart instanceof IDirectionalCart)
((IDirectionalCart) cart).reverse();
else {
if (cart.posX < thePlayer.posX)
cart.motionX -= SMACK_VELOCITY;
else
cart.motionX += SMACK_VELOCITY;
if (cart.posZ < thePlayer.posZ)
cart.motionZ -= SMACK_VELOCITY;
else
cart.motionZ += SMACK_VELOCITY;
}
crowbar.onBoost(thePlayer, stack, cart);
}
}
}
if (used)
event.setCanceled(true);