Void overflow and Distribution and Sticky card support for essentia cells (#82)

This commit is contained in:
lordIcocain authored and GitHub committed 2025-01-18 10:51:37 -06:00
1 parent 36d59b0b72
commit 57653e331a
9 files changed
+177 -11

No files matched your search

+1 -1
View File
@@ -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 }
@@ -49,7 +49,7 @@ public class GuiEssentiaCellWorkbench extends ThEBaseGui implements IAspectSlotG
/**
* Gui size.
*/
private static final int GUI_WIDTH = 176, GUI_HEIGHT = 251;
private static final int GUI_WIDTH = 212, GUI_HEIGHT = 251;
/**
* Title position.
@@ -145,7 +145,13 @@ public class GuiEssentiaCellWorkbench extends ThEBaseGui implements IAspectSlotG
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);
super.drawAEToolAndUpgradeSlots(alpha, mouseX, mouseY);
}
// Bind the AE states texture
Minecraft.getMinecraft().renderEngine.bindTexture(AEStateIconsEnum.AE_STATES_TEXTURE);
@@ -9,6 +9,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.items.contents.CellUpgrades;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.common.container.slot.SlotRestrictive;
import thaumicenergistics.common.integration.tc.EssentiaItemContainerHelper;
@@ -22,7 +23,7 @@ import thaumicenergistics.common.utils.EffectiveSide;
* @author Nividica
*
*/
public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory {
public class ContainerEssentiaCellWorkbench extends ContainerWithNetworkTool {
/**
* Y position for the player inventory
@@ -86,6 +87,22 @@ public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory
return false;
}
public void createUpgradeSlots(ItemStack stack) {
if (stack != null) {
if (haveUpgradeSlots()) {
removeUpgradeSlots();
}
addUpgradeSlots(new CellUpgrades(stack, 5), 5, 187, 8);
} else {
if (haveUpgradeSlots()) {
removeUpgradeSlots();
}
}
if (EffectiveSide.isServerSide()) {
Packet_C_AspectSlot.setUpgradeSlots(stack, this.player);
}
}
/**
* Called when a client has requested the full list.
*/
@@ -107,6 +124,7 @@ public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory
* Called when the partition list changes.
*/
public void onPartitionChanged(final ArrayList<Aspect> partitionList) {
createUpgradeSlots(this.workbench.getStackInSlot(0));
// Send to client
Packet_C_AspectSlot.setFilterList(partitionList, this.player);
}
@@ -1,5 +1,7 @@
package thaumicenergistics.common.container;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
@@ -117,6 +119,27 @@ public abstract class ContainerWithNetworkTool extends ContainerWithPlayerInvent
}
}
protected void removeUpgradeSlots() {
ArrayList<Object> slots = new ArrayList<>();
for (int slotIndex = this.firstUpgradeSlot; slotIndex <= this.lastUpgradeSlot; slotIndex++) {
slots.add(this.inventorySlots.get(slotIndex));
removeSlot(slotIndex);
}
for (Object slot : slots) {
this.inventorySlots.remove(slot);
}
}
protected boolean haveUpgradeSlots() {
for (Object inventorySlot : this.inventorySlots) {
Slot slot = (Slot) inventorySlot;
if (slot.inventory instanceof UpgradeInventory) {
return true;
}
}
return false;
}
protected void bindToNetworkTool(final InventoryPlayer playerInventory, final DimensionalCoord partLocation,
final int slotOffsetX, final int slotOffsetY) {
// Get the networkTool or null if absent (e.g. disabled in AE's config-file)
@@ -61,6 +61,10 @@ public abstract class TheContainerBase extends Container {
return slot;
}
protected void removeSlot(int slotIndex) {
this.slotMap.remove(slotIndex);
}
/**
* Detects server side changes to send to the player.<br/>
* When modifying slots, return true to set {@code playerMP.isChangingQuantityOnly} to {@code false}, or set it
@@ -58,6 +58,35 @@ public final class IntegrationCore {
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.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_Quantum.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);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_1k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_4k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_16k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_64k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_256k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_1024k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_4096k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_16384k.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_Quantum.getStack(), 1);
Upgrades.STICKY.registerItem(ThEApi.instance().items().EssentiaCell_Singularity.getStack(), 1);
ThELog.endSection("Integration", startTime);
}
@@ -2,6 +2,7 @@ package thaumicenergistics.common.inventory;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -9,7 +10,9 @@ 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;
@@ -107,6 +110,10 @@ public class HandlerItemEssentiaCell implements IMEInventoryHandler<IAEFluidStac
*/
protected final ArrayList<Aspect> partitionAspects = new ArrayList<Aspect>();
private boolean hasVoidOverflow = false;
private boolean hasDistribution = false;
private boolean hasSticky = false;
public HandlerItemEssentiaCell(final ItemStack storageStack, final ISaveProvider saveProvider) {
// Ensure we have a NBT tag
if (!storageStack.hasTagCompound()) {
@@ -143,18 +150,40 @@ public class HandlerItemEssentiaCell implements IMEInventoryHandler<IAEFluidStac
* @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;
@@ -162,8 +191,6 @@ public class HandlerItemEssentiaCell implements IMEInventoryHandler<IAEFluidStac
// Are we modulating?
if (mode == Actionable.MODULATE) {
// Get the slot
IAspectStack stackToAddTo = this.storedEssentia[slotIndex];
// Is the slot null?
if (stackToAddTo == null) {
@@ -329,6 +356,27 @@ public class HandlerItemEssentiaCell implements IMEInventoryHandler<IAEFluidStac
}
}
}
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;
case STICKY -> hasSticky = true;
default -> {}
}
}
}
}
}
}
}
/**
@@ -898,4 +946,9 @@ public class HandlerItemEssentiaCell implements IMEInventoryHandler<IAEFluidStac
return TYPE.ESSENTIA;
}
@Override
public boolean getSticky() {
return hasSticky;
}
}
@@ -6,12 +6,15 @@ import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.player.EntityPlayer;
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.container.ContainerEssentiaCellWorkbench;
import thaumicenergistics.common.network.NetworkHandler;
import thaumicenergistics.common.network.ThEBasePacket;
@@ -27,6 +30,10 @@ public class Packet_C_AspectSlot extends ThEClientPacket {
private List<Aspect> filterAspects;
private static final byte MODE_SLOTS_UPDATE = 1;
private ItemStack slotStack;
public static void setFilterList(final List<Aspect> filterAspects, final EntityPlayer player) {
Packet_C_AspectSlot packet = new Packet_C_AspectSlot();
@@ -46,6 +53,21 @@ public class Packet_C_AspectSlot extends ThEClientPacket {
NetworkHandler.sendPacketToClient(packet);
}
public static void setUpgradeSlots(final ItemStack stack, 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 = stack;
// Send it
NetworkHandler.sendPacketToClient(packet);
}
@SideOnly(Side.CLIENT)
@Override
protected void wrappedExecute() {
@@ -61,6 +83,10 @@ public class Packet_C_AspectSlot extends ThEClientPacket {
case Packet_C_AspectSlot.MODE_LIST_UPDATE:
((IAspectSlotGui) gui).updateAspects(this.filterAspects);
break;
case Packet_C_AspectSlot.MODE_SLOTS_UPDATE:
((ContainerEssentiaCellWorkbench) ((GuiEssentiaCellWorkbench) gui).inventorySlots)
.createUpgradeSlots(this.slotStack);
break;
}
}
@@ -79,6 +105,9 @@ public class Packet_C_AspectSlot extends ThEClientPacket {
this.filterAspects.add(ThEBasePacket.readAspect(stream));
}
break;
case Packet_C_AspectSlot.MODE_SLOTS_UPDATE:
this.slotStack = ThEBasePacket.readItemstack(stream);
break;
}
}
@@ -94,6 +123,10 @@ public class Packet_C_AspectSlot extends ThEClientPacket {
ThEBasePacket.writeAspect(this.filterAspects.get(index), stream);
}
break;
case Packet_C_AspectSlot.MODE_SLOTS_UPDATE:
// Write each aspect
ThEBasePacket.writeItemstack(this.slotStack, stream);
break;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB