feat: start implementing ME Chest

reference issue: #7
This commit is contained in:
Timo Ley 2023-01-23 19:26:10 +01:00
parent 3dcf98cc58
commit db09e9dff8
13 changed files with 181 additions and 28 deletions

View File

@ -0,0 +1,78 @@
package appeng.block.legacy;
import java.util.EnumSet;
import appeng.api.AEApi;
import appeng.api.storage.ICellHandler;
import appeng.block.AEBaseBlock;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderBlockLegacyChest;
import appeng.core.features.AEFeature;
import appeng.core.localization.PlayerMessages;
import appeng.core.sync.GuiBridge;
import appeng.tile.AEBaseTile;
import appeng.tile.legacy.TileLegacyChest;
import appeng.tile.storage.TileChest;
import appeng.util.Platform;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockLegacyChest extends AEBaseTileBlock {
public BlockLegacyChest() {
super(Material.iron);
this.isFullSize = this.isOpaque = false;
this.setTileEntity(TileChest.class);
this.setFeature(EnumSet.of(AEFeature.Legacy));
}
@Override
protected BaseBlockRender<? extends AEBaseBlock, ? extends AEBaseTile> getRenderer() {
return new RenderBlockLegacyChest();
}
@Override
public boolean onActivated(
final World w,
final int x,
final int y,
final int z,
final EntityPlayer p,
final int side,
final float hitX,
final float hitY,
final float hitZ
) {
final TileChest tg = this.getTileEntity(w, x, y, z);
if (tg != null && !p.isSneaking()) {
if (Platform.isClient()) {
return true;
}
if (side != tg.getUp().ordinal()) {
Platform.openGUI(
p, tg, ForgeDirection.getOrientation(side), GuiBridge.GUI_CHEST
);
} else {
final ItemStack cell = tg.getStackInSlot(1);
if (cell != null) {
final ICellHandler ch
= AEApi.instance().registries().cell().getHandler(cell);
tg.openGui(p, ch, cell, side);
} else {
p.addChatMessage(PlayerMessages.ChestCannotReadStorageCell.get());
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,20 @@
package appeng.client.render.blocks;
import appeng.block.legacy.BlockLegacyChest;
import appeng.client.render.BaseBlockRender;
import appeng.tile.legacy.TileLegacyChest;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
public class RenderBlockLegacyChest extends BaseBlockRender<BlockLegacyChest, TileLegacyChest> {
@Override
public boolean renderInWorld(BlockLegacyChest block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) {
renderer.setRenderBounds(0.02, 0.0, 0.02, 0.98, 0.98, 0.98);
renderer.renderAllFaces = true;
renderer.renderStandardBlock(block, x, y, z);
renderer.renderAllFaces = false;
return true;
}
}

View File

@ -35,6 +35,7 @@ import appeng.block.legacy.BlockAssemblerHeatVent;
import appeng.block.legacy.BlockAssemblerWall;
import appeng.block.legacy.BlockCraftMonitor;
import appeng.block.legacy.BlockCraftTerminal;
import appeng.block.legacy.BlockLegacyChest;
import appeng.block.legacy.BlockLegacyController;
import appeng.block.legacy.BlockPatternEncoder;
import appeng.block.legacy.BlockStorageMonitor;
@ -151,6 +152,7 @@ public final class ApiBlocks implements IBlocks {
private final ITileDefinition assemblerWall;
private final ITileDefinition assemblerHeatVent;
private final ITileDefinition assemblerCraftingAccelerator;
private final ITileDefinition legacyChest;
public ApiBlocks(final DefinitionConstructor constructor) {
final BlockLightDetector lightDetector = new BlockLightDetector();
@ -338,6 +340,7 @@ public final class ApiBlocks implements IBlocks {
= constructor.registerTileDefinition(new BlockAssemblerHeatVent());
this.assemblerCraftingAccelerator
= constructor.registerTileDefinition(new BlockAssemblerCraftingAccelerator());
this.legacyChest = constructor.registerTileDefinition(new BlockLegacyChest());
}
@Override

View File

@ -0,0 +1,45 @@
package appeng.tile.legacy;
import java.util.EnumSet;
import appeng.api.storage.StorageChannel;
import appeng.tile.storage.TileChest;
import net.minecraftforge.common.util.ForgeDirection;
public class TileLegacyChest extends TileChest {
public TileLegacyChest() {
super();
this.getProxy().setIdlePowerUsage(0.5);
this.getProxy().setValidSides(EnumSet.allOf(ForgeDirection.class));
}
@Override
public void
setOrientation(final ForgeDirection inForward, final ForgeDirection inUp) {
ForgeDirection forward = inForward;
ForgeDirection up = inUp;
if (up == ForgeDirection.DOWN) {
up = ForgeDirection.UP;
} else if (up != ForgeDirection.UP) {
forward = up.getOpposite();
up = ForgeDirection.UP;
}
super.setOrientation(forward, up);
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) {
if (this.isPowered()) {
try {
if (this.getHandler(StorageChannel.ITEMS) != null) {
return SIDES;
}
} catch (final ChestNoHandler e) {
// nope!
}
}
return NO_SLOTS;
}
}

View File

@ -68,23 +68,23 @@ import net.minecraftforge.fluids.IFluidHandler;
public class TileChest extends AENetworkPowerTile
implements IMEChest, IFluidHandler, ITerminalHost, IPriorityHost, IConfigManagerHost,
IColorableTile {
private static final ChestNoHandler NO_HANDLER = new ChestNoHandler();
private static final int[] SIDES = { 0 };
private static final int[] FRONT = { 1 };
private static final int[] NO_SLOTS = {};
private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 2);
private final BaseActionSource mySrc = new MachineSource(this);
private final IConfigManager config = new ConfigManager(this);
private ItemStack storageType;
private long lastStateChange = 0;
private int priority = 0;
private int state = 0;
private boolean wasActive = false;
private AEColor paintedColor = AEColor.Transparent;
private boolean isCached = false;
private ICellHandler cellHandler;
private MEMonitorHandler itemCell;
private MEMonitorHandler fluidCell;
protected static final ChestNoHandler NO_HANDLER = new ChestNoHandler();
protected static final int[] SIDES = { 0 };
protected static final int[] FRONT = { 1 };
protected static final int[] NO_SLOTS = {};
protected final AppEngInternalInventory inv = new AppEngInternalInventory(this, 2);
protected final BaseActionSource mySrc = new MachineSource(this);
protected final IConfigManager config = new ConfigManager(this);
protected ItemStack storageType;
protected long lastStateChange = 0;
protected int priority = 0;
protected int state = 0;
protected boolean wasActive = false;
protected AEColor paintedColor = AEColor.Transparent;
protected boolean isCached = false;
protected ICellHandler cellHandler;
protected MEMonitorHandler itemCell;
protected MEMonitorHandler fluidCell;
public TileChest() {
this.setInternalMaxPower(PowerMultiplier.CONFIG.multiply(40));
@ -112,7 +112,7 @@ public class TileChest extends AENetworkPowerTile
}
}
private void recalculateDisplay() {
protected void recalculateDisplay() {
final int oldState = this.state;
for (int x = 0; x < this.getCellCount(); x++) {
@ -145,7 +145,7 @@ public class TileChest extends AENetworkPowerTile
return 1;
}
private IMEInventoryHandler getHandler(final StorageChannel channel)
protected IMEInventoryHandler getHandler(final StorageChannel channel)
throws ChestNoHandler {
if (!this.isCached) {
this.itemCell = null;
@ -198,7 +198,7 @@ public class TileChest extends AENetworkPowerTile
return null;
}
private <StackType extends IAEStack> MEMonitorHandler<StackType>
protected <StackType extends IAEStack> MEMonitorHandler<StackType>
wrap(final IMEInventoryHandler h) {
if (h == null) {
return null;
@ -517,7 +517,7 @@ public class TileChest extends AENetworkPowerTile
return NO_SLOTS;
}
private void tryToStoreContents() {
protected void tryToStoreContents() {
try {
if (this.getStackInSlot(0) != null) {
final IMEInventory<IAEItemStack> cell
@ -728,13 +728,13 @@ public class TileChest extends AENetworkPowerTile
);
}
private static class ChestNoHandler extends Exception {
private static final long serialVersionUID = 7995805326136526631L;
protected static class ChestNoHandler extends Exception {
protected static final long serialVersionUID = 7995805326136526631L;
}
private class ChestNetNotifier<T extends IAEStack<T>>
protected class ChestNetNotifier<T extends IAEStack<T>>
implements IMEMonitorHandlerReceiver<T> {
private final StorageChannel chan;
protected final StorageChannel chan;
public ChestNetNotifier(final StorageChannel chan) {
this.chan = chan;
@ -782,12 +782,12 @@ public class TileChest extends AENetworkPowerTile
}
}
private class ChestMonitorHandler<T extends IAEStack> extends MEMonitorHandler<T> {
protected class ChestMonitorHandler<T extends IAEStack> extends MEMonitorHandler<T> {
public ChestMonitorHandler(final IMEInventoryHandler<T> t) {
super(t);
}
private IMEInventoryHandler<T> getInternalHandler() {
protected IMEInventoryHandler<T> getInternalHandler() {
final IMEInventoryHandler<T> h = this.getHandler();
if (h instanceof MEInventoryHandler) {
return (IMEInventoryHandler<T>) ((MEInventoryHandler) h).getInternal();
@ -807,7 +807,7 @@ public class TileChest extends AENetworkPowerTile
return super.injectItems(input, mode, src);
}
private boolean securityCheck(
protected boolean securityCheck(
final EntityPlayer player, final SecurityPermissions requiredPermission
) {
if (TileChest.this.getTile() instanceof IActionHost

View File

@ -59,6 +59,7 @@ tile.appliedenergistics2.BlockPatternEncoder.name=Pattern Encoder
tile.appliedenergistics2.BlockStorageMonitor.name=ME Storage Monitor
tile.appliedenergistics2.BlockTerminal.name=ME Access Terminal
tile.appliedenergistics2.BlockWirelessAccessPoint.name=Wireless Access Point
tile.appliedenergistics2.BlockLegacyChest.name=ME Chest
item.appliedenergistics2.ItemMaterial.ConversionMatrix.name=Conversion Matrix

View File

@ -47,3 +47,9 @@ shaped=
oredictionary:ingotIron oredictionary:craftingTableWood oredictionary:ingotIron,
oredictionary:ingotIron oredictionary:ingotIron oredictionary:ingotIron,
-> ae2:BlockPatternEncoder
shaped=
glass ae2:ItemMaterial.ConversionMatrix glass,
oredictionary:ingotIron oredictionary:chestWood oredictionary:ingotIron,
oredictionary:ingotIron oredictionary:ingotIron oredictionary:ingotIron,
-> ae2:BlockLegacyChest

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B