reformatted all src files (#141)
This commit is contained in:
@@ -19,243 +19,201 @@
|
||||
package appeng.fluids.container;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketTargetFluidStack;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketTargetFluidStack;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
import appeng.fluids.helper.FluidSyncHelper;
|
||||
import appeng.fluids.helper.IFluidInterfaceHost;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class ContainerFluidInterface extends ContainerFluidConfigurable implements IConfigManagerHost
|
||||
{
|
||||
private final DualityFluidInterface myDuality;
|
||||
private final FluidSyncHelper tankSync;
|
||||
private IConfigManagerHost gui;
|
||||
// Holds the fluid the client wishes to extract, or null for insert
|
||||
private IAEFluidStack clientRequestedTargetFluid = null;
|
||||
|
||||
public ContainerFluidInterface( final InventoryPlayer ip, final IFluidInterfaceHost te )
|
||||
{
|
||||
super( ip, te.getDualityFluidInterface().getHost() );
|
||||
public class ContainerFluidInterface extends ContainerFluidConfigurable implements IConfigManagerHost {
|
||||
private final DualityFluidInterface myDuality;
|
||||
private final FluidSyncHelper tankSync;
|
||||
private IConfigManagerHost gui;
|
||||
// Holds the fluid the client wishes to extract, or null for insert
|
||||
private IAEFluidStack clientRequestedTargetFluid = null;
|
||||
|
||||
this.myDuality = te.getDualityFluidInterface();
|
||||
this.tankSync = new FluidSyncHelper( this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS );
|
||||
}
|
||||
public ContainerFluidInterface(final InventoryPlayer ip, final IFluidInterfaceHost te) {
|
||||
super(ip, te.getDualityFluidInterface().getHost());
|
||||
|
||||
@Override
|
||||
protected int getHeight()
|
||||
{
|
||||
return 231;
|
||||
}
|
||||
this.myDuality = te.getDualityFluidInterface();
|
||||
this.tankSync = new FluidSyncHelper(this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory()
|
||||
{
|
||||
return this.myDuality.getConfig();
|
||||
}
|
||||
@Override
|
||||
protected int getHeight() {
|
||||
return 231;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
|
||||
{
|
||||
if( this.getGui() != null )
|
||||
{
|
||||
this.getGui().updateSetting( manager, settingName, newValue );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory() {
|
||||
return this.myDuality.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
this.verifyPermissions( SecurityPermissions.BUILD, false );
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) {
|
||||
if (this.getGui() != null) {
|
||||
this.getGui().updateSetting(manager, settingName, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
this.tankSync.sendDiff( this.listeners );
|
||||
}
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
this.verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
this.tankSync.sendDiff(this.listeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadSettingsFromHost( final IConfigManager cm )
|
||||
{
|
||||
}
|
||||
@Override
|
||||
protected void setupConfig() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( IContainerListener listener )
|
||||
{
|
||||
super.addListener( listener );
|
||||
this.tankSync.sendFull( Collections.singleton( listener ) );
|
||||
}
|
||||
@Override
|
||||
protected void loadSettingsFromHost(final IConfigManager cm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveFluidSlots( Map<Integer, IAEFluidStack> fluids )
|
||||
{
|
||||
super.receiveFluidSlots( fluids );
|
||||
this.tankSync.readPacket( fluids );
|
||||
}
|
||||
@Override
|
||||
public void addListener(IContainerListener listener) {
|
||||
super.addListener(listener);
|
||||
this.tankSync.sendFull(Collections.singleton(listener));
|
||||
}
|
||||
|
||||
private IConfigManagerHost getGui()
|
||||
{
|
||||
return this.gui;
|
||||
}
|
||||
@Override
|
||||
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
|
||||
super.receiveFluidSlots(fluids);
|
||||
this.tankSync.readPacket(fluids);
|
||||
}
|
||||
|
||||
public void setGui( @Nonnull final IConfigManagerHost gui )
|
||||
{
|
||||
this.gui = gui;
|
||||
}
|
||||
private IConfigManagerHost getGui() {
|
||||
return this.gui;
|
||||
}
|
||||
|
||||
public void doAction( EntityPlayerMP player, InventoryAction action, int slot, long id )
|
||||
{
|
||||
if( action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM )
|
||||
{
|
||||
super.doAction( player, action, slot, id );
|
||||
return;
|
||||
}
|
||||
public void setGui(@Nonnull final IConfigManagerHost gui) {
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
final ItemStack held = player.inventory.getItemStack();
|
||||
ItemStack heldCopy = held.copy();
|
||||
heldCopy.setCount( 1 );
|
||||
IFluidHandlerItem fh = FluidUtil.getFluidHandler( heldCopy );
|
||||
if( fh == null )
|
||||
{
|
||||
// only fluid handlers items
|
||||
return;
|
||||
}
|
||||
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id) {
|
||||
if (action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM) {
|
||||
super.doAction(player, action, slot, id);
|
||||
return;
|
||||
}
|
||||
|
||||
if( action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null )
|
||||
{
|
||||
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
|
||||
final ItemStack held = player.inventory.getItemStack();
|
||||
ItemStack heldCopy = held.copy();
|
||||
heldCopy.setCount(1);
|
||||
IFluidHandlerItem fh = FluidUtil.getFluidHandler(heldCopy);
|
||||
if (fh == null) {
|
||||
// only fluid handlers items
|
||||
return;
|
||||
}
|
||||
|
||||
// Check how much we can store in the item
|
||||
stack.setStackSize( Integer.MAX_VALUE );
|
||||
int amountAllowed = fh.fill( stack.getFluidStack(), false );
|
||||
int heldAmount = held.getCount();
|
||||
for( int i = 0; i < heldAmount; i++ )
|
||||
{
|
||||
ItemStack copiedFluidContainer = held.copy();
|
||||
copiedFluidContainer.setCount( 1 );
|
||||
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
|
||||
if (action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null) {
|
||||
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
|
||||
|
||||
FluidStack extractableFluid = this.myDuality.getTanks().drain( stack.setStackSize( amountAllowed ).getFluidStack(), false );
|
||||
if( extractableFluid == null || extractableFluid.amount == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
// Check how much we can store in the item
|
||||
stack.setStackSize(Integer.MAX_VALUE);
|
||||
int amountAllowed = fh.fill(stack.getFluidStack(), false);
|
||||
int heldAmount = held.getCount();
|
||||
for (int i = 0; i < heldAmount; i++) {
|
||||
ItemStack copiedFluidContainer = held.copy();
|
||||
copiedFluidContainer.setCount(1);
|
||||
fh = FluidUtil.getFluidHandler(copiedFluidContainer);
|
||||
|
||||
int fillableAmount = fh.fill( extractableFluid, false );
|
||||
if( fillableAmount > 0 )
|
||||
{
|
||||
FluidStack extractedFluid = this.myDuality.getTanks().drain( extractableFluid, true );
|
||||
fh.fill( extractedFluid, true );
|
||||
}
|
||||
FluidStack extractableFluid = this.myDuality.getTanks().drain(stack.setStackSize(amountAllowed).getFluidStack(), false);
|
||||
if (extractableFluid == null || extractableFluid.amount == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if( held.getCount() == 1 )
|
||||
{
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
}
|
||||
else
|
||||
{
|
||||
player.inventory.getItemStack().shrink( 1 );
|
||||
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
|
||||
{
|
||||
player.dropItem( fh.getContainer(), false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( action == InventoryAction.EMPTY_ITEM )
|
||||
{
|
||||
int heldAmount = held.getCount();
|
||||
for( int i = 0; i < heldAmount; i++ )
|
||||
{
|
||||
ItemStack copiedFluidContainer = held.copy();
|
||||
copiedFluidContainer.setCount( 1 );
|
||||
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
|
||||
int fillableAmount = fh.fill(extractableFluid, false);
|
||||
if (fillableAmount > 0) {
|
||||
FluidStack extractedFluid = this.myDuality.getTanks().drain(extractableFluid, true);
|
||||
fh.fill(extractedFluid, true);
|
||||
}
|
||||
|
||||
FluidStack drainable = fh.drain( this.myDuality.getTanks().getTankProperties()[slot].getCapacity(), false );
|
||||
if( drainable != null )
|
||||
{
|
||||
fh.drain( drainable, true );
|
||||
this.myDuality.getTanks().fill( drainable, true );
|
||||
}
|
||||
if (held.getCount() == 1) {
|
||||
player.inventory.setItemStack(fh.getContainer());
|
||||
} else {
|
||||
player.inventory.getItemStack().shrink(1);
|
||||
if (!player.inventory.addItemStackToInventory(fh.getContainer())) {
|
||||
player.dropItem(fh.getContainer(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (action == InventoryAction.EMPTY_ITEM) {
|
||||
int heldAmount = held.getCount();
|
||||
for (int i = 0; i < heldAmount; i++) {
|
||||
ItemStack copiedFluidContainer = held.copy();
|
||||
copiedFluidContainer.setCount(1);
|
||||
fh = FluidUtil.getFluidHandler(copiedFluidContainer);
|
||||
|
||||
if( held.getCount() == 1 )
|
||||
{
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
}
|
||||
else
|
||||
{
|
||||
player.inventory.getItemStack().shrink( 1 );
|
||||
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
|
||||
{
|
||||
player.dropItem( fh.getContainer(), false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateHeld( player );
|
||||
}
|
||||
FluidStack drainable = fh.drain(this.myDuality.getTanks().getTankProperties()[slot].getCapacity(), false);
|
||||
if (drainable != null) {
|
||||
fh.drain(drainable, true);
|
||||
this.myDuality.getTanks().fill(drainable, true);
|
||||
}
|
||||
|
||||
public void setTargetStack( final IAEFluidStack stack )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
if( stack == null && this.clientRequestedTargetFluid == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( stack != null && this.clientRequestedTargetFluid != null && stack.getFluidStack().isFluidEqual( this.clientRequestedTargetFluid.getFluidStack() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
NetworkHandler.instance().sendToServer( new PacketTargetFluidStack( (AEFluidStack) stack ) );
|
||||
}
|
||||
if (held.getCount() == 1) {
|
||||
player.inventory.setItemStack(fh.getContainer());
|
||||
} else {
|
||||
player.inventory.getItemStack().shrink(1);
|
||||
if (!player.inventory.addItemStackToInventory(fh.getContainer())) {
|
||||
player.dropItem(fh.getContainer(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateHeld(player);
|
||||
}
|
||||
|
||||
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
|
||||
}
|
||||
public void setTargetStack(final IAEFluidStack stack) {
|
||||
if (Platform.isClient()) {
|
||||
if (stack == null && this.clientRequestedTargetFluid == null) {
|
||||
return;
|
||||
}
|
||||
if (stack != null && this.clientRequestedTargetFluid != null && stack.getFluidStack().isFluidEqual(this.clientRequestedTargetFluid.getFluidStack())) {
|
||||
return;
|
||||
}
|
||||
NetworkHandler.instance().sendToServer(new PacketTargetFluidStack((AEFluidStack) stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportCapacity()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int availableUpgrades()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
protected boolean supportCapacity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasToolbox()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int availableUpgrades() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasToolbox() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user