Fix JABBA-related issues with crafting station slots (#54)

* Fix shift-merging tools voiding items

fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11392>

* Change 0-sized ItemStacks into null stacks in crafting station attached slots

Fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/10425>

* Update buildscript

* spotlessApply
This commit is contained in:
Raven Szewczyk authored and GitHub committed 2022-09-22 20:51:23 +02:00
1 parent 18bfeaff32
commit 39be06c23b
571 files changed
+25959 -28223

No files matched your search

@@ -4,6 +4,9 @@ import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import cpw.mods.fml.common.Optional;
import java.awt.Rectangle;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -22,17 +25,13 @@ import tconstruct.library.tools.ToolMaterial;
import tconstruct.library.util.HarvestLevels;
import tconstruct.tools.logic.CraftingStationLogic;
import java.awt.Rectangle;
import java.util.Collections;
import java.util.List;
@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
/*
* Slider/slots related. Taken & adapted from Tinkers Construct 1.12 under the MIT License
*/
private static final ResourceLocation gui_inventory = new ResourceLocation("tinker", "textures/gui/generic.png");
public static final GuiElementScalable slotElement = new GuiElementScalable(7, 7, 18, 18, 64, 64);
public static final GuiElementScalable slotEmptyElement = new GuiElementScalable(7 + 18, 7, 18, 18, 64, 64);
@@ -44,7 +43,8 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
private static final GuiElementScalable sliderBackground = new GuiElementScalable(43, 8, 12, 30, 64, 64);
private static final GuiElementScalable textBackground = new GuiElementScalable(7 + 18, 7, 18, 10, 64, 64);
private final GuiSliderWidget slider = new GuiSliderWidget(sliderNormal, sliderHigh, sliderLow, sliderTop, sliderBottom, sliderBackground);
private final GuiSliderWidget slider =
new GuiSliderWidget(sliderNormal, sliderHigh, sliderLow, sliderTop, sliderBottom, sliderBackground);
private final GuiBorderWidget border = new GuiBorderWidget();
private int firstSlotId;
@@ -52,7 +52,7 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
private int chestSlotCount;
/* end slider/slots */
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/tinkertable.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
@@ -64,19 +64,19 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
public GuiTextField text;
public String title, body = "";
CraftingStationLogic logic;
private int craftingLeft = 0;
private int craftingTop = 0;
private int craftingTextLeft = 0;
private int descLeft = 0;
private int descTop = 0;
private int descTextLeft = 0;
private int chestLeft = 0;
private int chestTop = 0;
private int chestWidth = 0;
private int chestHeight = 0;
public CraftingStationGui(InventoryPlayer inventory, CraftingStationLogic logic, World world, int x, int y, int z) {
super(logic.getGuiContainer(inventory, world, x, y, z));
this.logic = logic;
@@ -119,43 +119,52 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
if (logic.chest != null) {
if (logic.chest.get() instanceof TileEntity) {
TileEntity te = (TileEntity) logic.chest.get();
if (te == null || te.getWorldObj().getTileEntity(te.xCoord, te.yCoord, te.zCoord) == null && te.getWorldObj().isRemote) {
if (te == null
|| te.getWorldObj().getTileEntity(te.xCoord, te.yCoord, te.zCoord) == null
&& te.getWorldObj().isRemote) {
mc.thePlayer.closeScreen();
return;
}
}
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.chest.get().getInventoryName()), 8, 6, 0x202020);
this.fontRendererObj.drawString(
StatCollector.translateToLocal(logic.chest.get().getInventoryName()), 8, 6, 0x202020);
}
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.tinkerTable ? "crafters.TinkerTable" : logic.getInvName()), craftingTextLeft + 8, 6, 0x202020);
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), craftingTextLeft + 8, 72, 0x202020);
this.fontRendererObj.drawString(
StatCollector.translateToLocal(logic.tinkerTable ? "crafters.TinkerTable" : logic.getInvName()),
craftingTextLeft + 8,
6,
0x202020);
this.fontRendererObj.drawString(
StatCollector.translateToLocal("container.inventory"), craftingTextLeft + 8, 72, 0x202020);
if (logic.tinkerTable) {
if (logic.isStackInSlot(0)) // output slot = modified item
drawToolStats(logic.getStackInSlot(0));
drawToolStats(logic.getStackInSlot(0));
else if (logic.isStackInSlot(5)) { // center slot if no output item
// other slots empty?
if (!logic.isStackInSlot(1) && !logic.isStackInSlot(2) && !logic.isStackInSlot(3) && !logic.isStackInSlot(4)
&& !logic.isStackInSlot(6) && !logic.isStackInSlot(7) && !logic.isStackInSlot(8) && !logic.isStackInSlot(9))
drawToolStats(logic.getStackInSlot(5));
else
drawToolInformation();
} else
drawToolInformation();
if (!logic.isStackInSlot(1)
&& !logic.isStackInSlot(2)
&& !logic.isStackInSlot(3)
&& !logic.isStackInSlot(4)
&& !logic.isStackInSlot(6)
&& !logic.isStackInSlot(7)
&& !logic.isStackInSlot(8)
&& !logic.isStackInSlot(9)) drawToolStats(logic.getStackInSlot(5));
else drawToolInformation();
} else drawToolInformation();
}
}
void drawToolStats(ItemStack stack) {
if (stack.getItem() instanceof IModifyable)
ToolStationGuiHelper.drawToolStats(stack, descTextLeft + 10, 0);
if (stack.getItem() instanceof IModifyable) ToolStationGuiHelper.drawToolStats(stack, descTextLeft + 10, 0);
int matID = PatternBuilder.instance.getPartID(stack);
if (matID != Short.MAX_VALUE && matID > 0) {
ToolMaterial material = TConstructRegistry.getMaterial(matID);
if (material != null)
drawMaterialStats(material);
if (material != null) drawMaterialStats(material);
}
}
@@ -174,17 +183,44 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
drawCenteredString(this.fontRendererObj, centerTitle, baseX + 55, baseY, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter4") + materialEnum.durability(), baseX, baseY + 16, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter5") + materialEnum.handleDurability() + "x", baseX, baseY + 27, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter6") + materialEnum.toolSpeed() / 100f, baseX, baseY + 38, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter7") + HarvestLevels.getHarvestLevelName(materialEnum.harvestLevel()), baseX, baseY + 49, 16777215);
this.fontRendererObj.drawString(
StatCollector.translateToLocal("gui.partcrafter4") + materialEnum.durability(),
baseX,
baseY + 16,
16777215);
this.fontRendererObj.drawString(
StatCollector.translateToLocal("gui.partcrafter5") + materialEnum.handleDurability() + "x",
baseX,
baseY + 27,
16777215);
this.fontRendererObj.drawString(
StatCollector.translateToLocal("gui.partcrafter6") + materialEnum.toolSpeed() / 100f,
baseX,
baseY + 38,
16777215);
this.fontRendererObj.drawString(
StatCollector.translateToLocal("gui.partcrafter7")
+ HarvestLevels.getHarvestLevelName(materialEnum.harvestLevel()),
baseX,
baseY + 49,
16777215);
int attack = materialEnum.attack();
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
String heart = attack == 2
? StatCollector.translateToLocal("gui.partcrafter8")
: StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2 + heart, baseX, baseY + 60, 0xffffff);
this.fontRendererObj.drawString(
StatCollector.translateToLocal("gui.partcrafter10") + attack / 2 + heart,
baseX,
baseY + 60,
0xffffff);
else
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart, baseX, baseY + 60, 0xffffff);
this.fontRendererObj.drawString(
StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart,
baseX,
baseY + 60,
0xffffff);
}
@Override
@@ -207,9 +243,8 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(gui_inventory);
if(hasChest()) {
if (hasChest()) {
chestLeft += border.w;
chestTop += border.h;
@@ -243,7 +278,6 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
this.mc.getTextureManager().bindTexture(description);
this.drawTexturedModalRect(this.descLeft, this.descTop, 0, 0, 126, 172);
}
}
@Override
@@ -275,19 +309,19 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
final int cw = (logic.chest != null ? chestWidth : 0);
if(logic.chest != null) {
if (logic.chest != null) {
final Rectangle blah = new Rectangle(x, y, w, h);
final Rectangle chestRectangle = new Rectangle(
chestLeft, chestTop, chestWidth, chestHeight + (shouldDrawName() ? textBackground.y : 0) + (border.h * 2)
);
if(chestRectangle.intersects(blah))
return true;
chestLeft,
chestTop,
chestWidth,
chestHeight + (shouldDrawName() ? textBackground.y : 0) + (border.h * 2));
if (chestRectangle.intersects(blah)) return true;
}
if (y + h - 4 < guiTop || y + 4 > guiTop + ySize)
return false;
if (y + h - 4 < guiTop || y + 4 > guiTop + ySize) return false;
return x - w - 4 >= guiLeft + cw && x + 4 <= guiLeft + xSize + cw + (logic.tinkerTable ? 126 : 0);
}
@@ -298,14 +332,16 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
public boolean isMouseInChest(int mouseX, int mouseY) {
final int xMod = (slider.isEnabled() ? slider.width : 0) + border.w;
final int yMod = (shouldDrawName() ? textBackground.y : 0) + (border.h * 2);
return mouseX >= (this.chestLeft - xMod) && mouseX < (chestLeft + chestWidth + xMod) &&
mouseY >= (this.chestTop - yMod) && mouseY < (chestTop + chestHeight + yMod);
return mouseX >= (this.chestLeft - xMod)
&& mouseX < (chestLeft + chestWidth + xMod)
&& mouseY >= (this.chestTop - yMod)
&& mouseY < (chestTop + chestHeight + yMod);
}
public boolean isMouseOverFullSlot(int mouseX, int mouseY) {
for(final Object slot : inventorySlots.inventorySlots) {
if(isMouseOverSlot((Slot)slot, mouseX, mouseY) && ((Slot)slot).getHasStack()) {
for (final Object slot : inventorySlots.inventorySlots) {
if (isMouseOverSlot((Slot) slot, mouseX, mouseY) && ((Slot) slot).getHasStack()) {
return true;
}
}
@@ -313,22 +349,24 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
}
protected boolean shouldDrawName() {
return this.logic.chest != null && this.logic.chest.get().getInventoryName() != null && !this.logic.chest.get().getInventoryName().isEmpty();
return this.logic.chest != null
&& this.logic.chest.get().getInventoryName() != null
&& !this.logic.chest.get().getInventoryName().isEmpty();
}
@Override
public void func_146977_a/*drawSlot*/(Slot slot) {
if(!slot.func_111238_b/*isEnabled*/()) return;
public void func_146977_a /*drawSlot*/(Slot slot) {
if (!slot.func_111238_b /*isEnabled*/()) return;
super.func_146977_a(slot);
}
public boolean shouldDrawSlot(Slot slot) {
if(!(slot instanceof ChestSlot)) return true;
if (!(slot instanceof ChestSlot)) return true;
ChestSlot chestSlot = (ChestSlot) slot;
// all visible
if(!slider.isEnabled()) return true;
if (!slider.isEnabled()) return true;
return firstSlotId <= chestSlot.getVisualIndex() && lastSlotId > chestSlot.getVisualIndex();
}
@@ -337,7 +375,7 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
public boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) {
return super.isMouseOverSlot(slotIn, mouseX, mouseY) && shouldDrawSlot(slotIn);
}
private int getDisplayedRows() {
return chestHeight / slotElement.h;
}
@@ -346,7 +384,7 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
int h = slotElement.h * logic.invRows;
// not higher than the max
while(h > max) {
while (h > max) {
h -= slotElement.h;
}
return h;
@@ -362,28 +400,32 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
chestSlotCount = logic.slotCount;
// slider needed?
if(getDisplayedRows() < logic.invRows) {
if (getDisplayedRows() < logic.invRows) {
slider.enable();
}
else {
} else {
slider.disable();
}
chestWidth = logic.invColumns * CraftingStationGui.slotElement.w + 2 * border.w + (slider.isEnabled() ? slider.width : 0);
chestWidth = logic.invColumns * CraftingStationGui.slotElement.w
+ 2 * border.w
+ (slider.isEnabled() ? slider.width : 0);
chestLeft = guiLeft - chestWidth;
chestTop = guiTop;
// Leaving out the xSize increase by chestSize and adjusting where it's used, because otherwise it shifts both the bookmarks and item panel
// Leaving out the xSize increase by chestSize and adjusting where it's used, because otherwise it shifts both
// the bookmarks and item panel
// way too far out. If anything (mouseClick, for example) relies on xSize, you'll need to hack it like below.
// xSize += guiLeft - chestLeft;
// xSize += guiLeft - chestLeft;
guiLeft = chestLeft;
border.setPosition(chestLeft, chestTop);
border.setSize(chestWidth, chestHeight + (shouldDrawName() ? textBackground.h : 0) + 2 * border.h);
slider.show();
slider.setPosition(chestLeft + logic.invColumns * slotElement.w + border.w, chestTop + (shouldDrawName() ? textBackground.h : 0) + border.h);
slider.setPosition(
chestLeft + logic.invColumns * slotElement.w + border.w,
chestTop + (shouldDrawName() ? textBackground.h : 0) + border.h);
slider.setSize(chestHeight);
slider.setSliderParameters(0, logic.invRows - getDisplayedRows(), 1);
@@ -393,7 +435,7 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
@Override
protected void mouseClicked(int x, int y, int button) {
// Hacks
final int height = ySize;
final int height = ySize;
if (logic.chest != null && x >= guiLeft && x <= guiLeft + chestWidth) {
ySize = border.height;
@@ -404,11 +446,11 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
xSize -= chestWidth;
ySize = height;
}
@Override
protected void mouseMovedOrUp(int x, int y, int button) {
// Hacks
final int height = ySize;
final int height = ySize;
if (logic.chest != null && x >= guiLeft && x <= guiLeft + chestWidth) {
ySize = border.height;
@@ -419,29 +461,29 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
xSize -= chestWidth;
ySize = height;
}
// updates slot visibility
protected void updateChestSlots() {
if(!hasChest()) return;
if (!hasChest()) return;
final IInventory secondInventory = logic.getSecondInventory();
int xOffset = border.w;
int yOffset = border.h;
if(shouldDrawName()) {
if (shouldDrawName()) {
yOffset += textBackground.h;
}
firstSlotId = slider.getValue() * logic.invColumns;
lastSlotId = Math.min(chestSlotCount, firstSlotId + getDisplayedRows() * logic.invColumns);
for(Object o : inventorySlots.inventorySlots) {
if(!(o instanceof ChestSlot)) continue;
final ChestSlot slot = (ChestSlot)o;
if(shouldDrawSlot(slot)) {
for (Object o : inventorySlots.inventorySlots) {
if (!(o instanceof ChestSlot)) continue;
final ChestSlot slot = (ChestSlot) o;
if (shouldDrawSlot(slot)) {
slot.enable();
// calc position of the slot
final int offset = slot.getVisualIndex() - firstSlotId;
@@ -450,39 +492,36 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
slot.xDisplayPosition = x + xOffset + 1 /*- this.chestWidth*/;
slot.yDisplayPosition = y + yOffset + 1;
}
else {
} else {
slot.disable();
slot.xDisplayPosition = 0;
slot.yDisplayPosition = 0;
}
}
}
// drawSlots
protected void drawChestSlots(int xPos, int yPos) {
if(!hasChest()) return;
if (!hasChest()) return;
int width = logic.invColumns * slotElement.w;
int height = chestHeight - border.h * 2;
int fullRows = (lastSlotId - firstSlotId) / logic.invColumns;
int slotsLeft = (lastSlotId - firstSlotId) % logic.invColumns;
int y; // We use it after the loop
for(y = 0; y < fullRows * slotElement.h && y < height; y += slotElement.h) {
for (y = 0; y < fullRows * slotElement.h && y < height; y += slotElement.h) {
slotElement.drawScaledX(xPos, yPos + y, width);
}
// draw partial row and unused slots
if(slotsLeft > 0) {
if (slotsLeft > 0) {
slotElement.drawScaledX(xPos, yPos + y, slotsLeft * slotElement.w);
// empty slots that don't exist
slotEmptyElement.drawScaledX(xPos + slotsLeft * slotElement.w, yPos + y, width - slotsLeft * slotElement.w);
}
}
/*
* Hide the deprecated stuff at the bottom