feat: WIP storage monitor implementation

This commit is contained in:
LordMZTE 2022-12-05 17:42:32 +01:00
parent 30f0c25502
commit dea4766634
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
16 changed files with 348 additions and 25 deletions

View File

@ -134,4 +134,6 @@ public interface IMaterials {
IItemDefinition qESingularity();
IItemDefinition blankPattern();
IItemDefinition conversionMatrix();
}

View File

@ -0,0 +1,73 @@
package appeng.block.legacy;
import java.util.EnumSet;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderBlockStorageMonitor;
import appeng.core.Api;
import appeng.core.features.AEFeature;
import appeng.tile.AEBaseTile;
import appeng.tile.legacy.TileStorageMonitor;
import appeng.util.item.AEItemStack;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class BlockStorageMonitor extends BlockLegacyDisplay {
public BlockStorageMonitor() {
super(Material.iron);
this.setTileEntity(TileStorageMonitor.class);
this.setFeature(EnumSet.of(AEFeature.Legacy));
}
@Override
protected BaseBlockRender<? extends AEBaseBlock, ? extends AEBaseTile> getRenderer() {
return new RenderBlockStorageMonitor();
}
@Override
public boolean onBlockActivated(
World w,
int x,
int y,
int z,
EntityPlayer player,
int side,
float hitX,
float hitY,
float hitZ
) {
TileStorageMonitor tile = (TileStorageMonitor) w.getTileEntity(x, y, z);
if (player.getHeldItem() != null) {
if (player.getHeldItem().getItem()
== Api.INSTANCE.definitions()
.materials()
.conversionMatrix()
.maybeItem()
.get()
&& player.isSneaking() && !tile.upgraded) {
if (!w.isRemote) {
player.inventory.decrStackSize(player.inventory.currentItem, 1);
tile.upgraded = true;
tile.markForUpdate();
}
return true;
} else if (side == tile.getForward().ordinal() && !tile.isLocked) {
if (!w.isRemote) {
tile.myItem = AEItemStack.create(new ItemStack(
player.getHeldItem().getItem(),
1,
player.getHeldItem().getItemDamage()
));
tile.markForUpdate();
}
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,146 @@
package appeng.client.render.blocks;
import appeng.api.storage.data.IAEItemStack;
import appeng.block.AEBaseTileBlock;
import appeng.client.ClientHelper;
import appeng.core.AELog;
import appeng.tile.legacy.TileLegacyDisplay;
import appeng.tile.legacy.TileStorageMonitor;
import appeng.util.ReadableNumberConverter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class RenderBlockStorageMonitor extends RenderBlockLegacyDisplay {
private int dspList;
public RenderBlockStorageMonitor() {
this.dspList = GLAllocation.generateDisplayLists(1);
}
@Override
protected void finalize() throws Throwable {
super.finalize();
GLAllocation.deleteDisplayLists(this.dspList);
}
@Override
public boolean hasTESR() {
return true;
}
@Override
public void renderTile(
AEBaseTileBlock b,
TileLegacyDisplay tile_,
Tessellator tess,
double x,
double y,
double z,
float f,
RenderBlocks renderer
) {
TileStorageMonitor tile = (TileStorageMonitor) tile_;
if (tile.myItem != null && tile.isDisplayPowered()) {
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
if (tile.updateDisplayList) {
tile.updateDisplayList = false;
GL11.glNewList(this.dspList, GL11.GL_COMPILE_AND_EXECUTE);
this.tesrRenderScreen(tile, tess, tile.myItem);
GL11.glEndList();
} else {
GL11.glCallList(this.dspList);
}
GL11.glPopMatrix();
}
}
private void
tesrRenderScreen(TileLegacyDisplay tile, Tessellator tess, IAEItemStack ais) {
// GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
final ForgeDirection d = tile.getForward();
GL11.glTranslated(d.offsetX * 0.77, d.offsetY * 0.77, d.offsetZ * 0.77);
switch (d) {
case UP:
GL11.glScalef(1.0f, -1.0f, 1.0f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(tile.getUp().ordinal() * 90.0F, 0, 0, 1);
break;
case DOWN:
GL11.glScalef(1.0f, -1.0f, 1.0f);
GL11.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(tile.getUp().ordinal() * -90.0F, 0, 0, 1);
break;
case EAST:
GL11.glScalef(-1.0f, -1.0f, -1.0f);
GL11.glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
break;
case WEST:
GL11.glScalef(-1.0f, -1.0f, -1.0f);
GL11.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
break;
case NORTH:
GL11.glScalef(-1.0f, -1.0f, -1.0f);
break;
case SOUTH:
GL11.glScalef(-1.0f, -1.0f, -1.0f);
GL11.glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
break;
default:
break;
}
try {
final ItemStack sis = ais.getItemStack();
sis.stackSize = 1;
final int br = 16 << 20 | 16 << 4;
final int var11 = br % 65536;
final int var12 = br / 65536;
OpenGlHelper.setLightmapTextureCoords(
OpenGlHelper.lightmapTexUnit, var11 * 0.8F, var12 * 0.8F
);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
// RenderHelper.enableGUIStandardItemLighting();
tess.setColorOpaque_F(1.0f, 1.0f, 1.0f);
ClientHelper.proxy.doRenderItem(sis, tile.getWorldObj());
} catch (final Exception e) {
AELog.debug(e);
} finally {
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
GL11.glTranslatef(0.0f, 0.14f, -0.24f);
GL11.glScalef(1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f);
final long stackSize = ais.getStackSize();
final String renderedStackSize
= ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
final FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
final int width = fr.getStringWidth(renderedStackSize);
GL11.glTranslatef(-0.5f * width, 0.0f, -1.0f);
fr.drawString(renderedStackSize, 0, 0, 0);
// GL11.glPopAttrib();
}
}

View File

@ -32,6 +32,7 @@ import appeng.block.grindstone.BlockGrinder;
import appeng.block.legacy.BlockCraftMonitor;
import appeng.block.legacy.BlockCraftTerminal;
import appeng.block.legacy.BlockLegacyController;
import appeng.block.legacy.BlockStorageMonitor;
import appeng.block.legacy.BlockTerminal;
import appeng.block.legacy.BlockTransitionPlane;
import appeng.block.legacy.BlockWirelessAccessPoint;
@ -139,6 +140,7 @@ public final class ApiBlocks implements IBlocks {
private final ITileDefinition legacyController;
private final ITileDefinition legacyWirelessAccessPoint;
private final ITileDefinition transitionPlane;
private final ITileDefinition storageMonitor;
public ApiBlocks(final DefinitionConstructor constructor) {
final BlockLightDetector lightDetector = new BlockLightDetector();
@ -316,6 +318,8 @@ public final class ApiBlocks implements IBlocks {
= constructor.registerTileDefinition(new BlockWirelessAccessPoint());
this.transitionPlane
= constructor.registerTileDefinition(new BlockTransitionPlane());
this.storageMonitor
= constructor.registerTileDefinition(new BlockStorageMonitor());
}
@Override

View File

@ -61,16 +61,16 @@ public final class ApiItems implements IItems {
private final IItemDefinition netherQuartzWrench;
private final IItemDefinition netherQuartzKnife;
private final IItemDefinition entropyManipulator;
private final IItemDefinition vibrationCatalyst;
private final IItemDefinition entropyAccelerator;
private final IItemDefinition wirelessTerminal;
private final IItemDefinition biometricCard;
private final IItemDefinition chargedStaff;
private final IItemDefinition massCannon;
private final IItemDefinition memoryCard;
private final IItemDefinition networkTool;
private final IItemDefinition portableCell;
private final IItemDefinition entropyManipulator;
private final IItemDefinition vibrationCatalyst;
private final IItemDefinition entropyAccelerator;
private final IItemDefinition wirelessTerminal;
private final IItemDefinition biometricCard;
private final IItemDefinition chargedStaff;
private final IItemDefinition massCannon;
private final IItemDefinition memoryCard;
private final IItemDefinition networkTool;
private final IItemDefinition portableCell;
private final IItemDefinition cellCreative;
private final IItemDefinition viewCell;
@ -146,17 +146,21 @@ public final class ApiItems implements IItems {
new ToolQuartzCuttingKnife(AEFeature.NetherQuartzTools)
);
this.entropyManipulator = constructor.registerItemDefinition( new ToolEntropyManipulator() );
this.vibrationCatalyst = constructor.registerItemDefinition( new ToolVibrationCatalyst() );
this.entropyAccelerator = constructor.registerItemDefinition( new ToolEntropyAccelerator() );
this.entropyManipulator
= constructor.registerItemDefinition(new ToolEntropyManipulator());
this.vibrationCatalyst
= constructor.registerItemDefinition(new ToolVibrationCatalyst());
this.entropyAccelerator
= constructor.registerItemDefinition(new ToolEntropyAccelerator());
this.wirelessTerminal = constructor.registerItemDefinition( new ToolWirelessTerminal() );
this.biometricCard = constructor.registerItemDefinition( new ToolBiometricCard() );
this.chargedStaff = constructor.registerItemDefinition( new ToolChargedStaff() );
this.massCannon = constructor.registerItemDefinition( new ToolMassCannon() );
this.memoryCard = constructor.registerItemDefinition( new ToolMemoryCard() );
this.networkTool = constructor.registerItemDefinition( new ToolNetworkTool() );
this.portableCell = constructor.registerItemDefinition( new ToolPortableCell() );
this.wirelessTerminal
= constructor.registerItemDefinition(new ToolWirelessTerminal());
this.biometricCard = constructor.registerItemDefinition(new ToolBiometricCard());
this.chargedStaff = constructor.registerItemDefinition(new ToolChargedStaff());
this.massCannon = constructor.registerItemDefinition(new ToolMassCannon());
this.memoryCard = constructor.registerItemDefinition(new ToolMemoryCard());
this.networkTool = constructor.registerItemDefinition(new ToolNetworkTool());
this.portableCell = constructor.registerItemDefinition(new ToolPortableCell());
this.cellCreative
= constructor.registerItemDefinition(new ItemCreativeStorageCell());

View File

@ -562,4 +562,9 @@ public final class ApiMaterials implements IMaterials {
public IItemDefinition blankPattern() {
return this.blankPattern;
}
@Override
public IItemDefinition conversionMatrix() {
return this.conversionMatrix;
}
}

View File

@ -3,8 +3,6 @@ package appeng.items.tools.powered;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Optional;
import appeng.block.misc.BlockTinyTNT;
import appeng.util.InWorldToolOperationResult;
import appeng.util.Platform;

View File

@ -152,5 +152,4 @@ public class TileLegacyController extends AENetworkPowerTile implements ILocatab
new LocatableEventAnnounce(this, LocatableEvent.Unregister)
);
}
}

View File

@ -15,18 +15,19 @@ public class TileLegacyDisplay extends AENetworkTile {
}
@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStreamTileLegacyTerminal(ByteBuf data) {
public void writeToStreamTileLegacyDisplay(ByteBuf data) {
data.writeBoolean(this.displayPowered);
}
@TileEvent(TileEventType.NETWORK_READ)
public void readFromStreamTileLegacyTerminal(ByteBuf data) {
public void readFromStreamTileLegacyDisplay(ByteBuf data) {
this.displayPowered = data.readBoolean();
this.worldObj.func_147451_t(this.xCoord, this.yCoord, this.zCoord);
}
@MENetworkEventSubscribe
public void powerUpdate(final MENetworkPowerStatusChange changed) {
System.out.println("ALEC");
this.displayPowered = this.getProxy().isPowered();
this.worldObj.func_147451_t(this.xCoord, this.yCoord, this.zCoord);
this.markForUpdate();

View File

@ -0,0 +1,90 @@
package appeng.tile.legacy;
import java.io.IOException;
import java.util.EnumSet;
import appeng.api.networking.GridFlags;
import appeng.api.storage.data.IAEItemStack;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileStorageMonitor extends TileLegacyDisplay {
public boolean isLocked;
public boolean upgraded;
public IAEItemStack myItem;
public boolean updateDisplayList;
public TileStorageMonitor() {
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
this.getProxy().setIdlePowerUsage(0.5);
this.getProxy().setValidSides(EnumSet.allOf(ForgeDirection.class));
}
@Override
public boolean requiresTESR() {
return true;
}
@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStreamTileStorageMonitor(ByteBuf data) {
try {
// TODO: this is a hack because the stupid AE2 reflection BS doesn't work
super.writeToStreamTileLegacyDisplay(data);
int flags = (this.isLocked ? 1 : 0) | (this.upgraded ? 0b10 : 0)
| (this.myItem != null ? 0b100 : 0);
data.writeByte(flags);
if (this.myItem != null)
;
this.myItem.writeToPacket(data);
} catch (IOException kek) {
throw new RuntimeException(kek);
}
}
@TileEvent(TileEventType.NETWORK_READ)
public void readFromStreamTileStorageMonitor(ByteBuf data) {
try {
// TODO: this is a hack because the stupid AE2 reflection BS doesn't work
super.readFromStreamTileLegacyDisplay(data);
byte flags = data.readByte();
this.isLocked = (flags & 0b1) > 0;
this.upgraded = (flags & 0b10) > 0;
// 3rd flag means that there's an item set
if ((flags & 0b100) > 0) {
this.myItem = AEItemStack.loadItemStackFromPacket(data);
}
} catch (IOException kek) {
throw new RuntimeException(kek);
}
this.updateDisplayList = true;
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public void writeNbt(NBTTagCompound nbt) {
nbt.setBoolean("isLocked", this.isLocked);
nbt.setBoolean("upgraded", this.upgraded);
if (this.myItem != null) {
NBTTagCompound item = new NBTTagCompound();
this.myItem.writeToNBT(item);
nbt.setTag("item", item);
}
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readNbt(NBTTagCompound nbt) {
this.isLocked = nbt.getBoolean("isLocked");
this.upgraded = nbt.getBoolean("upgraded");
if (nbt.hasKey("item")) {
this.myItem = AEItemStack.loadItemStackFromNBT(nbt.getCompoundTag("item"));
} else {
this.myItem = null;
}
}
}

View File

@ -57,6 +57,7 @@ tile.appliedenergistics2.BlockCraftTerminal.name=ME Crafting Terminal
tile.appliedenergistics2.BlockCraftMonitor.name=ME Crafting Monitor
tile.appliedenergistics2.BlockLegacyController.name=ME Controller (W.I.P)
tile.appliedenergistics2.BlockWirelessAccessPoint.name=Wireless Access Point
tile.appliedenergistics2.BlockStorageMonitor.name=Storage Monitor
item.appliedenergistics2.ItemMaterial.ConversionMatrix.name=Conversion Matrix

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B