mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #2389 from R-Kaenbyou/new-branch-1
ME Storage bus compat for Arc Furnace
This commit is contained in:
commit
63d5d41d48
@ -14,5 +14,6 @@ public class AE2CompatHandler {
|
||||
@Optional.Method(modid = "appliedenergistics2")
|
||||
private static void registerHandler() {
|
||||
AEApi.instance().registries().externalStorage().addExternalStorageInterface(new MSUExternalStorageHandler());
|
||||
AEApi.instance().registries().externalStorage().addExternalStorageInterface(new AFLExternalStorageHandler());
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package com.hbm.handler.ae2;
|
||||
|
||||
import com.hbm.tileentity.machine.TileEntityMachineArcFurnaceLarge;
|
||||
import com.hbm.tileentity.TileEntityProxyCombo;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.IExternalStorageHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.me.storage.MEMonitorIInventory;
|
||||
import appeng.util.inv.IMEAdaptor;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@Optional.InterfaceList({@Optional.Interface(iface = "appeng.api.storage.IExternalStorageHandler", modid = "appliedenergistics2")})
|
||||
public class AFLExternalStorageHandler implements IExternalStorageHandler {
|
||||
|
||||
public AFLExternalStorageHandler() {}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource mySrc) {
|
||||
boolean coreProxy = te instanceof TileEntityProxyCombo && ((TileEntityProxyCombo) te).getTile() instanceof TileEntityMachineArcFurnaceLarge;
|
||||
return channel == StorageChannel.ITEMS && (te instanceof TileEntityMachineArcFurnaceLarge || coreProxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src) {
|
||||
if (!canHandle(te, d, channel, src)) return null;
|
||||
if (te instanceof TileEntityProxyCombo) return new MEMonitorIInventory(new IMEAdaptor(new ArcFurnaceLargeMEInventory((TileEntityMachineArcFurnaceLarge) ((TileEntityProxyCombo)te).getTile()), src)) {};
|
||||
return new MEMonitorIInventory(new IMEAdaptor(new ArcFurnaceLargeMEInventory((TileEntityMachineArcFurnaceLarge) te), src)) {};
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.hbm.handler.ae2;
|
||||
|
||||
import com.hbm.tileentity.machine.TileEntityMachineArcFurnaceLarge;
|
||||
import com.hbm.tileentity.TileEntityProxyCombo;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@Optional.InterfaceList({@Optional.Interface(iface = "appeng.api.storage.IMEInventory", modid = "appliedenergistics2")})
|
||||
public class ArcFurnaceLargeMEInventory implements IMEInventory<IAEItemStack> {
|
||||
|
||||
private TileEntityMachineArcFurnaceLarge afl;
|
||||
|
||||
public ArcFurnaceLargeMEInventory(TileEntityMachineArcFurnaceLarge afl) {
|
||||
this.afl = afl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) {
|
||||
ItemStack is = input.getItemStack();
|
||||
is = afl.distributeInput(is, type == Actionable.MODULATE);
|
||||
|
||||
if(is == null) return null;
|
||||
return AEApi.instance().storage().createItemStack(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src) {
|
||||
ItemStack is = request.getItemStack();
|
||||
is = afl.collectRequested(is, mode == Actionable.MODULATE);
|
||||
|
||||
if(is == null) return null;
|
||||
return AEApi.instance().storage().createItemStack(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
ItemStack is;
|
||||
for(int i = 0; i < 25; i++) {
|
||||
is = afl.getAvailableItemFromSlot(i);
|
||||
if(is != null) out.add(AEApi.instance().storage().createItemStack(is));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel() {
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
}
|
||||
@ -65,11 +65,12 @@ public class ContainerMachineArcFurnaceLarge extends Container {
|
||||
} else if(rStack.getItem() instanceof ItemMachineUpgrade) {
|
||||
if(!InventoryUtil.mergeItemStack(this.inventorySlots, stack, 4, 5, false)) return null;
|
||||
} else {
|
||||
if(!InventoryUtil.mergeItemStack(this.inventorySlots, stack, 5, 25, false)) return null;
|
||||
stack = furnace.distributeInput(stack, true);
|
||||
if(stack != null && stack.stackSize == rStack.stackSize) return null;
|
||||
}
|
||||
}
|
||||
|
||||
if(stack.stackSize == 0) {
|
||||
if(stack == null || stack.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
|
||||
@ -29,6 +29,7 @@ import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.IUpgradeInfoProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.CrucibleUtil;
|
||||
import com.hbm.util.ItemStackUtil;
|
||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||
import com.hbm.util.i18n.I18nUtil;
|
||||
|
||||
@ -400,6 +401,111 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
liquids.add(matStack.copy());
|
||||
}
|
||||
|
||||
//Returns what is unused, or null if used up
|
||||
public ItemStack distributeInput(ItemStack is, boolean modulate) {
|
||||
if(is.stackSize == 0) return null;
|
||||
ItemStack split;
|
||||
|
||||
//Slots 0,1,2
|
||||
if(is.getItem() == ModItems.arc_electrode) {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(slots[i] == null) {
|
||||
split = is.splitStack(1);
|
||||
if(modulate) this.setInventorySlotContents(i, split);
|
||||
}
|
||||
if (is.stackSize == 0) return null;
|
||||
}
|
||||
//Don't tell me you're gonna add an arc furnace recipe smelting electrodes
|
||||
return is;
|
||||
}
|
||||
|
||||
//Slots 5-24
|
||||
ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(is, this.liquidMode);
|
||||
if(recipe != null) {
|
||||
int maxStackSize = this.liquidMode ? 64 : recipe.solidOutput.getMaxStackSize() / recipe.solidOutput.stackSize;
|
||||
maxStackSize = Math.min(maxStackSize, Math.min(is.getMaxStackSize(), getMaxInputSize()));
|
||||
|
||||
//Scan
|
||||
for(int i = 5; i < 25; i++){
|
||||
if(slots[i] == null) {
|
||||
if(is.stackSize > maxStackSize) {
|
||||
split = is.splitStack(maxStackSize);
|
||||
if(modulate) slots[i] = split;
|
||||
} else {
|
||||
if(modulate) slots[i] = is;
|
||||
return null;
|
||||
}
|
||||
} else if(ItemStackUtil.areStacksCompatible(is, slots[i]) && slots[i].stackSize < maxStackSize) {
|
||||
if(is.stackSize > maxStackSize - slots[i].stackSize) {
|
||||
is.splitStack(maxStackSize - slots[i].stackSize);
|
||||
if(modulate) slots[i].stackSize = maxStackSize;
|
||||
} else {
|
||||
if(modulate) slots[i].stackSize += is.stackSize;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
//Returns requested ItemStack
|
||||
public ItemStack collectRequested(ItemStack is, boolean modulate) {
|
||||
int req = is.stackSize;
|
||||
if(req == 0) return null;
|
||||
|
||||
//Slots 0,1,2
|
||||
if(is.getItem() != ModItems.arc_electrode) {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(slots[i] == null) continue;
|
||||
if(ItemStackUtil.areStacksCompatible(is, slots[i])) {
|
||||
if(req > slots[i].stackSize) {
|
||||
req -= slots[i].stackSize;
|
||||
if(modulate) slots[i] = null;
|
||||
} else if(req < slots[i].stackSize) {
|
||||
if(modulate) slots[i].stackSize -= req;
|
||||
return is;
|
||||
} else {
|
||||
if(modulate) slots[i] = null;
|
||||
return is;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Slots 5-24
|
||||
if(ArcFurnaceRecipes.getOutput(is, this.liquidMode) == null) {
|
||||
for(int i = 5; i < 25; i++) {
|
||||
if(slots[i] == null) continue;
|
||||
if(ItemStackUtil.areStacksCompatible(is, slots[i])) {
|
||||
if(req > slots[i].stackSize) {
|
||||
req -= slots[i].stackSize;
|
||||
if(modulate) slots[i] = null;
|
||||
} else if(req < slots[i].stackSize) {
|
||||
if(modulate) slots[i].stackSize -= req;
|
||||
return is;
|
||||
} else {
|
||||
if(modulate) slots[i] = null;
|
||||
return is;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is.stackSize -= req;
|
||||
if(is.stackSize == 0) return null;
|
||||
return is;
|
||||
}
|
||||
|
||||
//Return ItemStack in slot, null if unavailable
|
||||
public ItemStack getAvailableItemFromSlot(int slot) {
|
||||
if(slots[slot] == null) return null;
|
||||
if(slot < 3 && slots[slot].getItem() == ModItems.arc_electrode) return null;
|
||||
else if(slot > 4 && ArcFurnaceRecipes.getOutput(slots[slot], this.liquidMode) != null) return null;
|
||||
else if(slot == 3 || slot == 4) return null;
|
||||
else return slots[slot];
|
||||
}
|
||||
|
||||
public static int getStackAmount(List<MaterialStack> stack) {
|
||||
int amount = 0;
|
||||
for(MaterialStack mat : stack) amount += mat.amount;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user