mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 01:54:59 +00:00
begin work
This commit is contained in:
commit
db2ad29b52
124 files changed
+11799
No files matched your search
@@ -0,0 +1,237 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.networking.crafting.ICraftingCPU;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.implementations.GuiCraftingStatus;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
import appeng.client.render.AppEngRenderItem;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.container.implementations.CraftingCPURecord;
|
||||
import appeng.helpers.MultiCraftingTracker;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import com.glodblock.github.client.gui.GuiBaseFluidPatternTerminal;
|
||||
import com.glodblock.github.client.gui.GuiFCBaseMonitor;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Ae2Reflect {
|
||||
|
||||
private static final Field fInventory_container;
|
||||
private static final Field fInventory_width;
|
||||
private static final Field fInventory_stackList;
|
||||
private static final Field fAEContainer_upgradeable;
|
||||
private static final Method mItemSlot_setExtractable;
|
||||
private static final Method mTracker_isBusy;
|
||||
private static final Method mTracker_cancel;
|
||||
|
||||
static {
|
||||
try {
|
||||
fInventory_container = reflectField(InventoryCrafting.class, "eventHandler");
|
||||
fInventory_width = reflectField(InventoryCrafting.class, "inventoryWidth");
|
||||
fInventory_stackList = reflectField(InventoryCrafting.class, "stackList");
|
||||
fAEContainer_upgradeable = reflectField(ContainerUpgradeable.class, "upgradeable");
|
||||
mItemSlot_setExtractable = reflectMethod(ItemSlot.class, "setExtractable", boolean.class);
|
||||
mTracker_isBusy = reflectMethod(MultiCraftingTracker.class, "isBusy", int.class);
|
||||
mTracker_cancel = reflectMethod(MultiCraftingTracker.class, "cancel");
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to initialize AE2 reflection hacks!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Method reflectMethod(Class<?> owner, String name, Class<?>... paramTypes) throws NoSuchMethodException {
|
||||
Method m = owner.getDeclaredMethod(name, paramTypes);
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
}
|
||||
|
||||
public static Field reflectField(Class<?> owner, String name) throws NoSuchFieldException {
|
||||
Field f = owner.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T readField(Object owner, Field field) {
|
||||
try {
|
||||
return (T)field.get(owner);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to read field: " + field);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeField(Object owner, Field field, Object value) {
|
||||
try {
|
||||
field.set(owner, value);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to write field: " + field);
|
||||
}
|
||||
}
|
||||
|
||||
public static void doCancel(MultiCraftingTracker mct) {
|
||||
try {
|
||||
mTracker_cancel.invoke(mct);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mTracker_cancel, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getBusy(MultiCraftingTracker mct, int slot) {
|
||||
try {
|
||||
return (boolean) mTracker_isBusy.invoke(mct, slot);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mTracker_isBusy, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static IUpgradeableHost getUpgrade(ContainerUpgradeable container) {
|
||||
return Ae2Reflect.readField(container, fAEContainer_upgradeable);
|
||||
}
|
||||
|
||||
public static Container getCraftContainer(InventoryCrafting inv) {
|
||||
return Ae2Reflect.readField(inv, fInventory_container);
|
||||
}
|
||||
|
||||
public static int getCraftWidth(InventoryCrafting inv) {
|
||||
return Ae2Reflect.readField(inv, fInventory_width);
|
||||
}
|
||||
|
||||
public static ItemStack[] getCraftStackList(InventoryCrafting inv) {
|
||||
return Ae2Reflect.readField(inv, fInventory_stackList);
|
||||
}
|
||||
|
||||
public static void setItemSlotExtractable(ItemSlot slot, boolean extractable) {
|
||||
try {
|
||||
mItemSlot_setExtractable.invoke(slot, extractable);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mItemSlot_setExtractable, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Field fAEBaseGui_stackSizeRenderer;
|
||||
private static final Field fGuiCraftingStatus_originalGuiBtn;
|
||||
private static final Field fGuiPatternTerm_container;
|
||||
private static final Field fGuiCPUStatus_icon;
|
||||
private static final Field fGuiMEMonitorable_monitorableContainer;
|
||||
private static final Field fGuiMEMonitorable_configSrc;
|
||||
private static final Field fGuiMEMonitorable_craftingStatusBtn;
|
||||
private static final Field fGuiContainer_guiLeft;
|
||||
private static final Field fGuiContainer_guiTop;
|
||||
private static final Field fCPU_cpu;
|
||||
private static final Field fCPU_myName;
|
||||
private static final Field fCPU_processors;
|
||||
private static final Field fCPU_size;
|
||||
private static final Field fGui_drag;
|
||||
private static final Method mGuiPatternTerm_inventorySlots;
|
||||
private static final Method mGuiPatternTerm_reservedSpace;
|
||||
private static final Method mGuiPatternTerm_reservedSpaceSetter;
|
||||
|
||||
static {
|
||||
try {
|
||||
fAEBaseGui_stackSizeRenderer = Ae2Reflect.reflectField(AEBaseGui.class, "aeRenderItem");
|
||||
fGuiCraftingStatus_originalGuiBtn = Ae2Reflect.reflectField(GuiCraftingStatus.class, "originalGuiBtn");
|
||||
fGuiPatternTerm_container = Ae2Reflect.reflectField(GuiBaseFluidPatternTerminal.class, "container");
|
||||
fGuiMEMonitorable_monitorableContainer = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "monitorableContainer");
|
||||
fGuiMEMonitorable_configSrc = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "configSrc");
|
||||
fGuiMEMonitorable_craftingStatusBtn = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "craftingStatusBtn");
|
||||
fGuiCPUStatus_icon = Ae2Reflect.reflectField(GuiCraftingStatus.class, "myIcon");
|
||||
fGuiContainer_guiLeft = Ae2Reflect.reflectField(GuiContainer.class, "guiLeft");
|
||||
fGuiContainer_guiTop = Ae2Reflect.reflectField(GuiContainer.class, "guiTop");
|
||||
fCPU_cpu = Ae2Reflect.reflectField(CraftingCPURecord.class, "cpu");
|
||||
fCPU_myName = Ae2Reflect.reflectField(CraftingCPURecord.class, "myName");
|
||||
fCPU_processors = Ae2Reflect.reflectField(CraftingCPURecord.class, "processors");
|
||||
fCPU_size = Ae2Reflect.reflectField(CraftingCPURecord.class, "size");
|
||||
fGui_drag = Ae2Reflect.reflectField(AEBaseGui.class, "drag_click");
|
||||
mGuiPatternTerm_inventorySlots = Ae2Reflect.reflectMethod(AEBaseGui.class, "getInventorySlots");
|
||||
mGuiPatternTerm_reservedSpace = Ae2Reflect.reflectMethod(GuiFCBaseMonitor.class, "getReservedSpace");
|
||||
mGuiPatternTerm_reservedSpaceSetter = Ae2Reflect.reflectMethod(GuiFCBaseMonitor.class, "setReservedSpace", int.class);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to initialize AE2 reflection hacks!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Slot> getInventorySlots(AEBaseGui gui) {
|
||||
try {
|
||||
return (List<Slot>) mGuiPatternTerm_inventorySlots.invoke(gui);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mGuiPatternTerm_inventorySlots, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void rewriteIcon(GuiCraftingStatus gui, ItemStack icon) {
|
||||
Ae2Reflect.writeField(gui, fGuiCPUStatus_icon, icon);
|
||||
}
|
||||
|
||||
public static Set<Slot> getDragClick(AEBaseGui gui) {
|
||||
return Ae2Reflect.readField(gui, fGui_drag);
|
||||
}
|
||||
|
||||
public static ICraftingCPU getCPU(CraftingCPURecord cpu) {
|
||||
return Ae2Reflect.readField(cpu, fCPU_cpu);
|
||||
}
|
||||
|
||||
public static String getName(CraftingCPURecord cpu) {
|
||||
return Ae2Reflect.readField(cpu, fCPU_myName);
|
||||
}
|
||||
|
||||
public static int getProcessors(CraftingCPURecord cpu) {
|
||||
return Ae2Reflect.readField(cpu, fCPU_processors);
|
||||
}
|
||||
|
||||
public static long getSize(CraftingCPURecord cpu) {
|
||||
return Ae2Reflect.readField(cpu, fCPU_size);
|
||||
}
|
||||
|
||||
public static int getGuiLeft(GuiContainer gui) {
|
||||
return Ae2Reflect.readField(gui, fGuiContainer_guiLeft);
|
||||
}
|
||||
|
||||
public static int getGuiTop(GuiContainer gui) {
|
||||
return Ae2Reflect.readField(gui, fGuiContainer_guiTop);
|
||||
}
|
||||
|
||||
public static void setReservedSpace(GuiFCBaseMonitor gui, int size) {
|
||||
try {
|
||||
mGuiPatternTerm_reservedSpaceSetter.invoke(gui, size);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mGuiPatternTerm_reservedSpaceSetter, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getReservedSpace(GuiFCBaseMonitor gui) {
|
||||
try {
|
||||
return (int) mGuiPatternTerm_reservedSpace.invoke(gui);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mGuiPatternTerm_reservedSpace, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static AppEngRenderItem getStackSizeRenderer(AEBaseGui gui) {
|
||||
return Ae2Reflect.readField(gui, fAEBaseGui_stackSizeRenderer);
|
||||
}
|
||||
|
||||
public static GuiTabButton getOriginalGuiButton(GuiCraftingStatus gui) {
|
||||
return Ae2Reflect.readField(gui, fGuiCraftingStatus_originalGuiBtn);
|
||||
}
|
||||
|
||||
public static void setGuiContainer(GuiBaseFluidPatternTerminal instance, ContainerFluidPatternTerminal container) {
|
||||
Ae2Reflect.writeField(instance, fGuiPatternTerm_container, container);
|
||||
Ae2Reflect.writeField(instance, fGuiMEMonitorable_monitorableContainer, container);
|
||||
Ae2Reflect.writeField(instance, fGuiMEMonitorable_configSrc, container.getConfigManager());
|
||||
}
|
||||
|
||||
public static GuiTabButton getCraftingStatusButton(GuiFCBaseMonitor gui) {
|
||||
return Ae2Reflect.readField(gui, fGuiMEMonitorable_craftingStatusBtn);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BlockPos {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public BlockPos(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public BlockPos(@Nonnull TileEntity te) {
|
||||
this.x = te.xCoord;
|
||||
this.y = te.yCoord;
|
||||
this.z = te.zCoord;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof BlockPos) {
|
||||
BlockPos pos = (BlockPos) obj;
|
||||
return pos.x == x && pos.y == y && pos.z == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<FluidPatternDetails>{
|
||||
|
||||
private final ItemStack patternStack;
|
||||
private IAEItemStack patternStackAe;
|
||||
private IAEItemStack[] inputs = null, inputsCond = null, outputs = null, outputsCond = null;
|
||||
private int priority = 0;
|
||||
|
||||
public FluidPatternDetails(ItemStack stack) {
|
||||
this.patternStack = stack;
|
||||
this.patternStackAe = Objects.requireNonNull(AEItemStack.create(stack)); // s2g
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPattern() {
|
||||
return patternStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSubstitute() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getInputs() {
|
||||
return checkInitialized(inputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getCondensedInputs() {
|
||||
return checkInitialized(inputsCond);
|
||||
}
|
||||
|
||||
public boolean setInputs(IAEItemStack[] inputs) {
|
||||
for (IAEItemStack stack : inputs) { // see note at top of class
|
||||
if (stack == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
IAEItemStack[] condensed = condenseStacks(inputs);
|
||||
if (condensed.length == 0) {
|
||||
return false;
|
||||
}
|
||||
this.inputs = inputs;
|
||||
this.inputsCond = condensed;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getOutputs() {
|
||||
return checkInitialized(outputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getCondensedOutputs() {
|
||||
return checkInitialized(outputsCond);
|
||||
}
|
||||
|
||||
public boolean setOutputs(IAEItemStack[] outputs) {
|
||||
for (IAEItemStack stack : outputs) { // see note at top of class
|
||||
if (stack == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
IAEItemStack[] condensed = condenseStacks(outputs);
|
||||
if (condensed.length == 0) {
|
||||
return false;
|
||||
}
|
||||
this.outputs = outputs;
|
||||
this.outputsCond = condensed;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IAEItemStack[] condenseStacks(IAEItemStack[] stacks) {
|
||||
// AE item stacks are equivalent iff they are of the same item type (not accounting for stack size)
|
||||
// thus, it's not the semantically-correct definition of "equal" but it's useful for matching item types
|
||||
Map<IAEItemStack, IAEItemStack> accMap = new HashMap<>();
|
||||
for (IAEItemStack stack : stacks) {
|
||||
if (stack != null) {
|
||||
IAEItemStack acc = accMap.get(stack);
|
||||
if (acc == null) {
|
||||
accMap.put(stack, stack.copy());
|
||||
} else {
|
||||
acc.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
return accMap.values().toArray(new IAEItemStack[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput(InventoryCrafting craftingInv, World world) {
|
||||
throw new IllegalStateException("Not a crafting recipe!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidItemForSlot(int slotIndex, ItemStack itemStack, World world) {
|
||||
throw new IllegalStateException("Not a crafting recipe!");
|
||||
}
|
||||
|
||||
private static <T> T checkInitialized(@Nullable T value) {
|
||||
if (value == null) {
|
||||
throw new IllegalStateException("Pattern is not initialized!");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return patternStackAe.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
// ae2 null-checks the pattern stack here for some reason, but doesn't null-check in hashCode()
|
||||
// this is inconsistent, so i've just decided to assert non-null in the constructor, which is to say that
|
||||
// the pattern stack can never be null here
|
||||
return obj instanceof FluidPatternDetails && patternStackAe.equals(((FluidPatternDetails)obj).patternStackAe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(FluidPatternDetails o) {
|
||||
return Integer.compare(o.priority, this.priority);
|
||||
}
|
||||
|
||||
public ItemStack writeToStack() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setTag("Inputs", writeStackArray(checkInitialized(inputs)));
|
||||
tag.setTag("Outputs", writeStackArray(checkInitialized(outputs)));
|
||||
patternStack.setTagCompound(tag);
|
||||
patternStackAe = Objects.requireNonNull(AEItemStack.create(patternStack));
|
||||
return patternStack;
|
||||
}
|
||||
|
||||
public static NBTTagList writeStackArray(IAEItemStack[] stacks) {
|
||||
NBTTagList listTag = new NBTTagList();
|
||||
for (IAEItemStack stack : stacks) {
|
||||
if (stack != null) {
|
||||
// see note at top of class
|
||||
NBTTagCompound stackTag = new NBTTagCompound();
|
||||
stack.writeToNBT(stackTag);
|
||||
listTag.appendTag(stackTag);
|
||||
}
|
||||
}
|
||||
return listTag;
|
||||
}
|
||||
|
||||
public boolean readFromStack() {
|
||||
if (!patternStack.hasTagCompound()) {
|
||||
return false;
|
||||
}
|
||||
NBTTagCompound tag = Objects.requireNonNull(patternStack.getTagCompound());
|
||||
// may be possible to enter a partially-correct state if setInputs succeeds but setOutputs failed
|
||||
// but outside code should treat it as completely incorrect and not attempt to make calls
|
||||
return setInputs(readStackArray(tag.getTagList("Inputs", Constants.NBT.TAG_COMPOUND), 9))
|
||||
&& setOutputs(readStackArray(tag.getTagList("Outputs", Constants.NBT.TAG_COMPOUND), 3));
|
||||
}
|
||||
|
||||
public static IAEItemStack[] readStackArray(NBTTagList listTag, int maxCount) {
|
||||
// see note at top of class
|
||||
IAEItemStack[] stacks = new IAEItemStack[Math.min(listTag.tagCount(), maxCount)];
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
stacks[i] = AEItemStack.loadItemStackFromNBT(listTag.getCompoundTagAt(i));
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.inventory.AEFluidInventory;
|
||||
import com.glodblock.github.inventory.IAEFluidTank;
|
||||
import com.glodblock.github.network.SPacketFluidSlot;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FluidSyncHelper {
|
||||
private final IAEFluidTank inv;
|
||||
private final IAEFluidTank cache;
|
||||
private final int idOffset;
|
||||
|
||||
public FluidSyncHelper(final IAEFluidTank inv, final int idOffset )
|
||||
{
|
||||
this.inv = inv;
|
||||
this.cache = new AEFluidInventory( null, inv.getSlots() );
|
||||
this.idOffset = idOffset;
|
||||
}
|
||||
|
||||
public void sendFull( final Iterable<ICrafting> listeners )
|
||||
{
|
||||
this.sendDiffMap( this.createDiffMap( true ), listeners );
|
||||
}
|
||||
|
||||
public void sendDiff( final Iterable<ICrafting> listeners )
|
||||
{
|
||||
this.sendDiffMap( this.createDiffMap( false ), listeners );
|
||||
}
|
||||
|
||||
public void readPacket( final Map<Integer, IAEFluidStack> data )
|
||||
{
|
||||
for( int i = 0; i < this.inv.getSlots(); ++i )
|
||||
{
|
||||
if( data.containsKey( i + this.idOffset ) )
|
||||
{
|
||||
this.inv.setFluidInSlot( i, data.get( i + this.idOffset ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendDiffMap( final Map<Integer, IAEFluidStack> data, final Iterable<ICrafting> listeners )
|
||||
{
|
||||
if( data.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for( final ICrafting l : listeners )
|
||||
{
|
||||
if( l instanceof EntityPlayerMP)
|
||||
{
|
||||
FluidCraft.proxy.netHandler.sendTo( new SPacketFluidSlot( data ), (EntityPlayerMP) l );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, IAEFluidStack> createDiffMap(final boolean full )
|
||||
{
|
||||
final Map<Integer, IAEFluidStack> ret = new HashMap<>();
|
||||
for( int i = 0; i < this.inv.getSlots(); ++i )
|
||||
{
|
||||
if( full || !this.equalsSlot( i ) )
|
||||
{
|
||||
ret.put( i + this.idOffset, this.inv.getFluidInSlot( i ) );
|
||||
}
|
||||
if( !full )
|
||||
{
|
||||
this.cache.setFluidInSlot( i, this.inv.getFluidInSlot( i ) );
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private boolean equalsSlot(int slot )
|
||||
{
|
||||
final IAEFluidStack stackA = this.inv.getFluidInSlot( slot );
|
||||
final IAEFluidStack stackB = this.cache.getFluidInSlot( slot );
|
||||
|
||||
if( !Objects.equals( stackA, stackB ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stackA == null || stackA.getStackSize() == stackB.getStackSize();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import appeng.api.config.ActionItems;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
public final class ModAndClassUtil {
|
||||
|
||||
public static boolean GT5 = false;
|
||||
public static boolean GT6 = false;
|
||||
|
||||
public static boolean isDoubleButton;
|
||||
|
||||
public static void init() {
|
||||
try {
|
||||
ActionItems x = ActionItems.DOUBLE;
|
||||
isDoubleButton = true;
|
||||
} catch (Exception e) {
|
||||
isDoubleButton = false;
|
||||
}
|
||||
|
||||
if (Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi"))
|
||||
GT5 = true;
|
||||
if (Loader.isModLoaded("gregapi") && Loader.isModLoaded("gregapi_post"))
|
||||
GT6 = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
|
||||
public class NameConst {
|
||||
|
||||
public static final String BLOCK_FLUID_DISCRETIZER = "fluid_discretizer";
|
||||
public static final String BLOCK_FLUID_PATTERN_ENCODER = "fluid_pattern_encoder";
|
||||
public static final String BLOCK_FLUID_PACKET_DECODER = "fluid_packet_decoder";
|
||||
public static final String BLOCK_FLUID_INTERFACE = "fluid_interface";
|
||||
|
||||
public static final String ITEM_FLUID_DROP = "fluid_drop";
|
||||
public static final String ITEM_FLUID_ENCODED_PATTERN = "fluid_encoded_pattern";
|
||||
public static final String ITEM_PART_FLUID_PATTERN_TERMINAL = "part_fluid_pattern_terminal";
|
||||
public static final String ITEM_FLUID_PACKET = "fluid_packet";
|
||||
|
||||
public static final String TT_KEY = FluidCraft.MODID + ".tooltip.";
|
||||
public static final String TT_INVALID_FLUID = TT_KEY + "invalid_fluid";
|
||||
public static final String TT_FLUID_PACKET = TT_KEY + "fluid_packet";
|
||||
public static final String TT_ENCODE_PATTERN = TT_KEY + "encode_pattern";
|
||||
|
||||
public static final String RES_KEY = FluidCraft.MODID + ":";
|
||||
|
||||
public static final String GUI_KEY = FluidCraft.MODID + ".gui.";
|
||||
public static final String GUI_FLUID_PATTERN_TERMINAL = GUI_KEY + ITEM_PART_FLUID_PATTERN_TERMINAL;
|
||||
public static final String GUI_FLUID_PATTERN_ENCODER = GUI_KEY + BLOCK_FLUID_PATTERN_ENCODER;
|
||||
public static final String GUI_FLUID_PACKET_DECODER = GUI_KEY + BLOCK_FLUID_PACKET_DECODER;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* An {@link java.util.Iterator Iterator} over an array of objects.
|
||||
* <p>
|
||||
* This iterator does not support {@link #remove}, as the object array cannot be
|
||||
* structurally modified.
|
||||
* <p>
|
||||
* The iterator implements a {@link #reset} method, allowing the reset of the iterator
|
||||
* back to the start if required.
|
||||
*
|
||||
* @param <E> the type to iterate over
|
||||
* @since 3.0
|
||||
* @version $Id: ObjectArrayIterator.java 1734648 2016-03-11 23:51:22Z ggregory $
|
||||
*/
|
||||
public class ObjectArrayIterator<E> implements /*Resettable*/ Iterator<E> {
|
||||
|
||||
/** The array */
|
||||
final E[] array;
|
||||
/** The start index to loop from */
|
||||
final int startIndex;
|
||||
/** The end index to loop to */
|
||||
final int endIndex;
|
||||
/** The current iterator index */
|
||||
int index = 0;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
/**
|
||||
* Constructs an ObjectArrayIterator that will iterate over the values in the
|
||||
* specified array.
|
||||
*
|
||||
* @param array the array to iterate over
|
||||
* @throws NullPointerException if <code>array</code> is <code>null</code>
|
||||
*/
|
||||
@SafeVarargs
|
||||
public ObjectArrayIterator(final E... array) {
|
||||
this(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an ObjectArrayIterator that will iterate over the values in the
|
||||
* specified array from a specific start index.
|
||||
*
|
||||
* @param array the array to iterate over
|
||||
* @param start the index to start iterating at
|
||||
* @throws NullPointerException if <code>array</code> is <code>null</code>
|
||||
* @throws IndexOutOfBoundsException if the start index is out of bounds
|
||||
*/
|
||||
public ObjectArrayIterator(final E array[], final int start) {
|
||||
this(array, start, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an ObjectArrayIterator that will iterate over a range of values
|
||||
* in the specified array.
|
||||
*
|
||||
* @param array the array to iterate over
|
||||
* @param start the index to start iterating at
|
||||
* @param end the index (exclusive) to finish iterating at
|
||||
* @throws IndexOutOfBoundsException if the start or end index is out of bounds
|
||||
* @throws IllegalArgumentException if end index is before the start
|
||||
* @throws NullPointerException if <code>array</code> is <code>null</code>
|
||||
*/
|
||||
public ObjectArrayIterator(final E array[], final int start, final int end) {
|
||||
super();
|
||||
if (start < 0) {
|
||||
throw new ArrayIndexOutOfBoundsException("Start index must not be less than zero");
|
||||
}
|
||||
if (end > array.length) {
|
||||
throw new ArrayIndexOutOfBoundsException("End index must not be greater than the array length");
|
||||
}
|
||||
if (start > array.length) {
|
||||
throw new ArrayIndexOutOfBoundsException("Start index must not be greater than the array length");
|
||||
}
|
||||
if (end < start) {
|
||||
throw new IllegalArgumentException("End index must not be less than start index");
|
||||
}
|
||||
this.array = array;
|
||||
this.startIndex = start;
|
||||
this.endIndex = end;
|
||||
this.index = start;
|
||||
}
|
||||
|
||||
// Iterator interface
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns true if there are more elements to return from the array.
|
||||
*
|
||||
* @return true if there is a next element to return
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.index < this.endIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next element in the array.
|
||||
*
|
||||
* @return the next element in the array
|
||||
* @throws NoSuchElementException if all the elements in the array
|
||||
* have already been returned
|
||||
*/
|
||||
@Override
|
||||
public E next() {
|
||||
if (hasNext() == false) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return this.array[this.index++];
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws {@link UnsupportedOperationException}.
|
||||
*
|
||||
* @throws UnsupportedOperationException always
|
||||
*/
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("remove() method is not supported for an ObjectArrayIterator");
|
||||
}
|
||||
|
||||
// Properties
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the array that this iterator is iterating over.
|
||||
*
|
||||
* @return the array this iterator iterates over
|
||||
*/
|
||||
public E[] getArray() {
|
||||
return this.array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the start index to loop from.
|
||||
*
|
||||
* @return the start index
|
||||
*/
|
||||
public int getStartIndex() {
|
||||
return this.startIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the end index to loop to.
|
||||
*
|
||||
* @return the end index
|
||||
*/
|
||||
public int getEndIndex() {
|
||||
return this.endIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the iterator back to the start index.
|
||||
*/
|
||||
//@Override
|
||||
public void reset() {
|
||||
this.index = this.startIndex;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public final class RenderUtil {
|
||||
|
||||
public static void renderItemIcon(IIcon icon, double size, double z, float nx, float ny, float nz) {
|
||||
renderItemIcon(icon, 0.0D, 0.0D, size, size, z, nx, ny, nz);
|
||||
}
|
||||
|
||||
public static void renderItemIcon(IIcon icon, double xStart, double yStart, double xEnd, double yEnd, double z, float nx, float ny, float nz) {
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
Tessellator.instance.setNormal(nx, ny, nz);
|
||||
if (nz > 0.0F) {
|
||||
Tessellator.instance.addVertexWithUV(xStart, yStart, z, icon.getMinU(), icon.getMinV());
|
||||
Tessellator.instance.addVertexWithUV(xEnd, yStart, z, icon.getMaxU(), icon.getMinV());
|
||||
Tessellator.instance.addVertexWithUV(xEnd, yEnd, z, icon.getMaxU(), icon.getMaxV());
|
||||
Tessellator.instance.addVertexWithUV(xStart, yEnd, z, icon.getMinU(), icon.getMaxV());
|
||||
} else {
|
||||
Tessellator.instance.addVertexWithUV(xStart, yEnd, z, icon.getMinU(), icon.getMaxV());
|
||||
Tessellator.instance.addVertexWithUV(xEnd, yEnd, z, icon.getMaxU(), icon.getMaxV());
|
||||
Tessellator.instance.addVertexWithUV(xEnd, yStart, z, icon.getMaxU(), icon.getMinV());
|
||||
Tessellator.instance.addVertexWithUV(xStart, yStart, z, icon.getMinU(), icon.getMinV());
|
||||
}
|
||||
Tessellator.instance.draw();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.IMachineSet;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SetBackedMachineSet implements IMachineSet {
|
||||
|
||||
private final Class<? extends IGridHost> machineClass;
|
||||
private final Set<IGridNode> backingSet;
|
||||
|
||||
public SetBackedMachineSet(Class<? extends IGridHost> machineClass, Set<IGridNode> backingSet) {
|
||||
this.machineClass = machineClass;
|
||||
this.backingSet = backingSet;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Class<? extends IGridHost> getMachineClass() {
|
||||
return machineClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return backingSet.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return backingSet.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
//noinspection SuspiciousMethodCalls
|
||||
return backingSet.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IGridNode> iterator() {
|
||||
return backingSet.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super IGridNode> action) {
|
||||
backingSet.forEach(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<IGridNode> spliterator() {
|
||||
return backingSet.spliterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.parts.IPart;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
public final class Util {
|
||||
|
||||
public static EnumFacing from(ForgeDirection direction) {
|
||||
switch (direction) {
|
||||
case WEST: return EnumFacing.EAST;
|
||||
case EAST: return EnumFacing.WEST;
|
||||
case UNKNOWN: return null;
|
||||
default: {
|
||||
int o = direction.ordinal();
|
||||
return EnumFacing.values()[o];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ForgeDirection from(EnumFacing direction) {
|
||||
switch (direction) {
|
||||
case WEST: return ForgeDirection.EAST;
|
||||
case EAST: return ForgeDirection.WEST;
|
||||
default: {
|
||||
int o = direction.ordinal();
|
||||
return ForgeDirection.values()[o];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasPermission(EntityPlayer player, SecurityPermissions permission, IGrid grid) {
|
||||
return grid == null || hasPermission(player, permission, (ISecurityGrid) grid.getCache(ISecurityGrid.class));
|
||||
}
|
||||
|
||||
public static boolean hasPermission(EntityPlayer player, SecurityPermissions permission, IGridHost host) {
|
||||
return hasPermission(player, permission, host, ForgeDirection.UNKNOWN);
|
||||
}
|
||||
|
||||
public static boolean hasPermission(EntityPlayer player, SecurityPermissions permission, IGridHost host, ForgeDirection side) {
|
||||
return host == null || hasPermission(player, permission, host.getGridNode(side));
|
||||
}
|
||||
|
||||
public static boolean hasPermission(EntityPlayer player, SecurityPermissions permission, IGridNode host) {
|
||||
return host == null || hasPermission(player, permission, host.getGrid());
|
||||
}
|
||||
|
||||
public static boolean hasPermission(EntityPlayer player, SecurityPermissions permission, IPart part) {
|
||||
return part == null || hasPermission(player, permission, part.getGridNode());
|
||||
}
|
||||
|
||||
public static boolean hasPermission(EntityPlayer player, SecurityPermissions permission, ISecurityGrid securityGrid) {
|
||||
return player == null || permission == null || securityGrid == null || securityGrid.hasPermission(player, permission);
|
||||
}
|
||||
|
||||
public static ItemStack copyStackWithSize(ItemStack itemStack, int size)
|
||||
{
|
||||
if (size == 0 || itemStack == null)
|
||||
return null;
|
||||
ItemStack copy = itemStack.copy();
|
||||
copy.stackSize = size;
|
||||
return copy;
|
||||
}
|
||||
|
||||
public static FluidStack getFluidFromItem(ItemStack stack) {
|
||||
if (stack != null && (stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(stack))) {
|
||||
if (stack.getItem() instanceof IFluidContainerItem) {
|
||||
FluidStack fluid = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
|
||||
if (fluid != null) {
|
||||
FluidStack fluid0 = fluid.copy();
|
||||
fluid0.amount *= stack.stackSize;
|
||||
return fluid0;
|
||||
}
|
||||
}
|
||||
if (FluidContainerRegistry.isContainer(stack)) {
|
||||
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
if (fluid != null) {
|
||||
FluidStack fluid0 = fluid.copy();
|
||||
fluid0.amount *= stack.stackSize;
|
||||
return fluid0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isFluidPacket(ItemStack stack) {
|
||||
return stack != null && stack.getItem() instanceof ItemFluidPacket;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user