Search in sources :

Example 1 with EntityMinecartContainer

use of net.minecraft.entity.item.EntityMinecartContainer in project MinecraftForge by MinecraftForge.

the class ForgeHooks method onTravelToDimension.

public static boolean onTravelToDimension(Entity entity, int dimension) {
    EntityTravelToDimensionEvent event = new EntityTravelToDimensionEvent(entity, dimension);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled()) {
        // Revert variable back to true as it would have been set to false
        if (entity instanceof EntityMinecartContainer) {
            ((EntityMinecartContainer) entity).dropContentsWhenDead = true;
        }
    }
    return !event.isCanceled();
}
Also used : EntityMinecartContainer(net.minecraft.entity.item.EntityMinecartContainer) EntityTravelToDimensionEvent(net.minecraftforge.event.entity.EntityTravelToDimensionEvent)

Example 2 with EntityMinecartContainer

use of net.minecraft.entity.item.EntityMinecartContainer in project MineFactoryReloaded by powercrystals.

the class BlockRailCargoPickup method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (world.isRemote || !(entity instanceof EntityMinecartContainer)) {
        return;
    }
    IInventoryManager minecart = InventoryManager.create((EntityMinecartContainer) entity, ForgeDirection.UNKNOWN);
    for (Entry<ForgeDirection, IInventory> inventory : UtilInventory.findChests(world, x, y, z).entrySet()) {
        IInventoryManager chest = InventoryManager.create(inventory.getValue(), inventory.getKey().getOpposite());
        for (Entry<Integer, ItemStack> contents : chest.getContents().entrySet()) {
            if (contents.getValue() == null) {
                continue;
            }
            ItemStack stackToAdd = contents.getValue().copy();
            ItemStack remaining = minecart.addItem(stackToAdd);
            if (remaining != null) {
                stackToAdd.stackSize -= remaining.stackSize;
                if (stackToAdd.stackSize > 0) {
                    chest.removeItem(stackToAdd.stackSize, stackToAdd);
                }
            } else {
                chest.removeItem(stackToAdd.stackSize, stackToAdd);
                break;
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) EntityMinecartContainer(net.minecraft.entity.item.EntityMinecartContainer) ForgeDirection(net.minecraftforge.common.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Example 3 with EntityMinecartContainer

use of net.minecraft.entity.item.EntityMinecartContainer in project MineFactoryReloaded by powercrystals.

the class BlockRailCargoDropoff method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (world.isRemote || !(entity instanceof EntityMinecartContainer)) {
        return;
    }
    IInventoryManager minecart = InventoryManager.create((EntityMinecartContainer) entity, ForgeDirection.UNKNOWN);
    for (Entry<Integer, ItemStack> contents : minecart.getContents().entrySet()) {
        if (contents.getValue() == null) {
            continue;
        }
        ItemStack stackToAdd = contents.getValue().copy();
        ItemStack remaining = UtilInventory.dropStack(world, new BlockPosition(x, y, z), contents.getValue(), ForgeDirection.VALID_DIRECTIONS, ForgeDirection.UNKNOWN);
        if (remaining != null) {
            stackToAdd.stackSize -= remaining.stackSize;
        }
        minecart.removeItem(stackToAdd.stackSize, stackToAdd);
    }
}
Also used : EntityMinecartContainer(net.minecraft.entity.item.EntityMinecartContainer) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Aggregations

EntityMinecartContainer (net.minecraft.entity.item.EntityMinecartContainer)3 ItemStack (net.minecraft.item.ItemStack)2 IInventoryManager (powercrystals.core.inventory.IInventoryManager)2 IInventory (net.minecraft.inventory.IInventory)1 ForgeDirection (net.minecraftforge.common.ForgeDirection)1 EntityTravelToDimensionEvent (net.minecraftforge.event.entity.EntityTravelToDimensionEvent)1 BlockPosition (powercrystals.core.position.BlockPosition)1