pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -1,7 +1,6 @@
package appeng.fluids.container;
import java.util.Collections;
import java.util.Map;
@@ -22,98 +21,79 @@ import appeng.fluids.util.AEFluidStack;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
public abstract class ContainerFluidConfigurable extends ContainerUpgradeable implements IFluidSyncContainer {
private FluidSyncHelper sync = null;
public abstract class ContainerFluidConfigurable extends ContainerUpgradeable implements IFluidSyncContainer
{
private FluidSyncHelper sync = null;
public ContainerFluidConfigurable(ContainerType<?> containerType, int id, PlayerInventory ip, IUpgradeableHost te) {
super(containerType, id, ip, te);
}
public ContainerFluidConfigurable(ContainerType<?> containerType, int id, PlayerInventory ip, IUpgradeableHost te )
{
super( containerType, id, ip, te );
}
public abstract IAEFluidTank getFluidConfigInventory();
public abstract IAEFluidTank getFluidConfigInventory();
private FluidSyncHelper getSyncHelper() {
if (this.sync == null) {
this.sync = new FluidSyncHelper(this.getFluidConfigInventory(), 0);
}
return this.sync;
}
private FluidSyncHelper getSyncHelper()
{
if( this.sync == null )
{
this.sync = new FluidSyncHelper( this.getFluidConfigInventory(), 0 );
}
return this.sync;
}
@Override
protected ItemStack transferStackToContainer(ItemStack input) {
LazyOptional<FluidStack> fsOpt = FluidUtil.getFluidContained(input);
if (fsOpt.isPresent()) {
final IAEFluidTank t = this.getFluidConfigInventory();
final IAEFluidStack stack = AEFluidStack.fromFluidStack(fsOpt.orElse(null));
for (int i = 0; i < t.getSlots(); ++i) {
if (t.getFluidInSlot(i) == null && this.isValidForConfig(i, stack)) {
t.setFluidInSlot(i, stack);
break;
}
}
}
return input;
}
@Override
protected ItemStack transferStackToContainer( ItemStack input )
{
LazyOptional<FluidStack> fsOpt = FluidUtil.getFluidContained( input );
if( fsOpt.isPresent() )
{
final IAEFluidTank t = this.getFluidConfigInventory();
final IAEFluidStack stack = AEFluidStack.fromFluidStack( fsOpt.orElse( null ) );
for( int i = 0; i < t.getSlots(); ++i )
{
if( t.getFluidInSlot( i ) == null && this.isValidForConfig( i, stack ) )
{
t.setFluidInSlot( i, stack );
break;
}
}
}
return input;
}
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
// assumes 4 slots per upgrade
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
protected boolean isValidForConfig( int slot, IAEFluidStack fs )
{
if( this.supportCapacity() )
{
// assumes 4 slots per upgrade
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
if (slot > 0 && upgrades < 1) {
return false;
}
if (slot > 4 && upgrades < 2) {
return false;
}
}
if( slot > 0 && upgrades < 1 )
{
return false;
}
if( slot > 4 && upgrades < 2 )
{
return false;
}
}
return true;
}
return true;
}
@Override
protected void standardDetectAndSendChanges() {
if (Platform.isServer()) {
this.getSyncHelper().sendDiff(this.listeners);
@Override
protected void standardDetectAndSendChanges()
{
if( Platform.isServer() )
{
this.getSyncHelper().sendDiff( this.listeners );
// clear out config items that are no longer valid (eg capacity upgrade removed)
final IAEFluidTank t = this.getFluidConfigInventory();
for (int i = 0; i < t.getSlots(); ++i) {
if (t.getFluidInSlot(i) != null && !this.isValidForConfig(i, t.getFluidInSlot(i))) {
t.setFluidInSlot(i, null);
}
}
}
super.standardDetectAndSendChanges();
}
// clear out config items that are no longer valid (eg capacity upgrade removed)
final IAEFluidTank t = this.getFluidConfigInventory();
for( int i = 0; i < t.getSlots(); ++i )
{
if( t.getFluidInSlot( i ) != null && !this.isValidForConfig( i, t.getFluidInSlot( i ) ) )
{
t.setFluidInSlot( i, null );
}
}
}
super.standardDetectAndSendChanges();
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
this.getSyncHelper().sendFull(Collections.singleton(listener));
}
@Override
public void addListener( IContainerListener listener )
{
super.addListener( listener );
this.getSyncHelper().sendFull( Collections.singleton( listener ) );
}
@Override
public void receiveFluidSlots( Map<Integer, IAEFluidStack> fluids )
{
this.getSyncHelper().readPacket( fluids );
}
@Override
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
this.getSyncHelper().readPacket(fluids);
}
}
@@ -1,9 +1,6 @@
package appeng.fluids.container;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
@@ -13,110 +10,95 @@ import net.minecraftforge.items.IItemHandler;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Upgrades;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotRestrictedInput;
import appeng.fluids.parts.PartFluidFormationPlane;
import appeng.fluids.util.IAEFluidTank;
public class ContainerFluidFormationPlane extends ContainerFluidConfigurable {
public class ContainerFluidFormationPlane extends ContainerFluidConfigurable
{
public static ContainerType<ContainerFluidFormationPlane> TYPE;
public static ContainerType<ContainerFluidFormationPlane> TYPE;
private static final ContainerHelper<ContainerFluidFormationPlane, PartFluidFormationPlane> helper = new ContainerHelper<>(
ContainerFluidFormationPlane::new, PartFluidFormationPlane.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerFluidFormationPlane, PartFluidFormationPlane> helper
= new ContainerHelper<>(ContainerFluidFormationPlane::new, PartFluidFormationPlane.class, SecurityPermissions.BUILD);
public static ContainerFluidFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerFluidFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final PartFluidFormationPlane plane;
private final PartFluidFormationPlane plane;
public ContainerFluidFormationPlane(int id, final PlayerInventory ip, final PartFluidFormationPlane te) {
super(TYPE, id, ip, te);
this.plane = te;
}
public ContainerFluidFormationPlane(int id, final PlayerInventory ip, final PartFluidFormationPlane te )
{
super( TYPE, id,ip, te );
this.plane = te;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.plane.getConfig();
}
@Override
public IAEFluidTank getFluidConfigInventory()
{
return this.plane.getConfig();
}
@Override
protected void setupConfig() {
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected void setupConfig()
{
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getPlayerInventory() ) )
.setNotDraggable() );
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
this.checkToolbox();
this.standardDetectAndSendChanges();
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
this.checkToolbox();
this.standardDetectAndSendChanges();
}
@Override
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
@Override
protected boolean isValidForConfig( int slot, IAEFluidStack fs )
{
if( this.supportCapacity() )
{
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
final int y = slot / 9;
final int y = slot / 9;
if (y >= upgrades + 2) {
return false;
}
}
if( y >= upgrades + 2 )
{
return false;
}
}
return true;
}
return true;
}
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
@Override
public boolean isSlotEnabled( final int idx )
{
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
return upgrades > idx;
}
return upgrades > idx;
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
public int availableUpgrades() {
return 5;
}
}
@@ -18,57 +18,51 @@
package appeng.fluids.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import appeng.fluids.parts.PartSharedFluidBus;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
/**
* @author BrockWS
* @version rv5 - 1/05/2018
* @since rv5 1/05/2018
*/
public class ContainerFluidIO extends ContainerFluidConfigurable
{
public class ContainerFluidIO extends ContainerFluidConfigurable {
public static ContainerType<ContainerFluidIO> TYPE;
public static ContainerType<ContainerFluidIO> TYPE;
private static final ContainerHelper<ContainerFluidIO, PartSharedFluidBus> helper
= new ContainerHelper<>(ContainerFluidIO::new, PartSharedFluidBus.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerFluidIO, PartSharedFluidBus> helper = new ContainerHelper<>(
ContainerFluidIO::new, PartSharedFluidBus.class, SecurityPermissions.BUILD);
public static ContainerFluidIO fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerFluidIO fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final PartSharedFluidBus bus;
private final PartSharedFluidBus bus;
public ContainerFluidIO(int id, PlayerInventory ip, PartSharedFluidBus te )
{
super( TYPE, id,ip, te );
this.bus = te;
}
public ContainerFluidIO(int id, PlayerInventory ip, PartSharedFluidBus te) {
super(TYPE, id, ip, te);
this.bus = te;
}
@Override
public IAEFluidTank getFluidConfigInventory()
{
return this.bus.getConfig();
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.bus.getConfig();
}
@Override
protected void setupConfig()
{
this.setupUpgrades();
}
@Override
protected void setupConfig() {
this.setupUpgrades();
}
}
@@ -18,6 +18,14 @@
package appeng.fluids.container;
import java.util.Collections;
import java.util.Map;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketBuffer;
import appeng.api.config.SecurityPermissions;
import appeng.api.storage.data.IAEFluidStack;
@@ -29,111 +37,89 @@ import appeng.fluids.helper.FluidSyncHelper;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketBuffer;
import java.util.Collections;
import java.util.Map;
public class ContainerFluidInterface extends ContainerFluidConfigurable {
public static ContainerType<ContainerFluidInterface> TYPE;
public class ContainerFluidInterface extends ContainerFluidConfigurable
{
private static final ContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper = new ContainerHelper<>(
ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
public static ContainerType<ContainerFluidInterface> TYPE;
public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
private static final ContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper
= new ContainerHelper<>(ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
private final DualityFluidInterface myDuality;
private final FluidSyncHelper tankSync;
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public ContainerFluidInterface(int id, final PlayerInventory ip, final IFluidInterfaceHost te) {
super(TYPE, id, ip, te.getDualityFluidInterface().getHost());
private final DualityFluidInterface myDuality;
private final FluidSyncHelper tankSync;
this.myDuality = te.getDualityFluidInterface();
this.tankSync = new FluidSyncHelper(this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS);
}
public ContainerFluidInterface(int id, final PlayerInventory ip, final IFluidInterfaceHost te )
{
super( TYPE, id,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 );
}
public IAEFluidTank getTanks() {
return myDuality.getTanks();
}
@Override
protected int getHeight()
{
return 231;
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.myDuality.getConfig();
}
public IAEFluidTank getTanks() {
return myDuality.getTanks();
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
@Override
public IAEFluidTank getFluidConfigInventory()
{
return this.myDuality.getConfig();
}
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 ) );
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public void receiveFluidSlots( Map<Integer, IAEFluidStack> fluids )
{
super.receiveFluidSlots( fluids );
this.tankSync.readPacket( fluids );
}
@Override
public int availableUpgrades() {
return 0;
}
@Override
protected boolean supportCapacity()
{
return false;
}
@Override
public int availableUpgrades()
{
return 0;
}
@Override
public boolean hasToolbox()
{
return false;
}
@Override
public boolean hasToolbox() {
return false;
}
}
@@ -1,8 +1,5 @@
package appeng.fluids.container;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@@ -14,100 +11,89 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.fluids.parts.PartFluidLevelEmitter;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable {
public static ContainerType<ContainerFluidLevelEmitter> TYPE;
public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable
{
public static ContainerType<ContainerFluidLevelEmitter> TYPE;
private static final ContainerHelper<ContainerFluidLevelEmitter, PartFluidLevelEmitter> helper = new ContainerHelper<>(
ContainerFluidLevelEmitter::new, PartFluidLevelEmitter.class, SecurityPermissions.BUILD);
private static final ContainerHelper<ContainerFluidLevelEmitter, PartFluidLevelEmitter> helper
= new ContainerHelper<>(ContainerFluidLevelEmitter::new, PartFluidLevelEmitter.class, SecurityPermissions.BUILD);
public static ContainerFluidLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static ContainerFluidLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final PartFluidLevelEmitter lvlEmitter;
private final PartFluidLevelEmitter lvlEmitter;
@OnlyIn(Dist.CLIENT)
private TextFieldWidget textField;
@GuiSync(3)
public long EmitterValue = -1;
@OnlyIn( Dist.CLIENT )
private TextFieldWidget textField;
@GuiSync( 3 )
public long EmitterValue = -1;
public ContainerFluidLevelEmitter(int id, final PlayerInventory ip, final PartFluidLevelEmitter te) {
super(TYPE, id, ip, te);
this.lvlEmitter = te;
}
public ContainerFluidLevelEmitter(int id, final PlayerInventory ip, final PartFluidLevelEmitter te )
{
super( TYPE, id,ip, te );
this.lvlEmitter = te;
}
@OnlyIn(Dist.CLIENT)
public void setTextField(final TextFieldWidget level) {
this.textField = level;
this.textField.setText(String.valueOf(this.EmitterValue));
}
@OnlyIn( Dist.CLIENT )
public void setTextField( final TextFieldWidget level )
{
this.textField = level;
this.textField.setText( String.valueOf( this.EmitterValue ) );
}
public void setLevel(final long l, final PlayerEntity player) {
this.lvlEmitter.setReportingValue(l);
this.EmitterValue = l;
}
public void setLevel( final long l, final PlayerEntity player )
{
this.lvlEmitter.setReportingValue( l );
this.EmitterValue = l;
}
@Override
protected void setupConfig() {
}
@Override
protected void setupConfig()
{
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
protected boolean supportCapacity()
{
return false;
}
@Override
public int availableUpgrades() {
@Override
public int availableUpgrades()
{
return 0;
}
return 0;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
if (Platform.isServer()) {
this.EmitterValue = this.lvlEmitter.getReportingValue();
this.setRedStoneMode(
(RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_EMITTER));
}
if( Platform.isServer() )
{
this.EmitterValue = this.lvlEmitter.getReportingValue();
this.setRedStoneMode( (RedstoneMode) this.getUpgradeable().getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) );
}
this.standardDetectAndSendChanges();
}
this.standardDetectAndSendChanges();
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("EmitterValue")) {
if (this.textField != null) {
this.textField.setText(String.valueOf(this.EmitterValue));
}
}
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue )
{
if( field.equals( "EmitterValue" ) )
{
if( this.textField != null )
{
this.textField.setText( String.valueOf( this.EmitterValue ) );
}
}
}
@Override
public IAEFluidTank getFluidConfigInventory()
{
return this.lvlEmitter.getConfig();
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.lvlEmitter.getConfig();
}
}
@@ -1,228 +1,199 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.container;
import java.util.Iterator;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.fluids.parts.PartFluidStorageBus;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import appeng.util.iterators.NullIterator;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class ContainerFluidStorageBus extends ContainerFluidConfigurable
{
public static ContainerType<ContainerFluidStorageBus> TYPE;
private static final ContainerHelper<ContainerFluidStorageBus, PartFluidStorageBus> helper
= new ContainerHelper<>(ContainerFluidStorageBus::new, PartFluidStorageBus.class);
public static ContainerFluidStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final PartFluidStorageBus storageBus;
@GuiSync( 3 )
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync( 4 )
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public ContainerFluidStorageBus(int id, PlayerInventory ip, PartFluidStorageBus te )
{
super( TYPE, id,ip, te );
this.storageBus = te;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
protected void setupConfig()
{
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
.setNotDraggable() );
this.addSlot(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getPlayerInventory() ) )
.setNotDraggable() );
}
@Override
protected boolean isValidForConfig( int slot, IAEFluidStack fs )
{
if( this.supportCapacity() )
{
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
final int y = slot / 9;
if( y >= upgrades + 2 )
{
return false;
}
}
return true;
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
if( Platform.isServer() )
{
this.setFuzzyMode( (FuzzyMode) this.getUpgradeable().getConfigManager().getSetting( Settings.FUZZY_MODE ) );
this.setReadWriteMode( (AccessRestriction) this.getUpgradeable().getConfigManager().getSetting( Settings.ACCESS ) );
this.setStorageFilter( (StorageFilter) this.getUpgradeable().getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
}
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled( final int idx )
{
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
return upgrades > idx;
}
public void clear()
{
IAEFluidTank h = this.storageBus.getConfig();
for( int i = 0; i < h.getSlots(); ++i )
{
h.setFluidInSlot( i, null );
}
this.detectAndSendChanges();
}
public void partition()
{
IAEFluidTank h = this.storageBus.getConfig();
final IMEInventory<IAEFluidStack> cellInv = this.storageBus.getInternalHandler();
Iterator<IAEFluidStack> i = new NullIterator<>();
if( cellInv != null )
{
final IItemList<IAEFluidStack> list = cellInv
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList() );
i = list.iterator();
}
for( int x = 0; x < h.getSlots(); x++ )
{
if( i.hasNext() && this.isSlotEnabled( ( x / 9 ) - 2 ) )
{
h.setFluidInSlot( x, i.next() );
}
else
{
h.setFluidInSlot( x, null );
}
}
this.detectAndSendChanges();
}
public AccessRestriction getReadWriteMode()
{
return this.rwMode;
}
private void setReadWriteMode( final AccessRestriction rwMode )
{
this.rwMode = rwMode;
}
public StorageFilter getStorageFilter()
{
return this.storageFilter;
}
private void setStorageFilter( final StorageFilter storageFilter )
{
this.storageFilter = storageFilter;
}
@Override
public IAEFluidTank getFluidConfigInventory()
{
return this.storageBus.getConfig();
}
}
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.container;
import java.util.Iterator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.SlotRestrictedInput;
import appeng.fluids.parts.PartFluidStorageBus;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import appeng.util.iterators.NullIterator;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class ContainerFluidStorageBus extends ContainerFluidConfigurable {
public static ContainerType<ContainerFluidStorageBus> TYPE;
private static final ContainerHelper<ContainerFluidStorageBus, PartFluidStorageBus> helper = new ContainerHelper<>(
ContainerFluidStorageBus::new, PartFluidStorageBus.class);
public static ContainerFluidStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final PartFluidStorageBus storageBus;
@GuiSync(3)
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public ContainerFluidStorageBus(int id, PlayerInventory ip, PartFluidStorageBus te) {
super(TYPE, id, ip, te);
this.storageBus = te;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig() {
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
final int y = slot / 9;
if (y >= upgrades + 2) {
return false;
}
}
return true;
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades() {
return 5;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
this.setFuzzyMode((FuzzyMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FUZZY_MODE));
this.setReadWriteMode(
(AccessRestriction) this.getUpgradeable().getConfigManager().getSetting(Settings.ACCESS));
this.setStorageFilter(
(StorageFilter) this.getUpgradeable().getConfigManager().getSetting(Settings.STORAGE_FILTER));
}
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > idx;
}
public void clear() {
IAEFluidTank h = this.storageBus.getConfig();
for (int i = 0; i < h.getSlots(); ++i) {
h.setFluidInSlot(i, null);
}
this.detectAndSendChanges();
}
public void partition() {
IAEFluidTank h = this.storageBus.getConfig();
final IMEInventory<IAEFluidStack> cellInv = this.storageBus.getInternalHandler();
Iterator<IAEFluidStack> i = new NullIterator<>();
if (cellInv != null) {
final IItemList<IAEFluidStack> list = cellInv.getAvailableItems(
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList());
i = list.iterator();
}
for (int x = 0; x < h.getSlots(); x++) {
if (i.hasNext() && this.isSlotEnabled((x / 9) - 2)) {
h.setFluidInSlot(x, i.next());
} else {
h.setFluidInSlot(x, null);
}
}
this.detectAndSendChanges();
}
public AccessRestriction getReadWriteMode() {
return this.rwMode;
}
private void setReadWriteMode(final AccessRestriction rwMode) {
this.rwMode = rwMode;
}
public StorageFilter getStorageFilter() {
return this.storageFilter;
}
private void setStorageFilter(final StorageFilter storageFilter) {
this.storageFilter = storageFilter;
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.storageBus.getConfig();
}
}
@@ -1,504 +1,429 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.container;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEFluidInventoryUpdate;
import appeng.core.sync.packets.PacketTargetFluidStack;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.fluids.util.AEFluidStack;
import appeng.helpers.InventoryAction;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
/**
* @author BrockWS
* @version rv6 - 12/05/2018
* @since rv6 12/05/2018
*/
public class ContainerFluidTerminal extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack>
{
public static ContainerType<ContainerFluidTerminal> TYPE;
private static final ContainerHelper<ContainerFluidTerminal, ITerminalHost> helper
= new ContainerHelper<>(ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD);
public static ContainerFluidTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final IConfigManager clientCM;
private final IMEMonitor<IAEFluidStack> monitor;
private final IItemList<IAEFluidStack> fluids = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
@GuiSync( 99 )
public boolean hasPower = false;
private ITerminalHost terminal;
private IConfigManager serverCM;
private IConfigManagerHost gui;
private IGridNode networkNode;
// Holds the fluid the client wishes to extract, or null for insert
private IAEFluidStack clientRequestedTargetFluid = null;
public ContainerFluidTerminal(int id, PlayerInventory ip, ITerminalHost terminal) {
super(TYPE, id, ip, terminal);
this.terminal = terminal;
this.clientCM = new ConfigManager( this );
this.clientCM.registerSetting( Settings.SORT_BY, SortOrder.NAME );
this.clientCM.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
this.clientCM.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
if( Platform.isServer() )
{
this.serverCM = terminal.getConfigManager();
this.monitor = terminal.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
if( this.monitor != null )
{
this.monitor.addListener( this, null );
if( terminal instanceof IEnergySource )
{
this.setPowerSource( (IEnergySource) terminal );
}
else if( terminal instanceof IGridHost || terminal instanceof IActionHost )
{
final IGridNode node;
if( terminal instanceof IGridHost )
{
node = ( (IGridHost) terminal ).getGridNode( AEPartLocation.INTERNAL );
}
else if( terminal instanceof IActionHost )
{
node = ( (IActionHost) terminal ).getActionableNode();
}
else
{
node = null;
}
if( node != null )
{
this.networkNode = node;
final IGrid g = node.getGrid();
if( g != null )
{
this.setPowerSource( new ChannelPowerSrc( this.networkNode, (IEnergySource) g.getCache( IEnergyGrid.class ) ) );
}
}
}
}
}
else
{
this.monitor = null;
}
this.bindPlayerInventory( ip, 0, 222 - 82 );
}
@Override
public boolean isValid( Object verificationToken )
{
return true;
}
@Override
public void postChange( IBaseMonitor<IAEFluidStack> monitor, Iterable<IAEFluidStack> change, IActionSource actionSource )
{
for( final IAEFluidStack is : change )
{
this.fluids.add( is );
}
}
@Override
public void onListUpdate()
{
for( final IContainerListener c : this.listeners )
{
this.queueInventory( c );
}
}
@Override
public void addListener( IContainerListener listener )
{
super.addListener( listener );
this.queueInventory( listener );
}
@Override
public void onContainerClosed( final PlayerEntity player )
{
super.onContainerClosed( player );
if( this.monitor != null )
{
this.monitor.removeListener( this );
}
}
private void queueInventory( final IContainerListener c )
{
if( Platform.isServer() && c instanceof PlayerEntity && this.monitor != null )
{
try
{
PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
for( final IAEFluidStack send : monitorCache )
{
try
{
piu.appendFluid( send );
}
catch( final BufferOverflowException boe )
{
NetworkHandler.instance().sendTo( piu, (ServerPlayerEntity) c );
piu = new PacketMEFluidInventoryUpdate();
piu.appendFluid( send );
}
}
NetworkHandler.instance().sendTo( piu, (ServerPlayerEntity) c );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
@Override
public IConfigManager getConfigManager()
{
if( Platform.isServer() )
{
return this.serverCM;
}
return this.clientCM;
}
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 ) );
}
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
}
@Override
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue )
{
if( this.getGui() != null )
{
this.getGui().updateSetting( manager, settingName, newValue );
}
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() )
{
if( this.monitor != this.terminal.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ) )
{
this.setValidContainer( false );
}
for( final Settings set : this.serverCM.getSettings() )
{
final Enum<?> sideLocal = this.serverCM.getSetting( set );
final Enum<?> sideRemote = this.clientCM.getSetting( set );
if( sideLocal != sideRemote )
{
this.clientCM.putSetting( set, sideLocal );
for( final IContainerListener crafter : this.listeners )
{
if( crafter instanceof ServerPlayerEntity )
{
NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (ServerPlayerEntity) crafter );
}
}
}
}
if( !this.fluids.isEmpty() )
{
try
{
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
final PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
for( final IAEFluidStack is : this.fluids )
{
final IAEFluidStack send = monitorCache.findPrecise( is );
if( send == null )
{
is.setStackSize( 0 );
piu.appendFluid( is );
}
else
{
piu.appendFluid( send );
}
}
if( !piu.isEmpty() )
{
this.fluids.resetStatus();
for( final Object c : this.listeners )
{
if( c instanceof PlayerEntity )
{
NetworkHandler.instance().sendTo( piu, (ServerPlayerEntity) c );
}
}
}
}
catch( final IOException e )
{
AELog.debug( e );
}
}
this.updatePowerStatus();
super.detectAndSendChanges();
}
}
@Override
public void doAction( ServerPlayerEntity player, InventoryAction action, int slot, long id )
{
if( action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM )
{
super.doAction( player, action, slot, id );
return;
}
final ItemStack held = player.inventory.getItemStack();
if( held.getCount() != 1 )
{
// only support stacksize 1 for now
return;
}
final LazyOptional<IFluidHandlerItem> fhOpt = FluidUtil.getFluidHandler( held );
if( !fhOpt.isPresent() )
{
// only fluid handlers items
return;
}
IFluidHandlerItem fh = fhOpt.orElse( null );
if( action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null )
{
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
// Check how much we can store in the item
stack.setStackSize( Integer.MAX_VALUE );
int amountAllowed = fh.fill( stack.getFluidStack(), FluidAction.SIMULATE );
stack.setStackSize( amountAllowed );
// Check if we can pull out of the system
final IAEFluidStack canPull = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack, this.getActionSource(), Actionable.SIMULATE );
if( canPull == null || canPull.getStackSize() < 1 )
{
return;
}
// How much could fit into the container
final int canFill = fh.fill( canPull.getFluidStack(), FluidAction.SIMULATE );
if( canFill == 0 )
{
return;
}
// Now actually pull out of the system
stack.setStackSize( canFill );
final IAEFluidStack pulled = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack, this.getActionSource() );
if( pulled == null || pulled.getStackSize() < 1 )
{
// Something went wrong
AELog.error( "Unable to pull fluid out of the ME system even though the simulation said yes " );
return;
}
// Actually fill
final int used = fh.fill( pulled.getFluidStack(), FluidAction.EXECUTE );
if( used != canFill )
{
AELog.error( "Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName() );
}
player.inventory.setItemStack( fh.getContainer() );
this.updateHeld( player );
}
else if( action == InventoryAction.EMPTY_ITEM )
{
// See how much we can drain from the item
final FluidStack extract = fh.drain( Integer.MAX_VALUE, FluidAction.SIMULATE );
if( extract == null || extract.getAmount() < 1 )
{
return;
}
// Check if we can push into the system
final IAEFluidStack notStorable = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource(), Actionable.SIMULATE );
if( notStorable != null && notStorable.getStackSize() > 0 )
{
final int toStore = (int) ( extract.getAmount() - notStorable.getStackSize() );
final FluidStack storable = fh.drain( toStore, FluidAction.SIMULATE );
if( storable == null || storable.getAmount() == 0 )
{
return;
}
else
{
extract.setAmount( storable.getAmount() );
}
}
// Actually drain
final FluidStack drained = fh.drain( extract, FluidAction.EXECUTE );
extract.setAmount( drained.getAmount() );
final IAEFluidStack notInserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource() );
if( notInserted != null && notInserted.getStackSize() > 0 )
{
AELog.error( "Fluid item [%s] reported a different possible amount to drain than it actually provided.", held.getDisplayName() );
}
player.inventory.setItemStack( fh.getContainer() );
this.updateHeld( player );
}
}
protected void updatePowerStatus()
{
try
{
if( this.networkNode != null )
{
this.setPowered( this.networkNode.isActive() );
}
else if( this.getPowerSource() instanceof IEnergyGrid )
{
this.setPowered( ( (IEnergyGrid) this.getPowerSource() ).isNetworkPowered() );
}
else
{
this.setPowered( this.getPowerSource().extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.8 );
}
}
catch( final Exception ignore )
{
// :P
}
}
private IConfigManagerHost getGui()
{
return this.gui;
}
public void setGui( @Nonnull final IConfigManagerHost gui )
{
this.gui = gui;
}
public boolean isPowered()
{
return this.hasPower;
}
private void setPowered( final boolean isPowered )
{
this.hasPower = isPowered;
}
}
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.container;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEFluidInventoryUpdate;
import appeng.core.sync.packets.PacketTargetFluidStack;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.fluids.util.AEFluidStack;
import appeng.helpers.InventoryAction;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
/**
* @author BrockWS
* @version rv6 - 12/05/2018
* @since rv6 12/05/2018
*/
public class ContainerFluidTerminal extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack> {
public static ContainerType<ContainerFluidTerminal> TYPE;
private static final ContainerHelper<ContainerFluidTerminal, ITerminalHost> helper = new ContainerHelper<>(
ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD);
public static ContainerFluidTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final IConfigManager clientCM;
private final IMEMonitor<IAEFluidStack> monitor;
private final IItemList<IAEFluidStack> fluids = AEApi.instance().storage()
.getStorageChannel(IFluidStorageChannel.class).createList();
@GuiSync(99)
public boolean hasPower = false;
private ITerminalHost terminal;
private IConfigManager serverCM;
private IConfigManagerHost gui;
private IGridNode networkNode;
// Holds the fluid the client wishes to extract, or null for insert
private IAEFluidStack clientRequestedTargetFluid = null;
public ContainerFluidTerminal(int id, PlayerInventory ip, ITerminalHost terminal) {
super(TYPE, id, ip, terminal);
this.terminal = terminal;
this.clientCM = new ConfigManager(this);
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
if (Platform.isServer()) {
this.serverCM = terminal.getConfigManager();
this.monitor = terminal
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
if (this.monitor != null) {
this.monitor.addListener(this, null);
if (terminal instanceof IEnergySource) {
this.setPowerSource((IEnergySource) terminal);
} else if (terminal instanceof IGridHost || terminal instanceof IActionHost) {
final IGridNode node;
if (terminal instanceof IGridHost) {
node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL);
} else if (terminal instanceof IActionHost) {
node = ((IActionHost) terminal).getActionableNode();
} else {
node = null;
}
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode,
(IEnergySource) g.getCache(IEnergyGrid.class)));
}
}
}
}
} else {
this.monitor = null;
}
this.bindPlayerInventory(ip, 0, 222 - 82);
}
@Override
public boolean isValid(Object verificationToken) {
return true;
}
@Override
public void postChange(IBaseMonitor<IAEFluidStack> monitor, Iterable<IAEFluidStack> change,
IActionSource actionSource) {
for (final IAEFluidStack is : change) {
this.fluids.add(is);
}
}
@Override
public void onListUpdate() {
for (final IContainerListener c : this.listeners) {
this.queueInventory(c);
}
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
this.queueInventory(listener);
}
@Override
public void onContainerClosed(final PlayerEntity player) {
super.onContainerClosed(player);
if (this.monitor != null) {
this.monitor.removeListener(this);
}
}
private void queueInventory(final IContainerListener c) {
if (Platform.isServer() && c instanceof PlayerEntity && this.monitor != null) {
try {
PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
for (final IAEFluidStack send : monitorCache) {
try {
piu.appendFluid(send);
} catch (final BufferOverflowException boe) {
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
piu = new PacketMEFluidInventoryUpdate();
piu.appendFluid(send);
}
}
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
@Override
public IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
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));
}
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
}
@Override
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue) {
if (this.getGui() != null) {
this.getGui().updateSetting(manager, settingName, newValue);
}
}
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
if (this.monitor != this.terminal
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) {
this.setValidContainer(false);
}
for (final Settings set : this.serverCM.getSettings()) {
final Enum<?> sideLocal = this.serverCM.getSetting(set);
final Enum<?> sideRemote = this.clientCM.getSetting(set);
if (sideLocal != sideRemote) {
this.clientCM.putSetting(set, sideLocal);
for (final IContainerListener crafter : this.listeners) {
if (crafter instanceof ServerPlayerEntity) {
NetworkHandler.instance().sendTo(new PacketValueConfig(set.name(), sideLocal.name()),
(ServerPlayerEntity) crafter);
}
}
}
}
if (!this.fluids.isEmpty()) {
try {
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
final PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
for (final IAEFluidStack is : this.fluids) {
final IAEFluidStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendFluid(is);
} else {
piu.appendFluid(send);
}
}
if (!piu.isEmpty()) {
this.fluids.resetStatus();
for (final Object c : this.listeners) {
if (c instanceof PlayerEntity) {
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
}
}
}
} catch (final IOException e) {
AELog.debug(e);
}
}
this.updatePowerStatus();
super.detectAndSendChanges();
}
}
@Override
public void doAction(ServerPlayerEntity player, InventoryAction action, int slot, long id) {
if (action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM) {
super.doAction(player, action, slot, id);
return;
}
final ItemStack held = player.inventory.getItemStack();
if (held.getCount() != 1) {
// only support stacksize 1 for now
return;
}
final LazyOptional<IFluidHandlerItem> fhOpt = FluidUtil.getFluidHandler(held);
if (!fhOpt.isPresent()) {
// only fluid handlers items
return;
}
IFluidHandlerItem fh = fhOpt.orElse(null);
if (action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null) {
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
// Check how much we can store in the item
stack.setStackSize(Integer.MAX_VALUE);
int amountAllowed = fh.fill(stack.getFluidStack(), FluidAction.SIMULATE);
stack.setStackSize(amountAllowed);
// Check if we can pull out of the system
final IAEFluidStack canPull = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack,
this.getActionSource(), Actionable.SIMULATE);
if (canPull == null || canPull.getStackSize() < 1) {
return;
}
// How much could fit into the container
final int canFill = fh.fill(canPull.getFluidStack(), FluidAction.SIMULATE);
if (canFill == 0) {
return;
}
// Now actually pull out of the system
stack.setStackSize(canFill);
final IAEFluidStack pulled = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack,
this.getActionSource());
if (pulled == null || pulled.getStackSize() < 1) {
// Something went wrong
AELog.error("Unable to pull fluid out of the ME system even though the simulation said yes ");
return;
}
// Actually fill
final int used = fh.fill(pulled.getFluidStack(), FluidAction.EXECUTE);
if (used != canFill) {
AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted.",
held.getDisplayName());
}
player.inventory.setItemStack(fh.getContainer());
this.updateHeld(player);
} else if (action == InventoryAction.EMPTY_ITEM) {
// See how much we can drain from the item
final FluidStack extract = fh.drain(Integer.MAX_VALUE, FluidAction.SIMULATE);
if (extract == null || extract.getAmount() < 1) {
return;
}
// Check if we can push into the system
final IAEFluidStack notStorable = Platform.poweredInsert(this.getPowerSource(), this.monitor,
AEFluidStack.fromFluidStack(extract), this.getActionSource(), Actionable.SIMULATE);
if (notStorable != null && notStorable.getStackSize() > 0) {
final int toStore = (int) (extract.getAmount() - notStorable.getStackSize());
final FluidStack storable = fh.drain(toStore, FluidAction.SIMULATE);
if (storable == null || storable.getAmount() == 0) {
return;
} else {
extract.setAmount(storable.getAmount());
}
}
// Actually drain
final FluidStack drained = fh.drain(extract, FluidAction.EXECUTE);
extract.setAmount(drained.getAmount());
final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor,
AEFluidStack.fromFluidStack(extract), this.getActionSource());
if (notInserted != null && notInserted.getStackSize() > 0) {
AELog.error("Fluid item [%s] reported a different possible amount to drain than it actually provided.",
held.getDisplayName());
}
player.inventory.setItemStack(fh.getContainer());
this.updateHeld(player);
}
}
protected void updatePowerStatus() {
try {
if (this.networkNode != null) {
this.setPowered(this.networkNode.isActive());
} else if (this.getPowerSource() instanceof IEnergyGrid) {
this.setPowered(((IEnergyGrid) this.getPowerSource()).isNetworkPowered());
} else {
this.setPowered(
this.getPowerSource().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.8);
}
} catch (final Exception ignore) {
// :P
}
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
public boolean isPowered() {
return this.hasPower;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
}
@@ -1,13 +1,10 @@
package appeng.fluids.container;
import java.util.Map;
import appeng.api.storage.data.IAEFluidStack;
public interface IFluidSyncContainer
{
void receiveFluidSlots( final Map<Integer, IAEFluidStack> fluids );
public interface IFluidSyncContainer {
void receiveFluidSlots(final Map<Integer, IAEFluidStack> fluids);
}
@@ -18,21 +18,17 @@
package appeng.fluids.container.slots;
import appeng.api.storage.data.IAEFluidStack;
/**
* @author yueh
* @version rv6
* @since rv6
*/
public interface IMEFluidSlot
{
IAEFluidStack getAEFluidStack();
public interface IMEFluidSlot {
IAEFluidStack getAEFluidStack();
default boolean shouldRenderAsFluid()
{
return true;
}
default boolean shouldRenderAsFluid() {
return true;
}
}