Moved Sorting Config Into the World.
This commit is contained in:
@@ -9,6 +9,10 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import appeng.api.implementations.tiles.IMEChest;
|
||||
import appeng.api.networking.IGrid;
|
||||
@@ -19,27 +23,45 @@ import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigureableObject;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.ItemList;
|
||||
|
||||
public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>
|
||||
public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigureableObject, IMEMonitorHandlerReceiver<IAEItemStack>
|
||||
{
|
||||
|
||||
final IMEMonitor<IAEItemStack> monitor;
|
||||
final IItemList<IAEItemStack> items = new ItemList<IAEItemStack>();
|
||||
|
||||
protected ContainerMEMonitorable(InventoryPlayer ip, IStorageMonitorable montiorable, boolean bindInventory) {
|
||||
IConfigManager serverCM;
|
||||
IConfigManager clientCM;
|
||||
|
||||
public IConfigManagerHost gui;
|
||||
|
||||
protected ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost montiorable, boolean bindInventory) {
|
||||
super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null, montiorable instanceof IPart ? (IPart) montiorable : null );
|
||||
|
||||
clientCM = new ConfigManager( this );
|
||||
|
||||
clientCM.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
clientCM.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
clientCM.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
serverCM = montiorable.getConfigManager();
|
||||
|
||||
monitor = montiorable.getItemInventory();
|
||||
if ( monitor != null )
|
||||
{
|
||||
@@ -72,7 +94,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito
|
||||
bindPlayerInventory( ip, 0, 0 );
|
||||
}
|
||||
|
||||
public ContainerMEMonitorable(InventoryPlayer ip, IStorageMonitorable montiorable) {
|
||||
public ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost montiorable) {
|
||||
this( ip, montiorable, true );
|
||||
}
|
||||
|
||||
@@ -81,6 +103,28 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
for (Enum set : serverCM.getSettings())
|
||||
{
|
||||
Enum sideLocal = serverCM.getSetting( set );
|
||||
Enum sideRemote = clientCM.getSetting( set );
|
||||
|
||||
if ( sideLocal != sideRemote )
|
||||
{
|
||||
clientCM.putSetting( set, sideLocal );
|
||||
for (int j = 0; j < this.crafters.size(); ++j)
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) this.crafters.get( j ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !items.isEmpty() )
|
||||
{
|
||||
try
|
||||
@@ -188,4 +232,19 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
if ( gui != null )
|
||||
gui.updateSetting( manager, settingName, newValue );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return serverCM;
|
||||
return clientCM;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user