mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
Make this method less hideous
This commit is contained in:
parent
7524ee52fd
commit
da082cbfa5
1 changed files with 12 additions and 28 deletions
|
@ -54,40 +54,24 @@ import java.util.List;
|
||||||
|
|
||||||
public final class WorldUtil{
|
public final class WorldUtil{
|
||||||
|
|
||||||
//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){
|
||||||
ItemStack theoreticalExtract = extractItem(slotExtract, extract, extractSide, Integer.MAX_VALUE, true);
|
if(extract.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide) && insert.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide)){
|
||||||
if(theoreticalExtract != null){
|
IItemHandler extractCap = extract.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide);
|
||||||
ItemStack remaining = insertItem(slotInsert, insert, insertSide, theoreticalExtract, false);
|
IItemHandler insertCap = insert.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide);
|
||||||
if(!ItemStack.areItemStacksEqual(remaining, theoreticalExtract)){
|
|
||||||
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 tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer){
|
public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer){
|
||||||
if(maxTransfer > 0){
|
if(maxTransfer > 0){
|
||||||
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||||
|
|
Loading…
Reference in a new issue