Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,7 +49,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 +145,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);
super.drawAEToolAndUpgradeSlots(alpha, mouseX, mouseY);
}

// Bind the AE states texture
Minecraft.getMinecraft().renderEngine.bindTexture(AEStateIconsEnum.AE_STATES_TEXTURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -22,7 +23,7 @@
* @author Nividica
*
*/
public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory {
public class ContainerEssentiaCellWorkbench extends ContainerWithNetworkTool {

/**
* Y position for the player inventory
Expand Down Expand Up @@ -86,6 +87,22 @@ public boolean canInteractWith(final EntityPlayer player) {
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.
*/
Expand All @@ -107,6 +124,7 @@ public void onContainerClosed(@Nonnull final EntityPlayer player) {
* 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -117,6 +119,27 @@ protected void addUpgradeSlots(final UpgradeInventory upgradeInventory, final in
}
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ protected Slot addSlotToContainer(@Nonnull final Slot slot) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ 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.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);
}
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,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()) {
Expand Down Expand Up @@ -143,27 +150,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 +356,27 @@ 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;
case STICKY -> hasSticky = true;
default -> {}
}
}
}
}
}
}
}

/**
Expand Down Expand Up @@ -898,4 +946,9 @@ public TYPE getCellType() {
return TYPE.ESSENTIA;
}

@Override
public boolean getSticky() {
return hasSticky;
}

}
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.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;

Expand All @@ -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();

Expand All @@ -46,6 +53,21 @@ public static void setFilterList(final List<Aspect> filterAspects, final EntityP
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() {
Expand All @@ -61,6 +83,10 @@ protected void wrappedExecute() {
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;
}
}

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

Expand All @@ -94,6 +123,10 @@ public void writeData(final ByteBuf stream) {
ThEBasePacket.writeAspect(this.filterAspects.get(index), stream);
}
break;
case Packet_C_AspectSlot.MODE_SLOTS_UPDATE:
// Write each aspect
ThEBasePacket.writeItemstack(this.slotStack, stream);
break;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.