GUI Rendering and various fixes
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user