Search in sources :

Example 6 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class PacketShuntingAura method writeData.

@Override
public void writeData(RailcraftOutputStream data) throws IOException {
    data.writeInt(carts.size());
    for (EntityMinecart cart : carts) {
        data.writeUUID(cart.getPersistentID());
        data.writeUUID(Train.getTrainUUID(cart));
        LinkageManager lm = LinkageManager.instance();
        data.writeUUID(lm.getLinkA(cart));
        data.writeUUID(lm.getLinkB(cart));
    }
}
Also used : EntityMinecart(net.minecraft.entity.item.EntityMinecart) LinkageManager(mods.railcraft.common.carts.LinkageManager)

Example 7 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart 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 8 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class CartBaseEnergy method injectEnergy.

@Override
public double injectEnergy(Object source, double amount, int tier, boolean ignoreTransferLimit, boolean simulate, boolean passAlong) {
    if (tier < getTier())
        return amount;
    double extra = 0;
    if (!ignoreTransferLimit) {
        extra = Math.max(amount - getTransferLimit(), 0);
        amount = Math.min(amount, getTransferLimit());
    }
    double e = getEnergy() + amount;
    int capacity = getCapacity();
    if (e > capacity) {
        extra += e - capacity;
        e = capacity;
    }
    if (!simulate)
        setEnergy(e);
    if (!passAlong)
        return extra;
    try {
        ILinkageManager lm = CartToolsAPI.getLinkageManager(worldObj);
        EntityMinecart linkedCart = lm.getLinkedCartA(this);
        if (extra > 0 && linkedCart != source && linkedCart instanceof IEnergyTransfer)
            extra = ((IEnergyTransfer) linkedCart).injectEnergy(this, extra, tier, ignoreTransferLimit, simulate, true);
        linkedCart = lm.getLinkedCartB(this);
        if (extra > 0 && linkedCart != source && linkedCart instanceof IEnergyTransfer)
            extra = ((IEnergyTransfer) linkedCart).injectEnergy(this, extra, tier, ignoreTransferLimit, simulate, true);
    } catch (Throwable t) {
        APIErrorHandler.versionMismatch(IEnergyTransfer.class);
    }
    return extra;
}
Also used : ILinkageManager(mods.railcraft.api.carts.ILinkageManager) IEnergyTransfer(mods.railcraft.api.carts.IEnergyTransfer) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 9 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class TrackKitSwitch method getBestCartForVisualState.

// To render the state of the track most accurately, we choose the "best" cart from our set of
// carts based on distance.
@Nullable
private EntityMinecart getBestCartForVisualState(List<UUID> cartsOnTrack) {
    World world = theWorldAsserted();
    UUID cartUUID = null;
    if (!cartsOnTrack.isEmpty()) {
        cartUUID = cartsOnTrack.get(0);
        return CartTools.getCartFromUUID(world, cartUUID);
    } else {
        EntityMinecart closestCart = null;
        ArrayList<UUID> allCarts = new ArrayList<UUID>();
        allCarts.addAll(lockingCarts);
        allCarts.addAll(springingCarts);
        allCarts.addAll(decidingCarts);
        for (UUID testCartUUID : allCarts) {
            if (closestCart == null) {
                closestCart = CartTools.getCartFromUUID(world, testCartUUID);
            } else {
                double closestDist = crudeDistance(closestCart);
                EntityMinecart testCart = CartTools.getCartFromUUID(world, testCartUUID);
                if (testCart != null) {
                    double testDist = crudeDistance(testCart);
                    if (testDist < closestDist)
                        closestCart = testCart;
                }
            }
        }
        return closestCart;
    }
}
Also used : World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart) Nullable(javax.annotation.Nullable)

Example 10 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class TrackKitSwitch method update.

@Override
public void update() {
    super.update();
    boolean wasSwitched = isVisuallySwitched();
    if (locked > 0)
        locked--;
    if (sprung > 0)
        sprung--;
    if (locked == 0 && sprung == 0) {
        // Clear out our sets so we don't keep
        lockingCarts.clear();
        // these carts forever
        springingCarts.clear();
        decidingCarts.clear();
        currentCart = null;
    }
    // updating carts we just found in appropriate sets
    // this keeps exiting carts from getting mixed up with entering carts
    updateSet(lockingCarts, getCartsAtLockEntrance(), springingCarts, decidingCarts);
    updateSet(springingCarts, getCartsAtSpringEntrance(), lockingCarts, decidingCarts);
    updateSet(decidingCarts, getCartsAtDecisionEntrance(), lockingCarts, springingCarts);
    // We only set sprung/locked when a cart enters our track, this is
    // mainly for visual purposes as the subclass's getRailDirectionRaw()
    // determines which direction the carts actually take.
    List<UUID> cartsOnTrack = CartTools.getMinecartUUIDsAt(theWorldAsserted(), getTile().getPos(), 0.3f);
    EntityMinecart bestCart = getBestCartForVisualState(cartsOnTrack);
    // We must ask the switch every tick so we can update shouldSwitch properly
    switchDevice = getSwitchDevice();
    if (switchDevice == null) {
        shouldSwitch = false;
    } else {
        shouldSwitch = switchDevice.shouldSwitch(bestCart);
    }
    // Only allow cartsOnTrack to actually spring or lock the track
    if (bestCart != null && cartsOnTrack.contains(bestCart.getPersistentID())) {
        if (shouldSwitchForCart(bestCart)) {
            springTrack(bestCart.getPersistentID());
        } else {
            lockTrack(bestCart.getPersistentID());
        }
    }
    if (isVisuallySwitched() != wasSwitched) {
        if (switchDevice != null) {
            switchDevice.onSwitch(isVisuallySwitched());
        }
        sendUpdateToClient();
    }
}
Also used : EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Aggregations

EntityMinecart (net.minecraft.entity.item.EntityMinecart)45 ItemStack (net.minecraft.item.ItemStack)11 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 ILinkageManager (mods.railcraft.api.carts.ILinkageManager)6 World (net.minecraft.world.World)6 Nullable (javax.annotation.Nullable)5 Entity (net.minecraft.entity.Entity)5 List (java.util.List)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 ArrayList (java.util.ArrayList)3 IEnergyTransfer (mods.railcraft.api.carts.IEnergyTransfer)2 ILinkableCart (mods.railcraft.api.carts.ILinkableCart)2 ItemGoggles (mods.railcraft.common.items.ItemGoggles)2 EntityItem (net.minecraft.entity.item.EntityItem)2 Item (net.minecraft.item.Item)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 ShaderWrapper_Direct (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper_Direct)1 HashMultiset (com.google.common.collect.HashMultiset)1