split up util methods for later use

This commit is contained in:
Ellpeck 2016-07-20 22:23:03 +02:00
parent e9955348d8
commit 4bf0fce0d2

View file

@ -59,27 +59,38 @@ public final class WorldUtil{
//This is probably hideous. Just saying. //This is probably hideous. Just saying.
public static boolean doItemInteraction(int slotExtract, int slotInsert, TileEntity extract, TileEntity insert, EnumFacing extractSide, EnumFacing insertSide){ public static boolean doItemInteraction(int slotExtract, int slotInsert, TileEntity extract, TileEntity insert, EnumFacing extractSide, EnumFacing insertSide){
if(extract.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide) && insert.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide)){ ItemStack theoreticalExtract = extractItem(slotExtract, extract, extractSide, Integer.MAX_VALUE, true);
IItemHandler extractCap = extract.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide); if(theoreticalExtract != null){
IItemHandler insertCap = insert.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide); ItemStack remaining = insertItem(slotInsert, insert, insertSide, theoreticalExtract, false);
if(!ItemStack.areItemStacksEqual(remaining, theoreticalExtract)){
if(extractCap != null && insertCap != null){ int toExtract = remaining == null ? theoreticalExtract.stackSize : theoreticalExtract.stackSize-remaining.stackSize;
ItemStack theoreticalExtract = extractCap.extractItem(slotExtract, Integer.MAX_VALUE, true); extractItem(slotExtract, extract, extractSide, toExtract, false);
if(theoreticalExtract != null){ return true;
ItemStack remaining = insertCap.insertItem(slotInsert, theoreticalExtract, false);
if(!ItemStack.areItemStacksEqual(remaining, theoreticalExtract)){
int toExtract = remaining == null ? theoreticalExtract.stackSize : theoreticalExtract.stackSize-remaining.stackSize;
extractCap.extractItem(slotExtract, toExtract, false);
return true;
}
}
} }
} }
return false; return false;
} }
public static ItemStack insertItem(int slotInsert, TileEntity insert, EnumFacing insertSide, ItemStack stack, boolean simulate){
if(insert.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide)){
IItemHandler insertCap = insert.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide);
if(insertCap != null){
return insertCap.insertItem(slotInsert, stack, simulate);
}
}
return stack;
}
public static ItemStack extractItem(int slotExtract, TileEntity extract, EnumFacing extractSide, int amount, boolean simulate){
if(extract.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide)){
IItemHandler extractCap = extract.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide);
if(extractCap != null){
return extractCap.extractItem(slotExtract, amount, simulate);
}
}
return null;
}
public static void doEnergyInteraction(TileEntity tile){ public static void doEnergyInteraction(TileEntity tile){
for(EnumFacing side : EnumFacing.values()){ for(EnumFacing side : EnumFacing.values()){
TileEntity otherTile = tile.getWorld().getTileEntity(tile.getPos().offset(side)); TileEntity otherTile = tile.getWorld().getTileEntity(tile.getPos().offset(side));