GUI Rendering and various fixes
This commit is contained in:
@@ -26,6 +26,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.container.slot.*;
|
||||
import appeng.core.Api;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
@@ -56,12 +57,6 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.me.SlotME;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.guisync.SyncData;
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.container.slot.SlotDisabled;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.container.slot.SlotInaccessible;
|
||||
import appeng.container.slot.SlotPlayerHotBar;
|
||||
import appeng.container.slot.SlotPlayerInv;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketTargetItemStack;
|
||||
@@ -92,6 +87,8 @@ public abstract class AEBaseContainer extends Container
|
||||
private boolean sentCustomName;
|
||||
private int ticksSinceCheck = 900;
|
||||
private IAEItemStack clientRequestedTargetItem = null;
|
||||
// Slots that were created to represent the player inventory
|
||||
private List<Slot> playerInventorySlots = null;
|
||||
|
||||
public AEBaseContainer( ContainerType<?> containerType, int id, final PlayerInventory ip, final TileEntity myTile, final IPart myPart )
|
||||
{
|
||||
@@ -409,7 +406,7 @@ public abstract class AEBaseContainer extends Container
|
||||
{
|
||||
final AppEngSlot cs = (AppEngSlot) inventorySlot;
|
||||
|
||||
if( !( cs.isPlayerSide() ) && !( cs instanceof SlotFake ) /* FIXME && !( cs instanceof SlotCraftingMatrix ) */ )
|
||||
if( !( cs.isPlayerSide() ) && !( cs instanceof SlotFake ) && !( cs instanceof SlotCraftingMatrix) )
|
||||
{
|
||||
if( cs.isItemValid( tis ) )
|
||||
{
|
||||
@@ -428,7 +425,7 @@ public abstract class AEBaseContainer extends Container
|
||||
{
|
||||
final AppEngSlot cs = (AppEngSlot) inventorySlot;
|
||||
|
||||
if( ( cs.isPlayerSide() ) && !( cs instanceof SlotFake ) /* FIXME && !( cs instanceof SlotCraftingMatrix ) */ )
|
||||
if( ( cs.isPlayerSide() ) && !( cs instanceof SlotFake ) && !( cs instanceof SlotCraftingMatrix ) )
|
||||
{
|
||||
if( cs.isItemValid( tis ) )
|
||||
{
|
||||
@@ -658,18 +655,18 @@ public abstract class AEBaseContainer extends Container
|
||||
{
|
||||
final Slot s = this.getSlot( slot );
|
||||
|
||||
// FIXME if( s instanceof SlotCraftingTerm )
|
||||
// FIXME {
|
||||
// FIXME switch( action )
|
||||
// FIXME {
|
||||
// FIXME case CRAFT_SHIFT:
|
||||
// FIXME case CRAFT_ITEM:
|
||||
// FIXME case CRAFT_STACK:
|
||||
// FIXME ( (SlotCraftingTerm) s ).doClick( action, player );
|
||||
// FIXME this.updateHeld( player );
|
||||
// FIXME default:
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
if( s instanceof SlotCraftingTerm )
|
||||
{
|
||||
switch( action )
|
||||
{
|
||||
case CRAFT_SHIFT:
|
||||
case CRAFT_ITEM:
|
||||
case CRAFT_STACK:
|
||||
( (SlotCraftingTerm) s ).doClick( action, player );
|
||||
this.updateHeld( player );
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
if( s instanceof SlotFake )
|
||||
{
|
||||
@@ -742,7 +739,7 @@ public abstract class AEBaseContainer extends Container
|
||||
|
||||
for( final Object j : this.inventorySlots )
|
||||
{
|
||||
if( j instanceof Slot && j.getClass() == s.getClass() /* FIXME && !( j instanceof SlotCraftingTerm ) */ )
|
||||
if( j instanceof Slot && j.getClass() == s.getClass() && !( j instanceof SlotCraftingTerm ) )
|
||||
{
|
||||
from.add( (Slot) j );
|
||||
}
|
||||
@@ -1014,17 +1011,10 @@ public abstract class AEBaseContainer extends Container
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance()
|
||||
.sendTo(
|
||||
new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( p.inventory.getItemStack() ) ),
|
||||
p );
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
NetworkHandler.instance()
|
||||
.sendTo(
|
||||
new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( p.inventory.getItemStack() ) ),
|
||||
p );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import appeng.container.AEBaseContainer;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketProgressBar;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.IContainerListener;
|
||||
|
||||
@@ -66,27 +67,20 @@ public class SyncData
|
||||
this.send( c, val );
|
||||
}
|
||||
}
|
||||
catch( final IllegalArgumentException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
catch( final IllegalAccessException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
catch( final IOException e )
|
||||
catch( final IllegalArgumentException | IllegalAccessException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void send( final IContainerListener o, final Object val ) throws IOException
|
||||
private void send( final IContainerListener o, final Object val )
|
||||
{
|
||||
if( val instanceof String )
|
||||
{
|
||||
if( o instanceof ServerPlayerEntity)
|
||||
{
|
||||
// FIXME NetworkHandler.instance().sendTo( new PacketValueConfig( "SyncDat." + this.channel, (String) val ), (ServerPlayerEntity) o );
|
||||
NetworkHandler.instance().sendTo( new PacketValueConfig( "SyncDat." + this.channel, (String) val ), (ServerPlayerEntity) o );
|
||||
}
|
||||
}
|
||||
else if( this.field.getType().isEnum() )
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package appeng.container.helper;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
abstract class AbstractContainerHelper {
|
||||
|
||||
private final SecurityPermissions requiredPermission;
|
||||
|
||||
public AbstractContainerHelper(SecurityPermissions requiredPermission) {
|
||||
this.requiredPermission = requiredPermission;
|
||||
}
|
||||
|
||||
protected boolean checkPermission(PlayerEntity player, Object accessInterface) {
|
||||
|
||||
// FIXME: Check permissions...
|
||||
if (requiredPermission != null && accessInterface instanceof IActionHost)
|
||||
{
|
||||
final IGridNode gn = ( (IActionHost) accessInterface ).getActionableNode();
|
||||
if( gn != null )
|
||||
{
|
||||
final IGrid g = gn.getGrid();
|
||||
if( g != null )
|
||||
{
|
||||
final boolean requirePower = false;
|
||||
if( requirePower )
|
||||
{
|
||||
final IEnergyGrid eg = g.getCache( IEnergyGrid.class );
|
||||
if( !eg.isNetworkPowered() )
|
||||
{
|
||||
// FIXME trace logging?
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final ISecurityGrid sg = g.getCache( ISecurityGrid.class );
|
||||
if( !sg.hasPermission( player, this.requiredPermission ) )
|
||||
{
|
||||
player.sendMessage(new TranslationTextComponent("appliedenergistics2.permission_denied")
|
||||
.applyTextStyle(TextFormatting.RED));
|
||||
// FIXME trace logging?
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import net.minecraftforge.fml.network.NetworkHooks;
|
||||
* @param <C>
|
||||
* @param <P> The type of part this container is for.
|
||||
*/
|
||||
public final class PartContainerHelper<C extends AEBaseContainer, P extends IPart> {
|
||||
public final class PartContainerHelper<C extends AEBaseContainer, P extends IPart> extends AbstractContainerHelper {
|
||||
|
||||
private final Class<P> partClass;
|
||||
|
||||
@@ -36,6 +36,7 @@ public final class PartContainerHelper<C extends AEBaseContainer, P extends IPar
|
||||
}
|
||||
|
||||
public PartContainerHelper(ContainerFactory<P, C> factory, Class<P> partClass, SecurityPermissions requiredPermission) {
|
||||
super(requiredPermission);
|
||||
this.partClass = partClass;
|
||||
this.factory = factory;
|
||||
this.requiredPermission = requiredPermission;
|
||||
@@ -79,6 +80,10 @@ public final class PartContainerHelper<C extends AEBaseContainer, P extends IPar
|
||||
}
|
||||
P actualPart = partClass.cast(tileEntity);
|
||||
|
||||
if (!checkPermission(player, actualPart)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use block name at position
|
||||
// FIXME: this is not right, we'd need to check the part's item stack, or custom naming interface impl
|
||||
ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent();
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package appeng.container.helper;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.core.AELog;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
@@ -13,6 +19,8 @@ import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
/**
|
||||
@@ -22,7 +30,7 @@ import net.minecraftforge.fml.network.NetworkHooks;
|
||||
* @param <C>
|
||||
*/
|
||||
// FIXME: This is also used in contexts where access is via an item that implements I or exposes I via IGuiItemObject
|
||||
public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> {
|
||||
public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> extends AbstractContainerHelper {
|
||||
|
||||
private final Class<I> interfaceClass;
|
||||
|
||||
@@ -35,6 +43,7 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> {
|
||||
}
|
||||
|
||||
public PartOrTileContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass, SecurityPermissions requiredPermission) {
|
||||
super(requiredPermission);
|
||||
this.interfaceClass = interfaceClass;
|
||||
this.factory = factory;
|
||||
this.requiredPermission = requiredPermission;
|
||||
@@ -61,16 +70,19 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> {
|
||||
|
||||
I accessInterface = getHostFromLocator(player, locator);
|
||||
|
||||
if (accessInterface == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!checkPermission(player, accessInterface)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use block name at position
|
||||
// FIXME: this is not right, we'd need to check the part's item stack, or custom naming interface impl
|
||||
// FIXME: Should move this up, because at this point, it's hard to know where the terminal host came from (part or tile)
|
||||
ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent();
|
||||
|
||||
// FIXME: Check permissions...
|
||||
if (requiredPermission != null) {
|
||||
throw new IllegalStateException(); // NOT YET IMPLEMENTED
|
||||
}
|
||||
|
||||
INamedContainerProvider container = new SimpleNamedContainerProvider(
|
||||
(wnd, p, pl) -> {
|
||||
C c = factory.create(wnd, p, accessInterface);
|
||||
@@ -80,7 +92,7 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> {
|
||||
return c;
|
||||
}, title
|
||||
);
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, container, locator.getBlockPos());
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, container, locator::write);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -92,6 +104,7 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> {
|
||||
}
|
||||
|
||||
TileEntity tileEntity = player.world.getTileEntity(locator.getBlockPos());
|
||||
|
||||
// The tile entity itself can host a terminal (i.e. Chest!)
|
||||
if (interfaceClass.isInstance(tileEntity)) {
|
||||
return interfaceClass.cast(tileEntity);
|
||||
@@ -99,10 +112,15 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> {
|
||||
// But it could also be a part attached to the tile entity
|
||||
IPartHost partHost = (IPartHost) tileEntity;
|
||||
IPart part = partHost.getPart(locator.getSide());
|
||||
if (part == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (interfaceClass.isInstance(part)) {
|
||||
return interfaceClass.cast(part);
|
||||
} else {
|
||||
// FIXME: Logging?
|
||||
AELog.debug("Trying to open a container @ {} for a {}, but the container requires {}",
|
||||
locator, part.getClass(), interfaceClass);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
public final class TileContainerHelper<C extends AEBaseContainer, T extends TileEntity> {
|
||||
public final class TileContainerHelper<C extends AEBaseContainer, T extends TileEntity> extends AbstractContainerHelper {
|
||||
|
||||
private final Class<T> tileEntityClass;
|
||||
|
||||
@@ -27,6 +27,7 @@ public final class TileContainerHelper<C extends AEBaseContainer, T extends Tile
|
||||
}
|
||||
|
||||
public TileContainerHelper(ContainerFactory<T, C> factory, Class<T> tileEntityClass, SecurityPermissions requiredPermission) {
|
||||
super(requiredPermission);
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.factory = factory;
|
||||
this.requiredPermission = requiredPermission;
|
||||
@@ -61,14 +62,13 @@ public final class TileContainerHelper<C extends AEBaseContainer, T extends Tile
|
||||
}
|
||||
T te = tileEntityClass.cast(tileEntity);
|
||||
|
||||
if (!checkPermission(player, te)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use block name at position
|
||||
ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent();
|
||||
|
||||
// FIXME: Check permissions...
|
||||
if (requiredPermission != null) {
|
||||
throw new IllegalStateException(); // NOT YET IMPLEMENTED
|
||||
}
|
||||
|
||||
INamedContainerProvider container = new SimpleNamedContainerProvider(
|
||||
(wnd, p, pl) -> {
|
||||
C c = factory.create(wnd, p, te);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SlotPatternTerm extends SlotCraftingTerm
|
||||
this.groupNum = groupNumber;
|
||||
}
|
||||
|
||||
public AppEngPacket getRequest( final boolean shift ) throws IOException
|
||||
public AppEngPacket getRequest( final boolean shift )
|
||||
{
|
||||
return new PacketPatternSlot( this
|
||||
.getPattern(), Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ).createStack( this.getStack() ), shift );
|
||||
|
||||
@@ -27,9 +27,9 @@ import net.minecraftforge.items.IItemHandler;
|
||||
public class SlotPlayerInv extends AppEngSlot
|
||||
{
|
||||
|
||||
public SlotPlayerInv( final IItemHandler par1iInventory, final int par2, final int par3, final int par4 )
|
||||
public SlotPlayerInv( final IItemHandler par1iInventory, final int idx, final int x, final int y )
|
||||
{
|
||||
super( par1iInventory, par2, par3, par4 );
|
||||
super( par1iInventory, idx, x, y );
|
||||
|
||||
this.setPlayerSide( true );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user