Skip to content

Commit

Permalink
feat: start implementing ME Chest
Browse files Browse the repository at this point in the history
reference issue: xsun2001#7
  • Loading branch information
leytilera committed Jan 23, 2023
1 parent 3dcf98c commit db09e9d
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 28 deletions.
78 changes: 78 additions & 0 deletions src/main/java/appeng/block/legacy/BlockLegacyChest.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
3 changes: 3 additions & 0 deletions src/main/java/appeng/core/api/definitions/ApiBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -338,6 +340,7 @@ public ApiBlocks(final DefinitionConstructor constructor) {
= constructor.registerTileDefinition(new BlockAssemblerHeatVent());
this.assemblerCraftingAccelerator
= constructor.registerTileDefinition(new BlockAssemblerCraftingAccelerator());
this.legacyChest = constructor.registerTileDefinition(new BlockLegacyChest());
}

@Override
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/appeng/tile/legacy/TileLegacyChest.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
56 changes: 28 additions & 28 deletions src/main/java/appeng/tile/storage/TileChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@
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));
Expand Down Expand Up @@ -112,7 +112,7 @@ protected void PowerEvent(final PowerEventType x) {
}
}

private void recalculateDisplay() {
protected void recalculateDisplay() {
final int oldState = this.state;

for (int x = 0; x < this.getCellCount(); x++) {
Expand Down Expand Up @@ -145,7 +145,7 @@ public int getCellCount() {
return 1;
}

private IMEInventoryHandler getHandler(final StorageChannel channel)
protected IMEInventoryHandler getHandler(final StorageChannel channel)
throws ChestNoHandler {
if (!this.isCached) {
this.itemCell = null;
Expand Down Expand Up @@ -198,7 +198,7 @@ private IMEInventoryHandler getHandler(final StorageChannel channel)
return null;
}

private <StackType extends IAEStack> MEMonitorHandler<StackType>
protected <StackType extends IAEStack> MEMonitorHandler<StackType>
wrap(final IMEInventoryHandler h) {
if (h == null) {
return null;
Expand Down Expand Up @@ -517,7 +517,7 @@ public int[] getAccessibleSlotsBySide(final ForgeDirection side) {
return NO_SLOTS;
}

private void tryToStoreContents() {
protected void tryToStoreContents() {
try {
if (this.getStackInSlot(0) != null) {
final IMEInventory<IAEItemStack> cell
Expand Down Expand Up @@ -728,13 +728,13 @@ public void saveChanges(final IMEInventory cellInventory) {
);
}

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;
Expand Down Expand Up @@ -782,12 +782,12 @@ public void onListUpdate() {
}
}

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();
Expand All @@ -807,7 +807,7 @@ private IMEInventoryHandler<T> getInternalHandler() {
return super.injectItems(input, mode, src);
}

private boolean securityCheck(
protected boolean securityCheck(
final EntityPlayer player, final SecurityPermissions requiredPermission
) {
if (TileChest.this.getTile() instanceof IActionHost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit db09e9d

Please sign in to comment.