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();
}
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;
}
}
}
}
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);
}
}
Aggregations