Skip to content

Commit

Permalink
aaaaaaaaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
lordIcocain committed Jan 17, 2025
1 parent 36d59b0 commit 0e59a11
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
dependencies {
implementation("com.github.GTNewHorizons:NotEnoughItems:2.7.15-GTNH:dev")
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.1:dev")
implementation("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-518-GTNH:dev")
implementation("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-523-GTNH:dev")
implementation("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev")
implementation("curse.maven:thaumcraft-nei-plugin-225095:2241913") { transitive = false }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

import appeng.parts.automation.UpgradeInventory;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import thaumcraft.api.aspects.Aspect;
Expand Down Expand Up @@ -49,7 +52,7 @@ public void mouseClicked(final Aspect withAspect) {
/**
* Gui size.
*/
private static final int GUI_WIDTH = 176, GUI_HEIGHT = 251;
private static final int GUI_WIDTH = 212, GUI_HEIGHT = 251;

/**
* Title position.
Expand Down Expand Up @@ -145,7 +148,13 @@ protected void drawGuiContainerBackgroundLayer(final float alpha, final int mous
Minecraft.getMinecraft().renderEngine.bindTexture(GuiTextureManager.CELL_WORKBENCH.getTexture());

// Draw the gui texture
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, this.ySize);
if (this.workbench.hasEssentiaCell()) {
this.drawTexturedModalRect(this.guiLeft + 177, this.guiTop, 177, 0, 35, 7 + 5 * 18);
this.drawTexturedModalRect(this.guiLeft + 177, this.guiTop + (7 + 5 * 18), 177, 151, 35, 7);
this.showUpgradeSlots();
super.drawAEToolAndUpgradeSlots(alpha, mouseX, mouseY);
}

// Bind the AE states texture
Minecraft.getMinecraft().renderEngine.bindTexture(AEStateIconsEnum.AE_STATES_TEXTURE);
Expand Down Expand Up @@ -301,4 +310,31 @@ public void updateAspects(final List<Aspect> aspectList) {
this.partitionWidgets[index].setAspect(null);
}
}

public void hideUpgradeSlots() {
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i);
if (slot.inventory instanceof UpgradeInventory) {
slot.xDisplayPosition = 1000;
}
}
}

public void showUpgradeSlots() {
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i);
if (slot.inventory instanceof UpgradeInventory) {
slot.xDisplayPosition = 187;
}
}
}

public void updateSlots(final ItemStack stack, int slot) {
if (stack == null) {
hideUpgradeSlots();
} else {
showUpgradeSlots();
}
((Slot) this.inventorySlots.inventorySlots.get(slot)).putStack(stack);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package thaumicenergistics.common.container;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

Expand All @@ -9,6 +10,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import appeng.items.contents.CellUpgrades;
import appeng.parts.automation.UpgradeInventory;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.common.container.slot.SlotRestrictive;
import thaumicenergistics.common.integration.tc.EssentiaItemContainerHelper;
Expand All @@ -22,7 +25,7 @@
* @author Nividica
*
*/
public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory {
public class ContainerEssentiaCellWorkbench extends ContainerWithNetworkTool {

/**
* Y position for the player inventory
Expand All @@ -48,6 +51,7 @@ public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory
* The cell slot.
*/
private final Slot cellSlot;
private final List<Slot> upgradeSlots = new ArrayList<>();

public ContainerEssentiaCellWorkbench(final EntityPlayer player, final World world, final int x, final int y,
final int z) {
Expand All @@ -64,13 +68,20 @@ public ContainerEssentiaCellWorkbench(final EntityPlayer player, final World wor
ContainerEssentiaCellWorkbench.CELL_SLOT_X,
ContainerEssentiaCellWorkbench.CELL_SLOT_Y);
this.addSlotToContainer(this.cellSlot);

// Bind to the player's inventory
this.bindPlayerInventory(
this.player.inventory,
ContainerEssentiaCellWorkbench.PLAYER_INV_POSITION_Y,
ContainerEssentiaCellWorkbench.HOTBAR_INV_POSITION_Y);

addUpgradeSlots(new CellUpgrades(this.workbench.fakeECell, 5), 5, 1000, 8);
for (Object inventorySlot : this.inventorySlots) {
Slot slot = (Slot) inventorySlot;
if (slot.inventory instanceof UpgradeInventory) {
upgradeSlots.add(slot);
}
}

// Register with the workbench
if (EffectiveSide.isServerSide()) {
this.workbench.registerListener(this);
Expand All @@ -86,6 +97,18 @@ public boolean canInteractWith(final EntityPlayer player) {
return false;
}

public void wipeSlots() {
for (Slot slot : upgradeSlots) {
slot.putStack(null);
Packet_C_AspectSlot.setUpgradeSlots(slot, this.player);
}
}

public void updateUpgradeSlots(ItemStack stack, int index) {
upgradeSlots.get(index).putStack(stack);
Packet_C_AspectSlot.setUpgradeSlots(upgradeSlots.get(index), this.player);
}

/**
* Called when a client has requested the full list.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ public static void init() {
Upgrades.SPEED.registerItem(
ThEApi.instance().blocks().ArcaneAssembler.getStack(),
BlockArcaneAssembler.MAX_SPEED_UPGRADES);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_1k.getStack(), 1);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_4k.getStack(), 1);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_16k.getStack(), 1);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_64k.getStack(), 1);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_256k.getStack(), 1);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_1024k.getStack(), 1);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_4096k.getStack(), 1);
Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_16384k.getStack(), 1);

Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_1k.getStack(), 1);
Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_4k.getStack(), 1);
Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_16k.getStack(), 1);
Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_64k.getStack(), 1);
Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_256k.getStack(), 1);
Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_1024k.getStack(), 1);
Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_4096k.getStack(), 1);
Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_16384k.getStack(), 1);

ThELog.endSection("Integration", startTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;

import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
import appeng.api.config.ViewItems;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.ICellCacheRegistry;
import appeng.api.storage.IMEInventoryHandler;
Expand Down Expand Up @@ -107,6 +110,9 @@ public class HandlerItemEssentiaCell implements IMEInventoryHandler<IAEFluidStac
*/
protected final ArrayList<Aspect> partitionAspects = new ArrayList<Aspect>();

private boolean hasVoidOverflow = false;
private boolean hasDistribution = false;

public HandlerItemEssentiaCell(final ItemStack storageStack, final ISaveProvider saveProvider) {
// Ensure we have a NBT tag
if (!storageStack.hasTagCompound()) {
Expand Down Expand Up @@ -143,27 +149,47 @@ public HandlerItemEssentiaCell(final ItemStack storageStack, final ISaveProvider
* @return Amount not stored
*/
private long addEssentiaToCell(final Aspect aspect, final long amount, final Actionable mode) {
// Calculate amount to store
long amountToStore = Math.min(amount, this.totalEssentiaStorage - this.usedEssentiaStorage);
long amountToStore;
// Get the slot for this aspect
int slotIndex = this.getSlotFor(aspect);
// Get the slot
IAspectStack stackToAddTo = this.storedEssentia[slotIndex];
if (hasDistribution) {
int types;
if (this.isPartitioned()) {
types = this.partitionAspects.size();
} else {
types = this.storedEssentia.length;
}
if (stackToAddTo == null) {
amountToStore = Math.min(amount, this.totalEssentiaStorage / types);
} else {
amountToStore = Math.min(
amount,
(this.totalEssentiaStorage / types) - this.storedEssentia[slotIndex].getStackSize());
}
} else {
amountToStore = Math.min(amount, this.totalEssentiaStorage - this.usedEssentiaStorage);
}

// Ensure we can store any
if (amountToStore == 0) {
if (hasVoidOverflow) {
if (stackToAddTo != null) {
return 0;
}
}
// Cell is full
return amount;
}

// Get the slot for this aspect
int slotIndex = this.getSlotFor(aspect);

// Ensure there is somewhere to put the essentia
if (slotIndex == -1) {
return amount;
}

// Are we modulating?
if (mode == Actionable.MODULATE) {
// Get the slot
IAspectStack stackToAddTo = this.storedEssentia[slotIndex];

// Is the slot null?
if (stackToAddTo == null) {
Expand Down Expand Up @@ -329,6 +355,26 @@ private void readCellData() {
}
}
}

if (this.cellData.hasKey("upgrades")) {
NBTTagCompound upgrades = this.cellData.getCompoundTag("upgrades");
for (int i = 0; i < 5; i++) {
NBTTagCompound upgrade = upgrades.getCompoundTag("#" + i);
if (!Objects.equals(upgrade.toString(), "{}")) {
ItemStack is = ItemStack.loadItemStackFromNBT(upgrade);
if (is != null && is.getItem() instanceof IUpgradeModule) {
final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is);
if (u != null) {
switch (u) {
case VOID_OVERFLOW -> hasVoidOverflow = true;
case DISTRIBUTION -> hasDistribution = true;
default -> {}
}
}
}
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.gui.IAspectSlotGui;
import thaumicenergistics.client.gui.GuiEssentiaCellWorkbench;
import thaumicenergistics.common.network.NetworkHandler;
import thaumicenergistics.common.network.ThEBasePacket;

Expand All @@ -27,6 +30,12 @@ public class Packet_C_AspectSlot extends ThEClientPacket {

private List<Aspect> filterAspects;

private static final byte MODE_SLOTS_UPDATE = 1;

private ItemStack slotStack;

private int slotIndex;

public static void setFilterList(final List<Aspect> filterAspects, final EntityPlayer player) {
Packet_C_AspectSlot packet = new Packet_C_AspectSlot();

Expand All @@ -46,6 +55,23 @@ public static void setFilterList(final List<Aspect> filterAspects, final EntityP
NetworkHandler.sendPacketToClient(packet);
}

public static void setUpgradeSlots(final Slot slot, final EntityPlayer player) {
Packet_C_AspectSlot packet = new Packet_C_AspectSlot();

// Set the player
packet.player = player;

// Set the mode
packet.mode = Packet_C_AspectSlot.MODE_SLOTS_UPDATE;

packet.slotStack = slot.getStack();

packet.slotIndex = slot.slotNumber;

// Send it
NetworkHandler.sendPacketToClient(packet);
}

@SideOnly(Side.CLIENT)
@Override
protected void wrappedExecute() {
Expand All @@ -61,6 +87,9 @@ protected void wrappedExecute() {
case Packet_C_AspectSlot.MODE_LIST_UPDATE:
((IAspectSlotGui) gui).updateAspects(this.filterAspects);
break;
case Packet_C_AspectSlot.MODE_SLOTS_UPDATE:
((GuiEssentiaCellWorkbench) gui).updateSlots(this.slotStack, this.slotIndex);
break;
}
}

Expand All @@ -79,6 +108,10 @@ public void readData(final ByteBuf stream) {
this.filterAspects.add(ThEBasePacket.readAspect(stream));
}
break;
case Packet_C_AspectSlot.MODE_SLOTS_UPDATE:
this.slotIndex = stream.readInt();
this.slotStack = ThEBasePacket.readItemstack(stream);
break;
}
}

Expand All @@ -94,6 +127,13 @@ public void writeData(final ByteBuf stream) {
ThEBasePacket.writeAspect(this.filterAspects.get(index), stream);
}
break;
case Packet_C_AspectSlot.MODE_SLOTS_UPDATE:
// Write the size of the list
stream.writeInt(this.slotIndex);

// Write each aspect
ThEBasePacket.writeItemstack(this.slotStack, stream);
break;
}
}
}
Loading

0 comments on commit 0e59a11

Please sign in to comment.