improve cheat gui, fix particle bug

This commit is contained in:
Sen 2025-07-01 00:20:02 +02:00
parent 8a9e9451b7
commit 30e6b4eb74
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
7 changed files with 147 additions and 134 deletions

View file

@ -1,5 +1,6 @@
package client.gui.container;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -8,7 +9,11 @@ import org.lwjgl.opengl.GL13;
import client.gui.Font;
import client.gui.Gui;
import client.gui.element.Element;
import client.gui.element.Field;
import client.gui.element.InventoryButton;
import client.gui.element.Label;
import client.gui.element.MultiLabel;
import client.renderer.Drawing;
import client.renderer.GlState;
import client.renderer.ItemRenderer;
@ -43,7 +48,7 @@ public abstract class GuiContainer extends Gui
private static final List<ItemStack> ITEM_LIST = Lists.<ItemStack>newArrayList();
private static CheatTab selectedTab = CheatTab.BLOCKS;
private static CheatTab selectedTab = CheatTab.ALL;
protected RenderItem itemRender;
protected int xSize = 176;
@ -76,8 +81,14 @@ public abstract class GuiContainer extends Gui
private boolean isScrolling;
private boolean wasClicking;
private ItemStack cheatStack;
private int cheatX;
private int cheatY;
private int cheatWidth;
private int cheatHeight;
private Label cheatLabel;
private MultiLabel cheatDesc;
private Field cheatSearch;
private String cheatLast;
public void drawString(String text, int x, int y) {
x = x * 2 + this.container_x;
@ -100,37 +111,21 @@ public abstract class GuiContainer extends Gui
public InventoryButton button(int x, int y, int w, int h) {
return this.add(new InventoryButton(this.container_x + x * 2, this.container_y + y * 2, w * 2, h * 2));
}
// public void uidims(int w, int h) {
// }
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
super.mouse(btn, x, y, ctrl, shift);
// public void click(Button btn, int x, int y) {
// if(this.openGui != null) {
// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x;
// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1;
this.mouseClicked((x - this.container_x) / 2, (y - this.container_y) / 2, btn.ordinal()); //TODO: enum
// }
}
public void mouserel(Button btn, int x, int y) {
super.mouserel(btn, x, y);
// if(this.openGui != null) {
// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x;
// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1;
this.mouseReleased((x - this.container_x) / 2, (y - this.container_y) / 2, btn.ordinal()); //TODO: enum
// }
}
public void drag(int x, int y) {
super.drag(x, y);
// if(this.openGui != null) {
// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x;
// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1;
if(Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown() || Button.MOUSE_MIDDLE.isDown())
this.mouseDragged((x - this.container_x) / 2, (y - this.container_y) / 2);
// }
}
public GuiContainer(Container inventorySlotsIn)
@ -143,10 +138,6 @@ public abstract class GuiContainer extends Gui
this.itemRender = this.gm.getRenderItem();
this.tooltip = null;
this.cheatStack = null;
// this.width = width;
// this.height = height;
// this.initialize(this.gm.getGame());
// this.container_x = this.container_y = this.container_w = this.container_h = 0;
this.container_x = (width - (this.container_w = (this.xSize * 2))) / 2;
this.container_y = (height - (this.container_h = (this.ySize * 2))) / 2;
this.initGui();
@ -163,38 +154,18 @@ public abstract class GuiContainer extends Gui
return "Inventar";
}
// public int getXSize() {
// return this.xSize;
// }
//
// public int getYSize() {
// return this.ySize;
// }
// public final void initialize(Game gm) {
// }
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.gm.player.openContainer = this.inventorySlots;
// this.guiLeft = (this.width - this.xSize) / 2;
// this.guiTop = (this.height - this.ySize) / 2;
// this.addButtons();
if(this.gm.itemCheat) {
this.cheatWidth = Math.max((this.gm.fb_x - this.container_x - this.container_w - 32) / 2 / 18, 1);
this.cheatHeight = Math.max((this.gm.fb_y - this.container_y - 20 * 2 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) - 64) / 2 / 18, 1);
// CheatTab i = selectedTab;
// selectedTab = null;
this.setCurrentTab(selectedTab);
this.cheatX = this.container_x + this.container_w + 4;
this.cheatY = 20;
this.cheatWidth = Math.max((this.gm.fb_x - this.container_x - this.container_w - 32) / 18, 1);
this.cheatHeight = Math.max((this.gm.fb_y - 20 * 2 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) - 64) / 18, 1);
}
}
public void addButtons() {
// this.uidims(this.xSize, this.ySize);
if(this.inventorySlots != null) {
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) {
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
@ -202,15 +173,14 @@ public abstract class GuiContainer extends Gui
}
}
if(this.gm.itemCheat) {
for (int k = 0; k < this.cheatHeight; ++k)
{
for (int l = 0; l < this.cheatWidth; ++l) {
this.button(this.xSize + 2 + 18 * l, k * 18, 18, 18);
}
}
this.cheatLabel = this.add(new Label(this.cheatX, this.cheatY, this.cheatWidth * 18, "", true));
this.cheatDesc = this.add(new MultiLabel(this.cheatX, this.cheatY + this.cheatHeight * 18, this.cheatWidth * 18, 60, "Vorsicht: Schummeln wird mit Keule bestraft\n(Halte Strg beim Klick für vollen Stapel)"));
this.cheatSearch = this.add(new Field(this.cheatX, this.gm.fb_y - Element.BASE_HEIGHT - 32, this.cheatWidth * 18, 0, 128, null, ""));
this.cheatLast = "";
for(CheatTab tab : CheatTab.values()) {
this.button(this.xSize + 2 + 18 * (tab.getIndex() % this.cheatWidth), this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth), 18, 18);
this.add(new InventoryButton(this.cheatX + 18 * (tab.getIndex() % this.cheatWidth), this.cheatY + this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth), 18, 18));
}
this.setCurrentTab(selectedTab);
}
}
@ -227,6 +197,9 @@ public abstract class GuiContainer extends Gui
}
if(this.gm.itemCheat) {
GL11.glPushMatrix();
GL11.glTranslatef(-(float)((this.gm.fb_x - this.xSize * 2) / 2) * 0.5f, -(float)((this.gm.fb_y - this.ySize * 2) / 2) * 0.5f, 0.0f);
GL11.glScalef(0.5f, 0.5f, 0.5f);
int i = (ITEM_LIST.size() + this.cheatWidth - 1) / this.cheatWidth - this.cheatHeight;
int j = (int)((double)(this.currentScroll * (float)i) + 0.5D);
@ -245,9 +218,9 @@ public abstract class GuiContainer extends Gui
this.itemRender.zLevel = 100.0F;
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(ITEM_LIST.get(i1), this.xSize + 2 + 18 * l + 1, k * 18 + 1);
this.itemRender.renderItemAndEffectIntoGUI(ITEM_LIST.get(i1), this.cheatX + 18 * l + 1, this.cheatY + k * 18 + 1);
this.itemRender.zLevel = 0.0F;
if(this.isPointInRegion(this.xSize + 2 + 18 * l + 1, k * 18 + 1, 16, 16, mouseX, mouseY))
if(this.isPointInRegion(this.cheatX + 18 * l + 1, this.cheatY + k * 18 + 1, 16, 16, this.gm.mouse_x, this.gm.mouse_y))
this.renderToolTip(ITEM_LIST.get(i1), mouseX, mouseY);
}
}
@ -257,6 +230,7 @@ public abstract class GuiContainer extends Gui
{
this.drawTab(tabs);
}
GL11.glPopMatrix();
}
}
@ -281,12 +255,12 @@ public abstract class GuiContainer extends Gui
return;
if(this.gm.itemCheat) {
boolean flag = Button.MOUSE_LEFT.isDown(); //TODO: remove?
int x1 = this.xSize + 2 + this.cheatWidth * 18 + 1;
int y1 = 1;
int x1 = this.cheatX + this.cheatWidth * 18 + 1;
int y1 = this.cheatY + 1;
int x2 = x1 + 10;
int y2 = y1 + 112 + 18 * 4;
if (!this.wasClicking && flag && mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2)
if (!this.wasClicking && flag && this.gm.mouse_x >= x1 && this.gm.mouse_y >= y1 && this.gm.mouse_x < x2 && this.gm.mouse_y < y2)
{
this.isScrolling = this.needsScrollBars();
}
@ -300,7 +274,7 @@ public abstract class GuiContainer extends Gui
if (this.isScrolling)
{
this.currentScroll = ((float)(mouseY - y1) - 7.5F) / ((float)(y2 - y1) - 15.0F);
this.currentScroll = ((float)(this.gm.mouse_y - y1) - 7.5F) / ((float)(y2 - y1) - 15.0F);
this.currentScroll = ExtMath.clampf(this.currentScroll, 0.0F, 1.0F);
}
}
@ -423,21 +397,15 @@ public abstract class GuiContainer extends Gui
super.draw();
if(this.gm.itemCheat) {
if(this.needsScrollBars()) {
int i = this.xSize + 2 + this.cheatWidth * 18 + 1;
int j = 1;
int k = j + 184;
this.rect(i, j, 8, 182, 0x000000);
this.grad(i, j + (int)((float)(k - j - 17) * this.currentScroll), 8, 15, this.gm.style.fill_top, this.gm.style.fill_btm, this.gm.style.brdr_top, this.gm.style.brdr_btm);
int x1 = this.cheatX + this.cheatWidth * 18 + 1;
int y1 = this.cheatY + 1;
int y2 = y1 + 184;
Drawing.drawRect(x1, y1, 8, 182, 0xff000000);
Drawing.drawGradient(x1, y1 + (int)((float)(y2 - y1 - 17) * this.currentScroll), 8, 15, this.gm.style.fill_top, this.gm.style.fill_btm, this.gm.style.brdr_top, this.gm.style.brdr_btm);
}
this.rect(this.xSize + 2 + 18 * (selectedTab.getIndex() % this.cheatWidth), this.cheatHeight * 18 + 4 + 20 * (selectedTab.getIndex() / this.cheatWidth) - 2, 18, 2, 0xffffff);
Drawing.drawRect(this.cheatX + 18 * (selectedTab.getIndex() % this.cheatWidth), this.cheatY + this.cheatHeight * 18 + 4 + 20 * (selectedTab.getIndex() / this.cheatWidth) - 2, 18, 2, 0xffffffff);
}
this.drawGuiContainerBackgroundLayer();
if(this.gm.itemCheat) {
// CheatTab tab = CheatTab.TABS[selectedTab];
this.drawString(selectedTab.getName(), this.xSize + 2 + 4, -10);
this.drawString("Vorsicht: Schummeln wird mit Keule bestraft", this.xSize + 2 + 4, 18 * this.cheatHeight + 20 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 10);
this.drawString("(Halte Strg beim Klick für vollen Stapel)", this.xSize + 2 + 4, 18 * this.cheatHeight + 20 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 20);
}
this.drawGuiContainerForegroundLayer();
}
@ -588,13 +556,13 @@ public abstract class GuiContainer extends Gui
this.cheatStack = null;
return;
}
if((mouseButton == 0 || mouseButton == 1 || mouseButton == 2) && this.clickSide(mouseX, mouseY, -1, this.gm.shift() || mouseButton == 1, this.gm.ctrl() || mouseButton == 2))
if((mouseButton == 0 || mouseButton == 1 || mouseButton == 2) && this.clickSide(this.gm.mouse_x, this.gm.mouse_y, -1, this.gm.shift() || mouseButton == 1, this.gm.ctrl() || mouseButton == 2))
return;
if(mouseButton == 0) {
if(this.gm.itemCheat && this.gm.player != null && this.gm.player.inventory.getItemStack() == null) {
for (CheatTab tab : CheatTab.values())
{
if (this.isInsideTab(tab, mouseX, mouseY))
if (this.isInsideTab(tab, this.gm.mouse_x, this.gm.mouse_y))
{
this.setCurrentTab(tab);
return;
@ -973,7 +941,7 @@ public abstract class GuiContainer extends Gui
*/
public void useHotbar(int slot)
{
if (!this.clickSide((this.gm.mouse_x - this.container_x) / 2, (this.gm.mouse_y - this.container_y) / 2, slot, this.gm.shift(), this.gm.ctrl()) && this.gm != null && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null && this.theSlot != null)
if (!this.clickSide(this.gm.mouse_x, this.gm.mouse_y, slot, this.gm.shift(), this.gm.ctrl()) && this.gm != null && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null && this.theSlot != null)
{
// for (int i = 0; i < 9; ++i)
// {
@ -1018,6 +986,10 @@ public abstract class GuiContainer extends Gui
{
this.gm.displayGuiScreen(null);
}
else if(this.gm.itemCheat && !this.cheatSearch.getText().equals(this.cheatLast)) {
this.cheatLast = this.cheatSearch.getText();
this.setCurrentTab(selectedTab);
}
}
public void renderItemOverlayIntoGUI(ItemStack stack, int xPosition, int yPosition, String text)
@ -1070,13 +1042,13 @@ public abstract class GuiContainer extends Gui
protected boolean isInsideTab(CheatTab tab, int x, int y)
{
return x >= this.xSize + 2 + 18 * (tab.getIndex() % this.cheatWidth) && x < this.xSize + 2 + 18 * (tab.getIndex() % this.cheatWidth) + 18 &&
y >= this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth) && y < this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth) + 18;
return x >= this.cheatX + 18 * (tab.getIndex() % this.cheatWidth) && x < this.cheatX + 18 * (tab.getIndex() % this.cheatWidth) + 18 &&
y >= this.cheatY + this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth) && y < this.cheatY + this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth) + 18;
}
protected boolean renderInventoryHoveringText(CheatTab tab, int x, int z)
private boolean renderInventoryHoveringText(CheatTab tab, int x, int z)
{
if (this.isPointInRegion(this.xSize + 2 + 18 * (tab.getIndex() % this.cheatWidth), this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth), 18, 18, x, z))
if (this.isPointInRegion(this.cheatX + 18 * (tab.getIndex() % this.cheatWidth), this.cheatY + this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth), 18, 18, this.gm.mouse_x, this.gm.mouse_y))
{
this.hover(tab.getName(), x, z);
return true;
@ -1092,7 +1064,7 @@ public abstract class GuiContainer extends Gui
this.itemRender.zLevel = 100.0F;
ItemStack itemstack = tab.getIcon();
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(itemstack, this.xSize + 2 + 18 * (tab.getIndex() % this.cheatWidth) + 1, this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth) + 1);
this.itemRender.renderItemAndEffectIntoGUI(itemstack, this.cheatX + 18 * (tab.getIndex() % this.cheatWidth) + 1, this.cheatY + this.cheatHeight * 18 + 4 + 20 * (tab.getIndex() / this.cheatWidth) + 1);
this.itemRender.zLevel = 0.0F;
}
@ -1116,30 +1088,43 @@ public abstract class GuiContainer extends Gui
this.dragSplittingSlots.clear();
ITEM_LIST.clear();
tab.filter(ITEM_LIST);
if(!this.cheatLast.isBlank() && this.gm.player != null) {
for(Iterator<ItemStack> iter = ITEM_LIST.iterator(); iter.hasNext();) {
ItemStack stack = iter.next();
for(String line : stack.getTooltip(this.gm.player)) {
if(line.toLowerCase().contains(this.cheatLast.toLowerCase())) {
stack = null;
break;
}
}
if(stack != null)
iter.remove();
}
}
this.currentScroll = 0.0F;
this.cheatLabel.setText(tab.getName());
}
private boolean clickSide(int mouseX, int mouseY, int slot, boolean instant, boolean full) {
if(this.gm.itemCheat && this.isPointInRegion(this.xSize + 2, 0, 18 * this.cheatWidth, 18 * this.cheatHeight, mouseX, mouseY) && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null) {
int i = (ITEM_LIST.size() + this.cheatWidth - 1) / this.cheatWidth - this.cheatHeight;
int j = (int)((double)(this.currentScroll * (float)i) + 0.5D);
if(this.gm.itemCheat && this.isPointInRegion(this.cheatX, this.cheatY, 18 * this.cheatWidth, 18 * this.cheatHeight, mouseX, mouseY) && this.gm.player != null && this.gm.player.inventory.getItemStack() == null && this.cheatStack == null) {
int size = (ITEM_LIST.size() + this.cheatWidth - 1) / this.cheatWidth - this.cheatHeight;
int off = (int)((double)(this.currentScroll * (float)size) + 0.5D);
if (j < 0)
if (off < 0)
{
j = 0;
off = 0;
}
int sx = (mouseX - (this.xSize + 2)) / 18;
int sy = mouseY / 18;
int i1 = sx + (sy + j) * this.cheatWidth;
int sx = (mouseX - this.cheatX) / 18;
int sy = (mouseY - this.cheatY) / 18;
int idx = sx + (sy + off) * this.cheatWidth;
if(i1 >= 0 && i1 < ITEM_LIST.size()) {
if(idx >= 0 && idx < ITEM_LIST.size()) {
if(slot >= 0 || instant) {
this.gm.player.client.addToSendQueue(new CPacketCheat(ITEM_LIST.get(i1), slot, full));
this.gm.player.client.addToSendQueue(new CPacketCheat(ITEM_LIST.get(idx), slot, full));
}
else {
this.cheatStack = ITEM_LIST.get(i1).copy();
this.cheatStack = ITEM_LIST.get(idx).copy();
this.cheatStack.size = full ? this.cheatStack.getMaxStackSize() : 1;
}
return true;

View file

@ -1838,7 +1838,7 @@ public class ClientPlayer implements IClientPlayer
try
{
ParticleType particle = packetIn.getParticleType();
this.world.spawnEntityFX(particle, particle.getShouldIgnoreRange() | packetIn.isLongDistance(), packetIn.getXCoordinate(), packetIn.getYCoordinate(), packetIn.getZCoordinate(), d0, d2, d4, packetIn.getParticleArgs());
this.world.spawnEntityFX(particle, particle.getShouldIgnoreRange() | packetIn.isLongDistance(), packetIn.getXCoordinate(), packetIn.getYCoordinate(), packetIn.getZCoordinate(), d0, d2, d4, new int[] {packetIn.getParticleArg()});
}
catch (Throwable var17)
{
@ -1859,7 +1859,7 @@ public class ClientPlayer implements IClientPlayer
try
{
ParticleType particle = packetIn.getParticleType();
this.world.spawnEntityFX(particle, particle.getShouldIgnoreRange() | packetIn.isLongDistance(), packetIn.getXCoordinate() + d1, packetIn.getYCoordinate() + d3, packetIn.getZCoordinate() + d5, d6, d7, d8, packetIn.getParticleArgs());
this.world.spawnEntityFX(particle, particle.getShouldIgnoreRange() | packetIn.isLongDistance(), packetIn.getXCoordinate() + d1, packetIn.getYCoordinate() + d3, packetIn.getZCoordinate() + d5, d6, d7, d8, new int[] {packetIn.getParticleArg()});
}
catch (Throwable var16)
{