mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-17 02:45:08 +00:00
refactor 6
This commit is contained in:
1 parent
5b62c4fdc8
commit
8d072f0c89
78 files changed
+525
-882
No files matched your search
@@ -5,13 +5,11 @@ import appeng.api.config.InsertionMode;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.p2p.PartP2PLiquids;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import cofh.api.transport.IItemDuct;
|
||||
import com.glodblock.github.common.Config;
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.common.parts.PartFluidExportBus;
|
||||
import com.glodblock.github.common.parts.PartFluidInterface;
|
||||
@@ -27,7 +25,6 @@ import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
@@ -38,13 +35,13 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
public FluidConvertingInventoryAdaptor(
|
||||
@Nullable InventoryAdaptor invItems,
|
||||
@Nullable IFluidHandler invFluids,
|
||||
EnumFacing facing,
|
||||
ForgeDirection facing,
|
||||
BlockPos pos,
|
||||
boolean isOnmi,
|
||||
Object eioConduct) {
|
||||
this.invItems = invItems;
|
||||
this.invFluids = invFluids;
|
||||
this.side = Util.from(facing);
|
||||
this.side = facing;
|
||||
this.posInterface = pos;
|
||||
this.eioDuct = eioConduct;
|
||||
this.onmi = isOnmi;
|
||||
@@ -57,21 +54,20 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
private final Object eioDuct;
|
||||
private final boolean onmi;
|
||||
|
||||
public static InventoryAdaptor wrap(TileEntity capProvider, EnumFacing face) {
|
||||
public static InventoryAdaptor wrap(TileEntity capProvider, ForgeDirection face) {
|
||||
// sometimes i wish 1.7.10 has cap system.
|
||||
ForgeDirection f = Util.from(face);
|
||||
TileEntity inter = capProvider
|
||||
.getWorldObj()
|
||||
.getTileEntity(
|
||||
capProvider.xCoord + f.offsetX, capProvider.yCoord + f.offsetY, capProvider.zCoord + f.offsetZ);
|
||||
capProvider.xCoord + face.offsetX,
|
||||
capProvider.yCoord + face.offsetY,
|
||||
capProvider.zCoord + face.offsetZ);
|
||||
if (!Config.noFluidPacket
|
||||
&& !(inter instanceof TileFluidInterface
|
||||
|| (inter instanceof TileCableBus
|
||||
&& (((TileCableBus) inter).getPart(f.getOpposite()) instanceof PartFluidInterface
|
||||
|| ((TileCableBus) inter).getPart(f.getOpposite())
|
||||
instanceof PartFluidExportBus))))
|
||||
return InventoryAdaptor.getAdaptor(capProvider, f);
|
||||
InventoryAdaptor item = InventoryAdaptor.getAdaptor(capProvider, f);
|
||||
|| Util.getPart(inter, face.getOpposite()) instanceof PartFluidInterface
|
||||
|| Util.getPart(inter, face.getOpposite()) instanceof PartFluidExportBus))
|
||||
return InventoryAdaptor.getAdaptor(capProvider, face);
|
||||
InventoryAdaptor item = InventoryAdaptor.getAdaptor(capProvider, face);
|
||||
IFluidHandler fluid = capProvider instanceof IFluidHandler ? (IFluidHandler) capProvider : null;
|
||||
boolean onmi = false;
|
||||
if (inter instanceof TileInterface) {
|
||||
@@ -85,16 +81,10 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
}
|
||||
|
||||
public ItemStack addItems(ItemStack toBeAdded, InsertionMode insertionMode) {
|
||||
if (toBeAdded.getItem() instanceof ItemFluidPacket || toBeAdded.getItem() instanceof ItemFluidDrop) {
|
||||
FluidStack fluid = Util.getFluidFromVirtual(toBeAdded);
|
||||
if (fluid != null) {
|
||||
if (invFluids != null) {
|
||||
FluidStack fluid;
|
||||
if (toBeAdded.getItem() instanceof ItemFluidPacket) {
|
||||
fluid = ItemFluidPacket.getFluidStack(toBeAdded);
|
||||
} else {
|
||||
fluid = ItemFluidDrop.getFluidStack(toBeAdded);
|
||||
}
|
||||
|
||||
if (fluid != null && invFluids.canFill(side, fluid.getFluid())) {
|
||||
if (invFluids.canFill(side, fluid.getFluid())) {
|
||||
int filled = invFluids.fill(side, fluid, true);
|
||||
if (filled > 0) {
|
||||
fluid.amount -= filled;
|
||||
@@ -122,46 +112,27 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated, InsertionMode insertionMode) {
|
||||
if (toBeSimulated.getItem() instanceof ItemFluidPacket || toBeSimulated.getItem() instanceof ItemFluidDrop) {
|
||||
FluidStack fluid = Util.getFluidFromVirtual(toBeSimulated);
|
||||
if (fluid != null) {
|
||||
if (onmi) {
|
||||
boolean sus = false;
|
||||
FluidStack fluid;
|
||||
if (toBeSimulated.getItem() instanceof ItemFluidPacket) {
|
||||
fluid = ItemFluidPacket.getFluidStack(toBeSimulated);
|
||||
} else {
|
||||
fluid = ItemFluidDrop.getFluidStack(toBeSimulated);
|
||||
}
|
||||
|
||||
if (fluid != null) {
|
||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
||||
TileEntity te = posInterface.getOffSet(dir).getTileEntity();
|
||||
if (te instanceof IFluidHandler) {
|
||||
int filled = ((IFluidHandler) te).fill(dir.getOpposite(), fluid, false);
|
||||
if (filled > 0) {
|
||||
sus = true;
|
||||
break;
|
||||
}
|
||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
||||
TileEntity te = posInterface.getOffSet(dir).getTileEntity();
|
||||
if (te instanceof IFluidHandler) {
|
||||
int filled = ((IFluidHandler) te).fill(dir.getOpposite(), fluid, false);
|
||||
if (filled > 0) {
|
||||
sus = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sus = true;
|
||||
}
|
||||
return sus ? null : toBeSimulated;
|
||||
}
|
||||
if (invFluids != null) {
|
||||
FluidStack fluid;
|
||||
if (toBeSimulated.getItem() instanceof ItemFluidPacket) {
|
||||
fluid = ItemFluidPacket.getFluidStack(toBeSimulated);
|
||||
} else {
|
||||
fluid = ItemFluidDrop.getFluidStack(toBeSimulated);
|
||||
}
|
||||
|
||||
if (fluid != null) {
|
||||
int filled = invFluids.fill(side, fluid, false);
|
||||
if (filled > 0) {
|
||||
fluid.amount -= filled;
|
||||
return ItemFluidPacket.newStack(fluid);
|
||||
}
|
||||
int filled = invFluids.fill(side, fluid, false);
|
||||
if (filled > 0) {
|
||||
fluid.amount -= filled;
|
||||
return ItemFluidPacket.newStack(fluid);
|
||||
}
|
||||
}
|
||||
return toBeSimulated;
|
||||
@@ -203,10 +174,9 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
}
|
||||
if (invFluids != null && invFluids.getTankInfo(this.side) != null) {
|
||||
List<FluidTankInfo[]> tankInfos = new LinkedList<>();
|
||||
if (invFluids instanceof TileCableBus
|
||||
&& ((TileCableBus) invFluids).getPart(this.side) instanceof PartP2PLiquids) {
|
||||
if (Util.getPart(invFluids, this.side) instanceof PartP2PLiquids) {
|
||||
// read other ends of p2p for blocking mode
|
||||
PartP2PLiquids invFluidsP2P = (PartP2PLiquids) ((TileCableBus) invFluids).getPart(this.side);
|
||||
PartP2PLiquids invFluidsP2P = (PartP2PLiquids) Util.getPart(invFluids, this.side);
|
||||
try {
|
||||
Iterator<PartP2PLiquids> it = invFluidsP2P.getOutputs().iterator();
|
||||
boolean checkedInput = false;
|
||||
@@ -223,8 +193,7 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
if (target == null) continue;
|
||||
tankInfos.add(target.getTankInfo(p2p.getSide().getOpposite()));
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
// ignore
|
||||
} catch (GridAccessException ignore) {
|
||||
}
|
||||
} else {
|
||||
tankInfos.add(invFluids.getTankInfo(this.side));
|
||||
|
||||
@@ -9,8 +9,8 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class InventoryHandler implements IGuiHandler {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class InventoryHandler implements IGuiHandler {
|
||||
FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(guiType));
|
||||
}
|
||||
|
||||
public static void openGui(EntityPlayer player, World world, BlockPos pos, EnumFacing face, GuiType guiType) {
|
||||
public static void openGui(EntityPlayer player, World world, BlockPos pos, ForgeDirection face, GuiType guiType) {
|
||||
player.openGui(
|
||||
FluidCraft.INSTANCE,
|
||||
(guiType.ordinal() << 3) | face.ordinal(),
|
||||
@@ -32,10 +32,10 @@ public class InventoryHandler implements IGuiHandler {
|
||||
@Override
|
||||
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
|
||||
int faceOrd = id & 0x7;
|
||||
if (faceOrd > EnumFacing.values().length) {
|
||||
if (faceOrd > ForgeDirection.values().length) {
|
||||
return null;
|
||||
}
|
||||
EnumFacing face = EnumFacing.getFront(faceOrd);
|
||||
ForgeDirection face = ForgeDirection.getOrientation(faceOrd);
|
||||
GuiType type = GuiType.getByOrdinal(id >>> 3);
|
||||
return type != null ? type.guiFactory.createServerGui(player, world, x, y, z, face) : null;
|
||||
}
|
||||
@@ -45,10 +45,10 @@ public class InventoryHandler implements IGuiHandler {
|
||||
@Override
|
||||
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
|
||||
int faceOrd = id & 0x7;
|
||||
if (faceOrd > EnumFacing.values().length) {
|
||||
if (faceOrd > ForgeDirection.values().length) {
|
||||
return null;
|
||||
}
|
||||
EnumFacing face = EnumFacing.getFront(faceOrd);
|
||||
ForgeDirection face = ForgeDirection.getOrientation(faceOrd);
|
||||
GuiType type = GuiType.getByOrdinal(id >>> 3);
|
||||
return type != null ? type.guiFactory.createClientGui(player, world, x, y, z, face) : null;
|
||||
}
|
||||
|
||||
+4
-7
@@ -5,7 +5,7 @@ import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.IExternalStorageHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
import com.glodblock.github.util.Util;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@@ -16,9 +16,7 @@ public class AEFluidInterfaceHandler implements IExternalStorageHandler {
|
||||
if (channel == StorageChannel.FLUIDS) {
|
||||
if (te instanceof ITileStorageMonitorable) {
|
||||
return true;
|
||||
} else
|
||||
return te instanceof TileCableBus
|
||||
&& ((TileCableBus) te).getPart(d.getOpposite()) instanceof ITileStorageMonitorable;
|
||||
} else return Util.getPart(te, d.getOpposite()) instanceof ITileStorageMonitorable;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -29,9 +27,8 @@ public class AEFluidInterfaceHandler implements IExternalStorageHandler {
|
||||
if (channel == StorageChannel.FLUIDS) {
|
||||
if (te instanceof ITileStorageMonitorable) {
|
||||
return ((ITileStorageMonitorable) te).getMonitorable(d, src).getFluidInventory();
|
||||
} else if (te instanceof TileCableBus
|
||||
&& ((TileCableBus) te).getPart(d.getOpposite()) instanceof ITileStorageMonitorable) {
|
||||
ITileStorageMonitorable part = (ITileStorageMonitorable) ((TileCableBus) te).getPart(d.getOpposite());
|
||||
} else if (Util.getPart(te, d.getOpposite()) instanceof ITileStorageMonitorable) {
|
||||
ITileStorageMonitorable part = (ITileStorageMonitorable) Util.getPart(te, d.getOpposite());
|
||||
return part.getMonitorable(d, src).getFluidInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IGuiFactory {
|
||||
|
||||
@Nullable
|
||||
Object createServerGui(EntityPlayer player, World world, int x, int y, int z, EnumFacing face);
|
||||
Object createServerGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Nullable
|
||||
Object createClientGui(EntityPlayer player, World world, int x, int y, int z, EnumFacing face);
|
||||
Object createClientGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face);
|
||||
}
|
||||
@@ -2,10 +2,9 @@ package com.glodblock.github.inventory.gui;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import com.glodblock.github.util.Util;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public abstract class PartGuiFactory<T> extends TileGuiFactory<T> {
|
||||
|
||||
@@ -15,9 +14,9 @@ public abstract class PartGuiFactory<T> extends TileGuiFactory<T> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected T getInventory(TileEntity tile, EnumFacing face) {
|
||||
protected T getInventory(TileEntity tile, ForgeDirection face) {
|
||||
if (tile instanceof IPartHost) {
|
||||
IPart part = ((IPartHost) tile).getPart(Util.from(face));
|
||||
IPart part = ((IPartHost) tile).getPart(face);
|
||||
if (invClass.isInstance(part)) {
|
||||
return invClass.cast(part);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ package com.glodblock.github.inventory.gui;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import com.glodblock.github.util.Util;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public abstract class TileGuiFactory<T> implements IGuiFactory {
|
||||
|
||||
@@ -18,13 +17,13 @@ public abstract class TileGuiFactory<T> implements IGuiFactory {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected T getInventory(TileEntity tile, EnumFacing face) {
|
||||
protected T getInventory(TileEntity tile, ForgeDirection face) {
|
||||
return invClass.isInstance(tile) ? invClass.cast(tile) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object createServerGui(EntityPlayer player, World world, int x, int y, int z, EnumFacing face) {
|
||||
public Object createServerGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile == null) {
|
||||
return null;
|
||||
@@ -40,7 +39,7 @@ public abstract class TileGuiFactory<T> implements IGuiFactory {
|
||||
ctx.setX(x);
|
||||
ctx.setY(y);
|
||||
ctx.setZ(z);
|
||||
ctx.setSide(Util.from(face));
|
||||
ctx.setSide(face);
|
||||
((AEBaseContainer) gui).setOpenContext(ctx);
|
||||
}
|
||||
return gui;
|
||||
@@ -51,7 +50,7 @@ public abstract class TileGuiFactory<T> implements IGuiFactory {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object createClientGui(EntityPlayer player, World world, int x, int y, int z, EnumFacing face) {
|
||||
public Object createClientGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile == null) {
|
||||
return null;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.glodblock.github.inventory.slot;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface SlotFluid {
|
||||
public interface ISlotFluid {
|
||||
|
||||
@Nullable
|
||||
IAEItemStack getAeStack();
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.glodblock.github.inventory.slot;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.AeItemStackHandler;
|
||||
import com.glodblock.github.inventory.AeStackInventory;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
public class SlotFluidConvertingFake extends SlotFake implements ISlotFluid {
|
||||
|
||||
private final AeStackInventory<IAEItemStack> inv;
|
||||
|
||||
public SlotFluidConvertingFake(AeItemStackHandler inv, int idx, int x, int y) {
|
||||
super(inv, idx, x, y);
|
||||
this.inv = inv.getAeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack) {
|
||||
inv.setStack(getSlotIndex(), AEItemStack.create(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAeStack(@Nullable IAEItemStack stack, boolean sync) {
|
||||
inv.setStack(getSlotIndex(), stack);
|
||||
}
|
||||
|
||||
public void putConvertedStack(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
setAeStack(null, false);
|
||||
return;
|
||||
} else if (stack.getItem() instanceof IFluidContainerItem) {
|
||||
FluidStack fluid = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
|
||||
if (fluid != null) {
|
||||
fluid.amount *= stack.stackSize;
|
||||
IAEItemStack aeStack = ItemFluidPacket.newAeStack(fluid);
|
||||
if (aeStack != null) {
|
||||
setAeStack(aeStack, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (FluidContainerRegistry.isContainer(stack)) {
|
||||
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
if (fluid != null) {
|
||||
fluid.amount *= stack.stackSize;
|
||||
IAEItemStack aeStack = ItemFluidPacket.newAeStack(fluid);
|
||||
if (aeStack != null) {
|
||||
setAeStack(aeStack, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
putStack(stack);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IAEItemStack getAeStack() {
|
||||
return inv.getStack(getSlotIndex());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user