Merge pull request #5 from D-Cysteine/add-view-cell

Add view cell support
This commit is contained in:
Martin Robertz authored and GitHub committed 2021-08-07 20:44:10 +02:00
commit db504c19bf
6 files changed
+233 -14

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
aeversion=rv3
wctchannel=
wctbuild=1.8.7.8-GTNH
wctbuild=1.8.7.9-GTNH
wctgroup=net.p455w0rd.wirelesscraftingterminal
wctbasename=WirelessCraftingTerminal
@@ -94,7 +94,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo
private float xSize_lo;
private float ySize_lo;
public static int tick = 0, GUI_HEIGHT = 240, GUI_WIDTH = 198, AE_ROW_HEIGHT = 18, AE_NUM_ROWS = 0,
public static int tick = 0, GUI_HEIGHT = 240, GUI_WIDTH = 230, AE_ROW_HEIGHT = 18, AE_NUM_ROWS = 0,
GUI_UPPER_HEIGHT = 35, GUI_SEARCH_ROW = 35, SEARCH_X = 81, SEARCH_Y = 5, SEARCH_WIDTH = 88,
SEARCH_HEIGHT = 12, SEARCH_MAXCHARS = 15, GUI_LOWER_HEIGHT, AE_TOTAL_ROWS_HEIGHT,
BUTTON_SEARCH_MODE_POS_X = -18, BUTTON_SEARCH_MODE_POS_Y = 68, BUTTON_SIZE = 16, NEI_EXTRA_SPACE = 30,
@@ -102,7 +102,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo
protected static final int BUTTON_SEARCH_MODE_ID = 5;
protected static final long TOOLTIP_UPDATE_INTERVAL = 3000L;
private int currScreenWidth, currScreenHeight;
private static final String bgTexturePath = "gui/crafting.png";
private static final String bgTexturePath = "gui/crafting_viewcell.png";
private final ContainerWirelessCraftingTerminal containerWCT;
private boolean isFullScreen, init = true, reInit, wasResized = false;
public static GuiWirelessCraftingTerminal INSTANCE;
@@ -142,6 +142,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo
private int standardSize;
private final int lowerTextureOffset = 0;
private int rows = 0;
private final ItemStack[] myCurrentViewCells = new ItemStack[5];
public GuiWirelessCraftingTerminal(Container container) {
super(container);
@@ -674,19 +675,36 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo
this.bindTexture(bgTexturePath);
final int x_width = 199;
//draw "over inventory area"
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 );
for( int x = 0; x < this.rows; x++ )
{
this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 );
}
//draw player inv
this.drawTexturedModalRect( offsetX, offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, 0, 106 - 18 - 18, x_width, 99 + this.reservedSpace - this.lowerTextureOffset );
//draw view cells
this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 32, 104);
if (Reference.WCT_BOOSTER_ENABLED) {
this.drawTexturedModalRect(this.guiLeft + 132, (this.guiTop + this.rows * 18) + 83, 237, 237, 19, 19);
}
GuiInventory.func_147046_a(this.guiLeft + 51, (this.guiTop + this.rows * 18) + 94, 32, (float) (this.guiLeft + 51) - this.xSize_lo, (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, this.mc.thePlayer);
boolean update = false;
for (int i = 0; i < 5; i++) {
if (myCurrentViewCells[i] != containerWCT.getCellViewSlot(i).getStack()) {
update = true;
myCurrentViewCells[i] = containerWCT.getCellViewSlot(i).getStack();
}
}
if (update) {
repo.setViewCell(myCurrentViewCells);
}
}
@@ -13,6 +13,7 @@ import java.util.List;
import javax.annotation.Nonnull;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
@@ -96,10 +97,12 @@ import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotMagnet;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerHotBar;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerInv;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotTrash;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotViewCell;
import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryBooster;
import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryCrafting;
import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryMagnet;
import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryTrash;
import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryViewCell;
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
@@ -111,10 +114,12 @@ import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler;
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
public class ContainerWirelessCraftingTerminal extends Container implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack>, IAEAppEngInventory, IContainerCraftingPacket {
public class ContainerWirelessCraftingTerminal extends Container implements IConfigManagerHost, IConfigurableObject,
IMEMonitorHandlerReceiver<IAEItemStack>, IAEAppEngInventory, IContainerCraftingPacket, IViewCellStorage {
private final ItemStack containerstack;
public WCTInventoryCrafting craftingGrid;
public final WCTInventoryCrafting craftingGrid;
public final WCTInventoryViewCell viewCellInventory;
public final WCTInventoryBooster boosterInventory;
public final WCTInventoryMagnet magnetInventory;
public final WCTInventoryTrash trashInventory;
@@ -126,7 +131,8 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
private static final int HOTBAR_START = 1, HOTBAR_END = HOTBAR_START + 8, INV_START = HOTBAR_END + 1,
INV_END = INV_START + 26, ARMOR_START = INV_END + 1, ARMOR_END = ARMOR_START + 3,
CRAFT_GRID_START = ARMOR_END + 1, CRAFT_GRID_END = CRAFT_GRID_START + 8, CRAFT_RESULT = CRAFT_GRID_END + 1,
BOOSTER_INDEX = 0, MAGNET_INDEX = CRAFT_RESULT + 1;
VIEW_CELL_START = CRAFT_RESULT + 1, VIEW_CELL_END = VIEW_CELL_START + 4,
BOOSTER_INDEX = 0, MAGNET_INDEX = VIEW_CELL_END + 1;
public static int CRAFTING_SLOT_X_POS = 80, CRAFTING_SLOT_Y_POS = 83;
private SlotBooster boosterSlot;
private SlotMagnet magnetSlot;
@@ -136,6 +142,7 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
private SlotArmor[] armorSlot;
private SlotCraftingMatrix[] craftMatrixSlot;
private SlotCraftingTerm craftingSlot;
private SlotViewCell[] viewCellSlot;
public SlotTrash trashSlot;
private int firstCraftingSlotNumber = -1, lastCraftingSlotNumber = -1;
@@ -188,6 +195,7 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
this.thisItem = (IWirelessCraftingTerminalItem) this.containerstack.getItem();
this.worldObj = player.worldObj;
this.craftingGrid = new WCTInventoryCrafting(this, 3, 3, containerstack);
this.viewCellInventory = new WCTInventoryViewCell(RandomUtils.getWirelessTerm(inventoryPlayer));
this.inventoryPlayer = inventoryPlayer;
this.player = player;
craftMatrixInventory = new ItemStack[9];
@@ -195,6 +203,7 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
inventorySlot = new Slot[27];
armorSlot = new SlotArmor[4];
craftMatrixSlot = new SlotCraftingMatrix[9];
viewCellSlot = new SlotViewCell[5];
this.obj = getGuiObject(containerstack, player, worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
this.civ = (IPortableCell) this.obj;
@@ -270,6 +279,12 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
// Add crafting result slot
this.addSlotToContainer(craftingSlot);
// Add view cell slots
for (int i = 0; i < 5; i++) {
viewCellSlot[i] = new SlotViewCell(getViewCellStorage(), i, 207, (i * 18) + 8);
addSlotToContainer(viewCellSlot[i]);
}
magnetSlot = new SlotMagnet(this.magnetInventory, 152, -20);
this.addSlotToContainer(magnetSlot);
@@ -695,9 +710,24 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
return null;
}
@Override
public IInventory getViewCellStorage() {
return viewCellInventory;
}
@Override
public ItemStack[] getViewCells() {
return null;
final ItemStack[] list = new ItemStack[viewCellSlot.length];
for (int x = 0; x < viewCellSlot.length; x++) {
list[x] = viewCellSlot[x].getStack();
}
return list;
}
public SlotViewCell getCellViewSlot(final int index) {
return viewCellSlot[index];
}
private WirelessTerminalGuiObject getGuiObject(final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) {
@@ -1289,6 +1319,9 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
case "crafting":
((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound());
break;
case "viewCell":
((WCTInventoryViewCell) viewCellInventory).writeNBT(this.containerstack.getTagCompound());
break;
case "magnet":
((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound());
break;
@@ -1299,6 +1332,7 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
default:
((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound());
((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound());
((WCTInventoryViewCell) viewCellInventory).writeNBT(this.containerstack.getTagCompound());
((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound());
((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound());
break;
@@ -1312,7 +1346,7 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
if (tis == null) {
return null;
}
// Try to place armor in armor slot/booster in booster lost first
// Try to place armor in armor slot/booster in booster slot first
if (isInInventory(idx) || isInHotbar(idx)) {
if (tis.getItem() instanceof ItemArmor) {
int type = ((ItemArmor) tis.getItem()).armorType;
@@ -1327,12 +1361,21 @@ public class ContainerWirelessCraftingTerminal extends Container implements ICon
return null;
}
}
else {
if (tis.getItem() instanceof ItemMagnet) {
if (this.mergeItemStack(tis, MAGNET_INDEX, MAGNET_INDEX + 1, false)) {
clickSlot.clearStack();
return null;
else if (tis.getItem() instanceof ItemMagnet) {
if (this.mergeItemStack(tis, MAGNET_INDEX, MAGNET_INDEX + 1, false)) {
clickSlot.clearStack();
return null;
}
}
else if (AEApi.instance().definitions().items().viewCell().isSameAs( tis )) {
if (mergeItemStack(tis.copy(), VIEW_CELL_START, VIEW_CELL_END + 1, false)) {
if (tis.stackSize > 1) {
tis.stackSize--;
}
else {
clickSlot.clearStack();
}
return null;
}
}
}
@@ -0,0 +1,21 @@
package net.p455w0rd.wirelesscraftingterminal.common.container.slot;
import appeng.api.AEApi;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class SlotViewCell extends AppEngSlot {
public SlotViewCell(IInventory inv, int index, int xPos, int yPos) {
super(inv, index, xPos, yPos);
}
@Override
public boolean isItemValid(ItemStack is) {
if( is == null || is.getItem() == null) {
return false;
}
return AEApi.instance().definitions().items().viewCell().isSameAs( is );
}
}
@@ -0,0 +1,137 @@
package net.p455w0rd.wirelesscraftingterminal.common.inventory;
import appeng.api.AEApi;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class WCTInventoryViewCell implements IInventory {
private final String name = "ViewCells";
private final ItemStack invItem;
private ItemStack[] inventory;
public WCTInventoryViewCell(ItemStack stack) {
super();
inventory = new ItemStack[5];
invItem = stack;
if (stack != null) {
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
readFromNBT(stack.getTagCompound());
}
}
@Override
public int getSizeInventory() {
return 5;
}
@Override
public ItemStack getStackInSlot(int slot) {
return inventory[slot];
}
@Override
public String getInventoryName() {
return name;
}
@Override
public boolean hasCustomInventoryName() {
return name.length() > 0;
}
@Override
public int getInventoryStackLimit() {
return 1;
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
if (stack.stackSize > amount) {
stack = stack.splitStack(amount);
markDirty();
}
else {
setInventorySlotContents(slot, null);
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (inventory[slot] != null) {
ItemStack itemStack = inventory[slot];
inventory[slot] = null;
return itemStack;
}
else {
return null;
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return true;
}
@Override
public void markDirty() {
writeNBT(invItem.getTagCompound());
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
return (AEApi.instance().definitions().items().viewCell().isSameAs( itemstack ));
}
public void readFromNBT(NBTTagCompound nbtTagCompound) {
NBTTagList tagList = nbtTagCompound.getTagList(this.name, 10);
inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound tagCompound = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = tagCompound.getInteger("Slot");
if (slot >= 0 && slot < inventory.length) {
inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
}
public void writeNBT(NBTTagCompound nbtTagCompound) {
NBTTagList tagList = new NBTTagList();
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
if (inventory[currentIndex] != null) {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setInteger("Slot", currentIndex);
inventory[currentIndex].writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
nbtTagCompound.setTag(this.name, tagList);
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB