Search in sources :

Example 1 with IToolCrowbar

use of mods.railcraft.api.core.items.IToolCrowbar in project Railcraft by Railcraft.

the class TrackKitLocomotive method blockActivated.

@Override
public boolean blockActivated(EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem) {
    if (!InvTools.isEmpty(heldItem) && heldItem.getItem() instanceof IToolCrowbar) {
        IToolCrowbar crowbar = (IToolCrowbar) heldItem.getItem();
        if (crowbar.canWhack(player, hand, heldItem, getPos())) {
            mode = EnumTools.next(mode, LocoMode.VALUES);
            crowbar.onWhack(player, hand, heldItem, getPos());
            sendUpdateToClient();
            return true;
        }
    }
    return false;
}
Also used : IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar)

Example 2 with IToolCrowbar

use of mods.railcraft.api.core.items.IToolCrowbar in project Railcraft by Railcraft.

the class TrackKitCoupler method blockActivated.

@Override
public boolean blockActivated(EntityPlayer player, EnumHand hand, ItemStack heldItem) {
    if (!InvTools.isEmpty(heldItem) && heldItem.getItem() instanceof IToolCrowbar) {
        IToolCrowbar crowbar = (IToolCrowbar) heldItem.getItem();
        if (crowbar.canWhack(player, hand, heldItem, getPos())) {
            Mode m;
            if (player.isSneaking())
                m = mode.previous();
            else
                m = mode.next();
            crowbar.onWhack(player, hand, heldItem, getPos());
            if (Game.isHost(theWorldAsserted()))
                setMode(m);
            else
                ChatPlugin.sendLocalizedChat(player, "gui.railcraft.track.mode.change", "ยง5" + LocalizationPlugin.translate("gui.railcraft.track.coupler.mode." + m.getName()));
            return true;
        }
    }
    return false;
}
Also used : IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar)

Example 3 with IToolCrowbar

use of mods.railcraft.api.core.items.IToolCrowbar 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);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ILinkableCart(mods.railcraft.api.carts.ILinkableCart) IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar) ModuleTrain(mods.railcraft.common.modules.ModuleTrain) EntityMinecart(net.minecraft.entity.item.EntityMinecart) EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ModuleTrain(mods.railcraft.common.modules.ModuleTrain) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IToolCrowbar

use of mods.railcraft.api.core.items.IToolCrowbar in project Railcraft by Railcraft.

the class TrackKitThrottle method blockActivated.

@Override
public boolean blockActivated(EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem) {
    if (!InvTools.isEmpty(heldItem) && heldItem.getItem() instanceof IToolCrowbar) {
        IToolCrowbar crowbar = (IToolCrowbar) heldItem.getItem();
        if (crowbar.canWhack(player, hand, heldItem, getPos())) {
            if (speed == LocoSpeed.MAX) {
                if (!getReverse()) {
                    setReverse(true);
                } else {
                    setReverse(false);
                    setSpeed(EnumTools.next(speed, LocoSpeed.VALUES));
                }
            } else {
                setSpeed(EnumTools.next(speed, LocoSpeed.VALUES));
            }
            crowbar.onWhack(player, hand, heldItem, getPos());
            sendUpdateToClient();
            return true;
        }
    }
    return false;
}
Also used : IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar)

Example 5 with IToolCrowbar

use of mods.railcraft.api.core.items.IToolCrowbar in project Railcraft by Railcraft.

the class TrackKitPriming method blockActivated.

@Override
public boolean blockActivated(EntityPlayer player, EnumHand hand, ItemStack heldItem) {
    if (!InvTools.isEmpty(heldItem) && heldItem.getItem() instanceof IToolCrowbar) {
        IToolCrowbar crowbar = (IToolCrowbar) heldItem.getItem();
        if (crowbar.canWhack(player, hand, heldItem, getPos())) {
            GuiHandler.openGui(EnumGui.TRACK_PRIMING, player, theWorldAsserted(), getPos().getX(), getPos().getY(), getPos().getZ());
            crowbar.onWhack(player, hand, heldItem, getPos());
            return true;
        }
    }
    return false;
}
Also used : IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar)

Aggregations

IToolCrowbar (mods.railcraft.api.core.items.IToolCrowbar)13 ItemStack (net.minecraft.item.ItemStack)3 WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ILinkableCart (mods.railcraft.api.carts.ILinkableCart)1 ModuleTrain (mods.railcraft.common.modules.ModuleTrain)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1 EntitySlime (net.minecraft.entity.monster.EntitySlime)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumHand (net.minecraft.util.EnumHand)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1