mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-05 13:29:10 +01:00
31 lines
1.2 KiB
Java
31 lines
1.2 KiB
Java
package de.ellpeck.prettypipes;
|
|
|
|
import net.minecraft.inventory.InventoryHelper;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.Direction;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
public final class Utility {
|
|
|
|
public static <T extends TileEntity> T getTileEntity(Class<T> type, World world, BlockPos pos) {
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
return type.isInstance(tile) ? (T) tile : null;
|
|
}
|
|
|
|
public static void dropInventory(TileEntity tile, IItemHandler inventory) {
|
|
BlockPos pos = tile.getPos();
|
|
for (int i = 0; i < inventory.getSlots(); i++) {
|
|
ItemStack stack = inventory.getStackInSlot(i);
|
|
if (!stack.isEmpty())
|
|
InventoryHelper.spawnItemStack(tile.getWorld(), pos.getX(), pos.getY(), pos.getZ(), stack);
|
|
}
|
|
}
|
|
|
|
public static Direction getDirectionFromOffset(BlockPos pos, BlockPos other) {
|
|
BlockPos diff = pos.subtract(other);
|
|
return Direction.getFacingFromVector(diff.getX(), diff.getY(), diff.getZ());
|
|
}
|
|
}
|