Search in sources :

Example 51 with EntityMinecart

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

the class LinkageHandler method canMinecartTick.

@SubscribeEvent
public void canMinecartTick(EntityEvent.CanUpdate event) {
    if (event.getEntity() instanceof EntityMinecart) {
        EntityMinecart cart = (EntityMinecart) event.getEntity();
        Train train = Train.getTrain(cart);
        for (EntityCartWorldspike worldspike : train.getCarts(EntityCartWorldspike.class)) {
            if (worldspike.hasActiveTicket()) {
                event.setCanUpdate(true);
                return;
            }
        }
    }
}
Also used : EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 52 with EntityMinecart

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

the class Train method buildTrain.

private void buildTrain(@Nullable EntityMinecart prev, EntityMinecart next) {
    _addLink(prev, next);
    LinkageManager lm = LinkageManager.instance();
    EntityMinecart linkA = lm.getLinkedCartA(next);
    EntityMinecart linkB = lm.getLinkedCartB(next);
    if (linkA != null && linkA != prev && !containsCart(linkA))
        buildTrain(next, linkA);
    if (linkB != null && linkB != prev && !containsCart(linkB))
        buildTrain(next, linkB);
}
Also used : EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 53 with EntityMinecart

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

the class LinkageManager method numLinkedCarts.

private int numLinkedCarts(EntityMinecart prev, EntityMinecart next) {
    int count = 1;
    EntityMinecart linkA = getLinkedCartA(next);
    EntityMinecart linkB = getLinkedCartB(next);
    if (linkA != null && linkA != prev)
        count += numLinkedCarts(next, linkA);
    if (linkB != null && linkB != prev)
        count += numLinkedCarts(next, linkB);
    return count;
}
Also used : EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 54 with EntityMinecart

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

the class CartBaseEnergy method extractEnergy.

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

Example 55 with EntityMinecart

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

the class TileItemManipulator method processCart.

@Override
protected void processCart(EntityMinecart cart) {
    chests.clear();
    chests.add(invBuffer);
    chests.addAll(invCache.getAdjacentInventories());
    InventoryComposite cartInv = InventoryComposite.of(InventoryFactory.get(cart, getFacing().getOpposite()));
    if (cartInv.isEmpty()) {
        sendCart(cart);
        return;
    }
    this.cart = cartInv;
    switch(getMode()) {
        case TRANSFER:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                filterManifest.entrySet().stream().filter(entry -> transferredItems.count(entry.getElement()) < entry.getCount()).anyMatch(entry -> {
                    ItemStack moved = InvTools.moveOneItem(getSource(), getDestination(), StackFilters.matches(entry.getElement().get()));
                    if (!InvTools.isEmpty(moved)) {
                        setProcessing(true);
                        transferredItems.add(entry.getElement());
                        return true;
                    }
                    return false;
                });
                break;
            }
        case STOCK:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                Multiset<StackKey> destManifest = InvTools.createManifest(getDestination(), filterManifest.elementSet());
                moveItem(filterManifest.entrySet().stream().filter(entry -> destManifest.count(entry.getElement()) < entry.getCount()));
                break;
            }
        case EXCESS:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                Multiset<StackKey> sourceManifest = InvTools.createManifest(getSource(), filterManifest.elementSet());
                moveItem(filterManifest.entrySet().stream().filter(entry -> sourceManifest.count(entry.getElement()) > entry.getCount()));
                if (!isProcessing()) {
                    Predicate<ItemStack> keep = filterManifest.elementSet().stream().map(e -> StackFilters.matches(e.get())).reduce(StackFilters.none(), Predicate::or);
                    ItemStack moved = InvTools.moveOneItemExcept(getSource(), getDestination(), keep);
                    itemMoved(moved);
                }
                break;
            }
        case ALL:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                if (filterManifest.isEmpty()) {
                    ItemStack moved = InvTools.moveOneItem(getSource(), getDestination());
                    itemMoved(moved);
                } else {
                    moveItem(filterManifest.entrySet().stream());
                }
                break;
            }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) EnumMap(java.util.EnumMap) Multiset(com.google.common.collect.Multiset) Predicate(java.util.function.Predicate) EntityMinecart(net.minecraft.entity.item.EntityMinecart) IOException(java.io.IOException) RailcraftInputStream(mods.railcraft.common.util.network.RailcraftInputStream) StackFilters(mods.railcraft.common.util.inventory.filters.StackFilters) InventoryMapper(mods.railcraft.common.util.inventory.wrappers.InventoryMapper) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) ItemStack(net.minecraft.item.ItemStack) InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) Stream(java.util.stream.Stream) HashMultiset(com.google.common.collect.HashMultiset) StackKey(mods.railcraft.common.util.collections.StackKey) MultiButtonController(mods.railcraft.common.gui.buttons.MultiButtonController) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Slot(net.minecraft.inventory.Slot) mods.railcraft.common.util.inventory(mods.railcraft.common.util.inventory) IInventoryComposite(mods.railcraft.common.util.inventory.wrappers.IInventoryComposite) Nullable(javax.annotation.Nullable) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) IInventoryComposite(mods.railcraft.common.util.inventory.wrappers.IInventoryComposite) ItemStack(net.minecraft.item.ItemStack) Predicate(java.util.function.Predicate)

Aggregations

EntityMinecart (net.minecraft.entity.item.EntityMinecart)75 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 ItemStack (net.minecraft.item.ItemStack)17 List (java.util.List)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)11 Entity (net.minecraft.entity.Entity)9 DamageSource (net.minecraft.util.DamageSource)8 World (net.minecraft.world.World)8 ItemNTP32Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit)6 ItemNTP8Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit)6 ILinkageManager (mods.railcraft.api.carts.ILinkageManager)6 LocoBase (club.nsdn.nyasamarailway.entity.LocoBase)5 Nullable (javax.annotation.Nullable)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 MinecartUpdateEvent (net.minecraftforge.event.entity.minecart.MinecartUpdateEvent)4 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 ArrayList (java.util.ArrayList)3