mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 10:34:40 +00:00
begin work
This commit is contained in:
commit
db2ad29b52
124 files changed
+11799
No files matched your search
@@ -0,0 +1,411 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.core.AELog;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class AEFluidInventory implements IAEFluidTank
|
||||
{
|
||||
private final IAEFluidStack[] fluids;
|
||||
private final IAEFluidInventory handler;
|
||||
private final int capacity;
|
||||
private FluidTankInfo[] props = null;
|
||||
|
||||
public AEFluidInventory( final IAEFluidInventory handler, final int slots, final int capcity )
|
||||
{
|
||||
this.fluids = new IAEFluidStack[slots];
|
||||
this.handler = handler;
|
||||
this.capacity = capcity;
|
||||
}
|
||||
|
||||
public AEFluidInventory( final IAEFluidInventory handler, final int slots )
|
||||
{
|
||||
this( handler, slots, Integer.MAX_VALUE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFluidInSlot( final int slot, final IAEFluidStack fluid )
|
||||
{
|
||||
if( slot >= 0 && slot < this.getSlots() )
|
||||
{
|
||||
if( Objects.equals( this.fluids[slot], fluid ) )
|
||||
{
|
||||
if( fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize() )
|
||||
{
|
||||
this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) );
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fluid == null )
|
||||
{
|
||||
this.fluids[slot] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.fluids[slot] = fluid.copy();
|
||||
this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) );
|
||||
}
|
||||
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onContentChanged( final int slot )
|
||||
{
|
||||
if( this.handler != null && Platform.isServer() )
|
||||
{
|
||||
this.handler.onFluidInventoryChanged( this, slot );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack getFluidInSlot( final int slot )
|
||||
{
|
||||
if( slot >= 0 && slot < this.getSlots() )
|
||||
{
|
||||
return this.fluids[slot];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.fluids.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
if( this.props == null )
|
||||
{
|
||||
this.props = new FluidTankInfo[this.getSlots()];
|
||||
for( int i = 0; i < this.getSlots(); ++i )
|
||||
{
|
||||
this.props[i] = new FluidTankInfo(new FluidTankPropertiesWrapper( i ));
|
||||
}
|
||||
|
||||
}
|
||||
return this.props;
|
||||
}
|
||||
|
||||
public int fill( final int slot, final FluidStack resource, final boolean doFill )
|
||||
{
|
||||
if( resource == null || resource.amount <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
|
||||
if( fluid != null && !fluid.getFluidStack().isFluidEqual( resource ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int amountToStore = this.capacity;
|
||||
|
||||
if( fluid != null )
|
||||
{
|
||||
amountToStore -= fluid.getStackSize();
|
||||
}
|
||||
|
||||
amountToStore = Math.min( amountToStore, resource.amount );
|
||||
|
||||
if( doFill )
|
||||
{
|
||||
if( fluid == null )
|
||||
{
|
||||
this.setFluidInSlot( slot, AEFluidStack.create( resource ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
fluid.setStackSize( fluid.getStackSize() + amountToStore );
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
}
|
||||
|
||||
return amountToStore;
|
||||
}
|
||||
|
||||
public FluidStack drain( final int slot, final FluidStack resource, final boolean doDrain )
|
||||
{
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
if(fluid == null || !fluid.getFluidStack().equals(resource))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.drain( slot, resource.amount, doDrain );
|
||||
}
|
||||
|
||||
public FluidStack drain( final int slot, final int maxDrain, boolean doDrain )
|
||||
{
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
if( fluid == null || maxDrain <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int drained = maxDrain;
|
||||
if( fluid.getStackSize() < drained )
|
||||
{
|
||||
drained = (int) fluid.getStackSize();
|
||||
}
|
||||
|
||||
FluidStack stack = new FluidStack( fluid.getFluid(), drained );
|
||||
if( doDrain )
|
||||
{
|
||||
fluid.setStackSize( fluid.getStackSize() - drained );
|
||||
if( fluid.getStackSize() <= 0 )
|
||||
{
|
||||
this.fluids[slot] = null;
|
||||
}
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, final FluidStack fluid, final boolean doFill )
|
||||
{
|
||||
if( fluid == null || fluid.amount <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
final FluidStack insert = fluid.copy();
|
||||
|
||||
int totalFillAmount = 0;
|
||||
for( int slot = 0; slot < this.getSlots(); ++slot )
|
||||
{
|
||||
int fillAmount = this.fill( slot, insert, doFill );
|
||||
totalFillAmount += fillAmount;
|
||||
insert.amount -= fillAmount;
|
||||
if( insert.amount <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return totalFillAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, final FluidStack fluid, final boolean doDrain )
|
||||
{
|
||||
if( fluid == null || fluid.amount <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final FluidStack resource = fluid.copy();
|
||||
|
||||
FluidStack totalDrained = null;
|
||||
for( int slot = 0; slot < this.getSlots(); ++slot )
|
||||
{
|
||||
FluidStack drain = this.drain( slot, resource, doDrain );
|
||||
if( drain != null )
|
||||
{
|
||||
if( totalDrained == null )
|
||||
{
|
||||
totalDrained = drain;
|
||||
}
|
||||
else
|
||||
{
|
||||
totalDrained.amount += drain.amount;
|
||||
}
|
||||
|
||||
resource.amount -= drain.amount;
|
||||
if( resource.amount <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalDrained;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain( ForgeDirection from, final int maxDrain, final boolean doDrain )
|
||||
{
|
||||
if( maxDrain == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack totalDrained = null;
|
||||
int toDrain = maxDrain;
|
||||
|
||||
for( int slot = 0; slot < this.getSlots(); ++slot )
|
||||
{
|
||||
if( totalDrained == null )
|
||||
{
|
||||
totalDrained = this.drain( slot, toDrain, doDrain );
|
||||
if( totalDrained != null )
|
||||
{
|
||||
toDrain -= totalDrained.amount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FluidStack copy = totalDrained.copy();
|
||||
copy.amount = toDrain;
|
||||
FluidStack drain = this.drain( slot, copy, doDrain );
|
||||
if( drain != null )
|
||||
{
|
||||
totalDrained.amount += drain.amount;
|
||||
toDrain -= drain.amount;
|
||||
}
|
||||
}
|
||||
|
||||
if( toDrain <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return totalDrained;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return fill(from, new FluidStack(fluid, 1), false) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return drain(from, new FluidStack(fluid, 1), false) != null;
|
||||
}
|
||||
|
||||
public void writeToNBT( final NBTTagCompound data, final String name )
|
||||
{
|
||||
final NBTTagCompound c = new NBTTagCompound();
|
||||
this.writeToNBT( c );
|
||||
data.setTag( name, c );
|
||||
}
|
||||
|
||||
private void writeToNBT( final NBTTagCompound target )
|
||||
{
|
||||
for( int x = 0; x < this.fluids.length; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
final NBTTagCompound c = new NBTTagCompound();
|
||||
|
||||
if( this.fluids[x] != null )
|
||||
{
|
||||
this.fluids[x].writeToNBT( c );
|
||||
}
|
||||
|
||||
target.setTag( "#" + x, c );
|
||||
}
|
||||
catch( final Exception ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT( final NBTTagCompound data, final String name )
|
||||
{
|
||||
final NBTTagCompound c = data.getCompoundTag( name );
|
||||
if( c != null )
|
||||
{
|
||||
this.readFromNBT( c );
|
||||
}
|
||||
}
|
||||
|
||||
private void readFromNBT( final NBTTagCompound target )
|
||||
{
|
||||
for( int x = 0; x < this.fluids.length; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
final NBTTagCompound c = target.getCompoundTag( "#" + x );
|
||||
|
||||
if( c != null )
|
||||
{
|
||||
this.fluids[x] = AEFluidStack.loadFluidStackFromNBT( c );
|
||||
}
|
||||
}
|
||||
catch( final Exception e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FluidTankPropertiesWrapper implements IFluidTank
|
||||
{
|
||||
private final int slot;
|
||||
|
||||
public FluidTankPropertiesWrapper( final int slot )
|
||||
{
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid()
|
||||
{
|
||||
return AEFluidInventory.this.fluids[this.slot] == null ? null : AEFluidInventory.this.fluids[this.slot].getFluidStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidAmount() {
|
||||
return getFluid() == null ? 0 : getFluid().amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity()
|
||||
{
|
||||
return Math.min( AEFluidInventory.this.capacity, Integer.MAX_VALUE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo getInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
if (resource == null || (getFluid() != null && !resource.equals(getFluid()))) return 0;
|
||||
int acc = 0;
|
||||
if (getFluid() == null) {
|
||||
acc = Math.min(resource.amount, getCapacity());
|
||||
}
|
||||
if (getFluid() != null) {
|
||||
acc = Math.max(resource.amount, getCapacity() - getFluid().amount);
|
||||
}
|
||||
if (doFill) {
|
||||
if (getFluid() == null)
|
||||
AEFluidInventory.this.setFluidInSlot(this.slot, AEFluidStack.create(new FluidStack(resource.getFluid(), acc)));
|
||||
else getFluid().amount += acc;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
if (getFluid() == null) return null;
|
||||
FluidStack remove = new FluidStack(getFluid().getFluid(), 1);
|
||||
int amt = Math.min(maxDrain, getFluid().amount);
|
||||
remove.amount = amt;
|
||||
if (doDrain) {
|
||||
if (amt == getFluid().amount) {
|
||||
AEFluidInventory.this.setFluidInSlot(this.slot, null);
|
||||
}
|
||||
else getFluid().amount -= amt;
|
||||
}
|
||||
return remove;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class AEFluidTank extends FluidTank implements IAEFluidTank
|
||||
{
|
||||
private final IAEFluidInventory host;
|
||||
|
||||
public AEFluidTank( IAEFluidInventory host, int capacity )
|
||||
{
|
||||
super( capacity );
|
||||
this.host = host;
|
||||
if( host instanceof TileEntity) {
|
||||
this.tile = (TileEntity) host;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onContentsChanged()
|
||||
{
|
||||
if( this.host != null && Platform.isServer() )
|
||||
{
|
||||
this.host.onFluidInventoryChanged( this, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFluidInSlot( int slot, IAEFluidStack fluid )
|
||||
{
|
||||
if( slot == 0 )
|
||||
{
|
||||
this.setFluid( fluid == null ? null : fluid.getFluidStack() );
|
||||
this.onContentsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack getFluidInSlot(int slot )
|
||||
{
|
||||
if( slot == 0 )
|
||||
{
|
||||
return AEFluidStack.create( this.getFluid() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return super.fill(resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
if (resource == null || !resource.equals(this.getFluid())) return null;
|
||||
return super.drain(resource.amount, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
return super.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return super.fill(new FluidStack(fluid, 1), false) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return drain(ForgeDirection.UNKNOWN, new FluidStack(fluid, 1), false) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return new FluidTankInfo[]{super.getInfo()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class AeItemStackHandler implements IInventory {
|
||||
|
||||
private final AeStackInventory<IAEItemStack> inv;
|
||||
|
||||
public AeItemStackHandler(AeStackInventory<IAEItemStack> inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getAeInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inv.getSlotCount();
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
IAEItemStack stack = inv.getStack(slot);
|
||||
return stack != null ? stack.getItemStack() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "AeItemStackHandler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface AeStackInventory<T extends IAEStack<T>> extends Iterable<T> {
|
||||
|
||||
int getSlotCount();
|
||||
|
||||
@Nullable
|
||||
T getStack(int slot);
|
||||
|
||||
void setStack(int slot, @Nullable T stack);
|
||||
|
||||
Stream<T> stream();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.glodblock.github.util.ObjectArrayIterator;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AeStackInventoryImpl <T extends IAEStack<T>> implements AeStackInventory<T> {
|
||||
|
||||
private final StorageChannel channel;
|
||||
private final T[] inv;
|
||||
private final IAEAppEngInventory owner;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public AeStackInventoryImpl(StorageChannel channel, int slotCount, @Nullable IAEAppEngInventory owner) {
|
||||
this.channel = channel;
|
||||
this.inv = (T[])new IAEStack[slotCount];
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public AeStackInventoryImpl(StorageChannel channel, int slotCount) {
|
||||
this(channel, slotCount, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return inv.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T getStack(int slot) {
|
||||
return inv[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int slot, @Nullable T stack) {
|
||||
inv[slot] = stack;
|
||||
if (owner != null) {
|
||||
owner.saveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new ObjectArrayIterator<>(inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<T> stream() {
|
||||
return Arrays.stream(inv);
|
||||
}
|
||||
|
||||
public void writeToNbt(NBTTagCompound tag) {
|
||||
NBTTagList stacksTag = new NBTTagList();
|
||||
for (T stack : inv) {
|
||||
if (stack == null) {
|
||||
stacksTag.appendTag(new NBTTagCompound());
|
||||
} else {
|
||||
NBTTagCompound stackTag = new NBTTagCompound();
|
||||
stack.writeToNBT(stackTag);
|
||||
stacksTag.appendTag(stackTag);
|
||||
}
|
||||
}
|
||||
tag.setTag("Contents", stacksTag);
|
||||
}
|
||||
|
||||
public void writeToNbt(NBTTagCompound parentTag, String key) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNbt(tag);
|
||||
parentTag.setTag(key, tag);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void readFromNbt(NBTTagCompound tag) {
|
||||
NBTTagList stacksTag = tag.getTagList("Contents", Constants.NBT.TAG_COMPOUND);
|
||||
for (int i = 0; i < inv.length; i++) {
|
||||
NBTTagCompound stackTag = stacksTag.getCompoundTagAt(i);
|
||||
if (channel == StorageChannel.ITEMS) {
|
||||
inv[i] = stackTag == null ? null : (T) AEItemStack.loadItemStackFromNBT(stackTag);
|
||||
}
|
||||
else {
|
||||
inv[i] = stackTag == null ? null : (T) AEFluidStack.loadFluidStackFromNBT(stackTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNbt(NBTTagCompound parentTag, String key) {
|
||||
readFromNbt(parentTag.getCompoundTag(key));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.common.tile.TileFluidInterface;
|
||||
import com.glodblock.github.util.Ae2Reflect;
|
||||
import com.glodblock.github.util.Util;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
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;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
|
||||
public static InventoryAdaptor wrap(TileEntity capProvider, EnumFacing 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);
|
||||
if (!(inter instanceof TileFluidInterface)) return InventoryAdaptor.getAdaptor(capProvider, f);
|
||||
IInventory item = capProvider instanceof IInventory ? (IInventory) capProvider : null;
|
||||
IFluidHandler fluid = capProvider instanceof IFluidHandler ? (IFluidHandler) capProvider : null;
|
||||
return new FluidConvertingInventoryAdaptor(item, fluid, face);
|
||||
}
|
||||
|
||||
private final InventoryAdaptor invItems;
|
||||
private final IFluidHandler invFluids;
|
||||
private final ForgeDirection side;
|
||||
|
||||
public FluidConvertingInventoryAdaptor(@Nullable IInventory invItems, @Nullable IFluidHandler invFluids, EnumFacing facing) {
|
||||
this.invItems = invItems != null ? InventoryAdaptor.getAdaptor(invItems, Util.from(facing)) : null;
|
||||
this.invFluids = invFluids;
|
||||
this.side = Util.from(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded) {
|
||||
if (toBeAdded.getItem() instanceof ItemFluidPacket) {
|
||||
if (invFluids != null) {
|
||||
FluidStack fluid = ItemFluidPacket.getFluidStack(toBeAdded);
|
||||
if (fluid != null) {
|
||||
int filled = invFluids.fill(side, fluid, true);
|
||||
if (filled > 0) {
|
||||
fluid.amount -= filled;
|
||||
return ItemFluidPacket.newStack(fluid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return toBeAdded;
|
||||
}
|
||||
return invItems != null ? invItems.addItems(toBeAdded) : toBeAdded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated) {
|
||||
if (toBeSimulated.getItem() instanceof ItemFluidPacket) {
|
||||
if (invFluids != null) {
|
||||
FluidStack fluid = ItemFluidPacket.getFluidStack(toBeSimulated);
|
||||
if (fluid != null) {
|
||||
int filled = invFluids.fill(side, fluid, false);
|
||||
if (filled > 0) {
|
||||
fluid.amount -= filled;
|
||||
return ItemFluidPacket.newStack(fluid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return toBeSimulated;
|
||||
}
|
||||
return invItems != null ? invItems.simulateAdd(toBeSimulated) : toBeSimulated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
return invItems != null ? invItems.removeItems(amount, filter, destination) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
return invItems != null ? invItems.simulateRemove(amount, filter, destination) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination) {
|
||||
return invItems != null ? invItems.removeSimilarItems(amount, filter, fuzzyMode, destination) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination) {
|
||||
return invItems != null ? invItems.simulateSimilarRemove(amount, filter, fuzzyMode, destination) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
if (invFluids != null) {
|
||||
for (FluidTankInfo tank : invFluids.getTankInfo(side)) {
|
||||
FluidStack fluid = tank.fluid;
|
||||
if (fluid != null && fluid.amount > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return invItems != null && invItems.containsItems();
|
||||
}
|
||||
|
||||
public boolean hasSlots() {
|
||||
return (invFluids != null && invFluids.getTankInfo(side).length > 0)
|
||||
|| (invItems != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new SlotIterator(
|
||||
invFluids != null ? invFluids.getTankInfo(side) : new FluidTankInfo[0],
|
||||
invItems != null ? invItems.iterator() : Collections.emptyIterator());
|
||||
}
|
||||
|
||||
private static class SlotIterator implements Iterator<ItemSlot> {
|
||||
|
||||
private final FluidTankInfo[] tanks;
|
||||
private final Iterator<ItemSlot> itemSlots;
|
||||
private int nextSlotIndex = 0;
|
||||
|
||||
SlotIterator(FluidTankInfo[] tanks, Iterator<ItemSlot> itemSlots) {
|
||||
this.tanks = tanks;
|
||||
this.itemSlots = itemSlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return nextSlotIndex < tanks.length || itemSlots.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next() {
|
||||
if (nextSlotIndex < tanks.length) {
|
||||
FluidStack fluid = tanks[nextSlotIndex].fluid;
|
||||
ItemSlot slot = new ItemSlot();
|
||||
slot.setSlot(nextSlotIndex++);
|
||||
slot.setItemStack(fluid != null ? ItemFluidPacket.newStack(fluid) : null);
|
||||
Ae2Reflect.setItemSlotExtractable(slot, false);
|
||||
return slot;
|
||||
} else {
|
||||
ItemSlot slot = itemSlots.next();
|
||||
slot.setSlot(nextSlotIndex++);
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FluidConvertingInventoryCrafting extends InventoryCrafting {
|
||||
|
||||
public FluidConvertingInventoryCrafting(Container container, int width, int height) {
|
||||
super(container, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, ItemStack stack) {
|
||||
if (stack.getItem() instanceof ItemFluidDrop) {
|
||||
FluidStack fluid = ItemFluidDrop.getFluidStack(stack);
|
||||
if (fluid != null) {
|
||||
super.setInventorySlotContents(index, ItemFluidPacket.newStack(new FluidStack(fluid, stack.stackSize)));
|
||||
} else {
|
||||
// wtf?
|
||||
super.setInventorySlotContents(index, ItemFluidPacket.newStack(new FluidStack(FluidRegistry.WATER, 1000)));
|
||||
}
|
||||
} else {
|
||||
super.setInventorySlotContents(index, stack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IAEFluidInventory
|
||||
{
|
||||
void onFluidInventoryChanged( final IAEFluidTank inv, final int slot );
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public interface IAEFluidTank extends IFluidHandler {
|
||||
void setFluidInSlot( final int slot, final IAEFluidStack fluid );
|
||||
|
||||
IAEFluidStack getFluidInSlot( final int slot );
|
||||
|
||||
int getSlots();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.network.CPacketSwitchGuis;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class InventoryHandler implements IGuiHandler {
|
||||
|
||||
public static void switchGui(GuiType guiType) {
|
||||
FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(guiType));
|
||||
}
|
||||
|
||||
public static void openGui(EntityPlayer player, World world, BlockPos pos, EnumFacing face, GuiType guiType) {
|
||||
player.openGui(FluidCraft.INSTANCE,
|
||||
(guiType.ordinal() << 3) | face.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@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) {
|
||||
return null;
|
||||
}
|
||||
EnumFacing face = EnumFacing.getFront(faceOrd);
|
||||
GuiType type = GuiType.getByOrdinal(id >>> 3);
|
||||
return type != null ? type.guiFactory.createServerGui(player, world, x, y, z, face) : null;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Nullable
|
||||
@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) {
|
||||
return null;
|
||||
}
|
||||
EnumFacing face = EnumFacing.getFront(faceOrd);
|
||||
GuiType type = GuiType.getByOrdinal(id >>> 3);
|
||||
return type != null ? type.guiFactory.createClientGui(player, world, x, y, z, face) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.glodblock.github.inventory;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public interface PatternConsumer {
|
||||
|
||||
void acceptPattern(IAEItemStack[] inputs, IAEItemStack[] outputs);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.glodblock.github.inventory.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface GuiFactory {
|
||||
|
||||
@Nullable
|
||||
Object createServerGui(EntityPlayer player, World world, int x, int y, int z, EnumFacing face);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Nullable
|
||||
Object createClientGui(EntityPlayer player, World world, int x, int y, int z, EnumFacing face);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.glodblock.github.inventory.gui;
|
||||
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.container.implementations.ContainerCraftingStatus;
|
||||
import com.glodblock.github.client.gui.*;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPacketDecoder;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternEncoder;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
|
||||
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
|
||||
import com.glodblock.github.common.tile.TileFluidPacketDecoder;
|
||||
import com.glodblock.github.common.tile.TileFluidPatternEncoder;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public enum GuiType {
|
||||
|
||||
FLUID_PAT_TERM_CRAFTING_STATUS(new PartGuiFactory<PartFluidPatternTerminal>(PartFluidPatternTerminal.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, PartFluidPatternTerminal inv) {
|
||||
return new ContainerCraftingStatus(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, PartFluidPatternTerminal inv) {
|
||||
return new GuiFluidPatternTerminalCraftingStatus(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_PATTERN_TERMINAL(new PartGuiFactory<ITerminalHost>(ITerminalHost.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, ITerminalHost inv) {
|
||||
return new ContainerFluidPatternTerminal(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, ITerminalHost inv) {
|
||||
return new GuiFluidPatternTerminal(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_PATTERN_ENCODER(new TileGuiFactory<TileFluidPatternEncoder>(TileFluidPatternEncoder.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, TileFluidPatternEncoder inv) {
|
||||
return new ContainerFluidPatternEncoder(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, TileFluidPatternEncoder inv) {
|
||||
return new GuiFluidPatternEncoder(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_CRAFTING_CONFIRM(new PartGuiFactory<PartFluidPatternTerminal>(PartFluidPatternTerminal.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, PartFluidPatternTerminal inv) {
|
||||
return new ContainerFluidCraftConfirm(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, PartFluidPatternTerminal inv) {
|
||||
return new GuiFluidCraftConfirm(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_CRAFTING_AMOUNT(new PartGuiFactory<PartFluidPatternTerminal>(PartFluidPatternTerminal.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, PartFluidPatternTerminal inv) {
|
||||
return new ContainerCraftAmount(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, PartFluidPatternTerminal inv) {
|
||||
return new GuiFluidCraftAmount(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_PACKET_DECODER(new TileGuiFactory<TileFluidPacketDecoder>(TileFluidPacketDecoder.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, TileFluidPacketDecoder inv) {
|
||||
return new ContainerFluidPacketDecoder(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, TileFluidPacketDecoder inv) {
|
||||
return new GuiFluidPacketDecoder(player.inventory, inv);
|
||||
}
|
||||
});
|
||||
|
||||
public static final List<GuiType> VALUES = ImmutableList.copyOf(values());
|
||||
|
||||
@Nullable
|
||||
public static GuiType getByOrdinal(int ordinal) {
|
||||
return ordinal < 0 || ordinal >= VALUES.size() ? null : VALUES.get(ordinal);
|
||||
}
|
||||
|
||||
public final GuiFactory guiFactory;
|
||||
|
||||
GuiType(GuiFactory guiFactory) {
|
||||
this.guiFactory = guiFactory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.glodblock.github.inventory.gui;
|
||||
|
||||
import com.glodblock.github.util.Ae2Reflect;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MouseRegionManager {
|
||||
private final GuiContainer gui;
|
||||
private final List<Region> regions = new ArrayList<>();
|
||||
private final FontRenderer font;
|
||||
|
||||
public MouseRegionManager(GuiContainer gui, FontRenderer font) {
|
||||
this.gui = gui;
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public void addRegion(int x, int y, int width, int height, Handler handler) {
|
||||
regions.add(new Region(x, y, width, height, handler));
|
||||
}
|
||||
|
||||
public boolean onClick(int mX, int mY, int button) {
|
||||
mX -= Ae2Reflect.getGuiLeft(gui);
|
||||
mY -= Ae2Reflect.getGuiTop(gui);
|
||||
for (Region region : regions) {
|
||||
if (region.containsMouse(mX, mY) && region.handler.onClick(button)) {
|
||||
gui.mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1F));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void render(int mX, int mY) {
|
||||
mX -= Ae2Reflect.getGuiLeft(gui);
|
||||
mY -= Ae2Reflect.getGuiTop(gui);
|
||||
for (Region region : regions) {
|
||||
if (region.containsMouse(mX, mY)) {
|
||||
List<String> tooltip = region.handler.getTooltip();
|
||||
if (tooltip != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Region {
|
||||
|
||||
private final int x, y, width, height;
|
||||
private final Handler handler;
|
||||
|
||||
Region(int x, int y, int width, int height, Handler handler) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
boolean containsMouse(int mX, int mY) {
|
||||
return mX >= x && mX < x + width && mY >= y && mY < y + height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface Handler {
|
||||
|
||||
@Nullable
|
||||
default List<String> getTooltip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default boolean onClick(int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.glodblock.github.inventory.gui;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import com.glodblock.github.util.Util;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class PartGuiFactory<T> extends TileGuiFactory<T> {
|
||||
|
||||
PartGuiFactory(Class<T> invClass) {
|
||||
super(invClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected T getInventory(TileEntity tile, EnumFacing face) {
|
||||
if (tile instanceof IPartHost) {
|
||||
IPart part = ((IPartHost)tile).getPart(Util.from(face));
|
||||
if (invClass.isInstance(part)) {
|
||||
return invClass.cast(part);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.glodblock.github.inventory.gui;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import com.glodblock.github.util.Util;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class TileGuiFactory<T> implements GuiFactory {
|
||||
|
||||
protected final Class<T> invClass;
|
||||
|
||||
TileGuiFactory(Class<T> invClass) {
|
||||
this.invClass = invClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected T getInventory(TileEntity tile, EnumFacing 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) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
T inv = getInventory(tile, face);
|
||||
if (inv == null) {
|
||||
return null;
|
||||
}
|
||||
Object gui = createServerGui(player, inv);
|
||||
if (gui instanceof AEBaseContainer) {
|
||||
ContainerOpenContext ctx = new ContainerOpenContext(inv);
|
||||
ctx.setWorld(world);
|
||||
ctx.setX(x);
|
||||
ctx.setY(y);
|
||||
ctx.setZ(z);
|
||||
ctx.setSide(Util.from(face));
|
||||
((AEBaseContainer)gui).setOpenContext(ctx);
|
||||
}
|
||||
return gui;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract Object createServerGui(EntityPlayer player, T inv);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object createClientGui(EntityPlayer player, World world, int x, int y, int z, EnumFacing face) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
T inv = getInventory(tile, face);
|
||||
return inv != null ? createClientGui(player, inv) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract Object createClientGui(EntityPlayer player, T inv);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.glodblock.github.inventory.slot;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface SlotFluid {
|
||||
|
||||
@Nullable
|
||||
IAEItemStack getAeStack();
|
||||
|
||||
void setAeStack(@Nullable IAEItemStack stack, boolean sync);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.glodblock.github.inventory.slot;
|
||||
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class SlotSingleItem extends Slot {
|
||||
|
||||
private final Slot delegate;
|
||||
|
||||
public SlotSingleItem(Slot delegate) {
|
||||
super(delegate.inventory, delegate.getSlotIndex(), delegate.xDisplayPosition, delegate.yDisplayPosition);
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
ItemStack stack = delegate.getStack();
|
||||
return stack == null ? null : Util.copyStackWithSize(stack, 1);
|
||||
}
|
||||
|
||||
// delegated
|
||||
|
||||
@Override
|
||||
public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_) {
|
||||
delegate.onSlotChange(p_75220_1_, p_75220_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer thePlayer, ItemStack stack) {
|
||||
delegate.onPickupFromSlot(thePlayer, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return delegate.isItemValid(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasStack() {
|
||||
return delegate.getHasStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack) {
|
||||
delegate.putStack(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
delegate.onSlotChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit() {
|
||||
return delegate.getSlotStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int amount) {
|
||||
return delegate.decrStackSize(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSlotInInventory(IInventory inv, int slotIn) {
|
||||
return delegate.isSlotInInventory(inv, slotIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer playerIn) {
|
||||
return delegate.canTakeStack(playerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean func_111238_b() {
|
||||
return delegate.func_111238_b();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ResourceLocation getBackgroundIconTexture() {
|
||||
return delegate.getBackgroundIconTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setBackgroundIconTexture(ResourceLocation texture) {
|
||||
delegate.setBackgroundIconTexture(texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotIndex() {
|
||||
return delegate.getSlotIndex();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user