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)
{

View file

@ -101,7 +101,7 @@ public abstract class ItemRegistry {
private static void register(String name, Item item) {
if(item.getBlock() != null)
throw new IllegalArgumentException("Gegenstand " + name + " darf keinen Block besitzen");
if(item.getTab() == null || item.getTab().isBlockTab())
if(item.getTab() == null || !item.getTab().isItemTab())
throw new IllegalArgumentException("Gegenstand " + name + " muss einen Gegenstand-Tab besitzen");
if(ITEM_MAP.containsKey(name))
throw new IllegalArgumentException("Gegenstand " + name + " ist bereits mit ID " + ITEM_IDS.get(ITEM_MAP.get(name)) + " registriert");

View file

@ -6,6 +6,17 @@ import common.init.ItemRegistry;
import common.init.Items;
public enum CheatTab {
ALL("Alles") {
protected Item getIconItem() {
return Items.navigator;
}
public void filter(List<ItemStack> list) {
for(Item item : ItemRegistry.items()) {
item.getSubItems(list);
}
}
},
BLOCKS("Baumaterial", true) {
protected Item getIconItem() {
return Items.glass;
@ -90,16 +101,48 @@ public enum CheatTab {
protected Item getIconItem() {
return Items.charge_crystal;
}
},
ALL_BLOCKS("Alle Blöcke") {
protected Item getIconItem() {
return Items.stone;
}
public void filter(List<ItemStack> list) {
for(Item item : ItemRegistry.items()) {
if(item.getBlock() != null)
item.getSubItems(list);
}
}
},
ALL_ITEMS("Alle Gegenstände") {
protected Item getIconItem() {
return Items.flint;
}
public void filter(List<ItemStack> list) {
for(Item item : ItemRegistry.items()) {
if(item.getBlock() == null)
item.getSubItems(list);
}
}
};
private final String name;
private final boolean blocks;
private final boolean items;
private ItemStack icon;
private CheatTab(String name, boolean blocks) {
this.name = name;
this.blocks = blocks;
this.items = !blocks;
}
private CheatTab(String name) {
this.name = name;
this.blocks = false;
this.items = false;
}
public int getIndex() {
@ -114,6 +157,10 @@ public enum CheatTab {
return this.blocks;
}
public boolean isItemTab() {
return this.items;
}
public ItemStack getIcon() {
if(this.icon == null)
this.icon = new ItemStack(this.getIconItem());
@ -124,9 +171,8 @@ public enum CheatTab {
public void filter(List<ItemStack> list) {
for(Item item : ItemRegistry.items()) {
if(item != null && item.getTab() == this) {
if(item.getTab() == this)
item.getSubItems(list);
}
}
}
}

View file

@ -44,9 +44,9 @@ public enum ParticleType
SLIME("slime", 33, false),
HEART("heart", 34, false),
// BARRIER("barrier", 35, false),
ITEM_CRACK("iconcrack_", 36, false, 2),
BLOCK_CRACK("blockcrack_", 37, false, 1),
BLOCK_DUST("blockdust_", 38, false, 1),
ITEM_CRACK("iconcrack_", 36, false, true),
BLOCK_CRACK("blockcrack_", 37, false, true),
BLOCK_DUST("blockdust_", 38, false, true),
WATER_DROP("droplet", 39, false),
ITEM_TAKE("take", 40, false),
HAIL_CORN("hail", 41, false);
@ -54,21 +54,21 @@ public enum ParticleType
private final String particleName;
private final int particleID;
private final boolean shouldIgnoreRange;
private final int argumentCount;
private final boolean argument;
private static final Map<Integer, ParticleType> PARTICLES = Maps.<Integer, ParticleType>newHashMap();
private static final String[] PARTICLE_NAMES;
private ParticleType(String particleNameIn, int particleIDIn, boolean unlimited, int argumentCountIn)
private ParticleType(String particleNameIn, int particleIDIn, boolean unlimited, boolean argumentCountIn)
{
this.particleName = particleNameIn;
this.particleID = particleIDIn;
this.shouldIgnoreRange = unlimited;
this.argumentCount = argumentCountIn;
this.argument = argumentCountIn;
}
private ParticleType(String particleNameIn, int particleIDIn, boolean unlimited)
{
this(particleNameIn, particleIDIn, unlimited, 0);
this(particleNameIn, particleIDIn, unlimited, false);
}
public static String[] getParticleNames()
@ -86,9 +86,9 @@ public enum ParticleType
return this.particleID;
}
public int getArgumentCount()
public boolean hasArgument()
{
return this.argumentCount;
return this.argument;
}
public boolean getShouldIgnoreRange()
@ -96,11 +96,6 @@ public enum ParticleType
return this.shouldIgnoreRange;
}
public boolean hasArguments()
{
return this.argumentCount > 0;
}
public static ParticleType getParticleFromId(int particleId)
{
return PARTICLES.get(particleId);

View file

@ -19,17 +19,13 @@ public class SPacketParticles implements Packet<IClientPlayer>
private float particleSpeed;
private int particleCount;
private boolean longDistance;
/**
* These are the block/item ids and possibly metaData ids that are used to color or texture the particle.
*/
private int[] particleArguments;
private int particleArgument;
public SPacketParticles()
{
}
public SPacketParticles(ParticleType particleTypeIn, boolean longDistanceIn, float x, float y, float z, float xOffsetIn, float yOffset, float zOffset, float particleSpeedIn, int particleCountIn, int[] particleArgumentsIn)
public SPacketParticles(ParticleType particleTypeIn, boolean longDistanceIn, float x, float y, float z, float xOffsetIn, float yOffset, float zOffset, float particleSpeedIn, int particleCountIn, int particleArgumentIn)
{
this.particleType = particleTypeIn;
this.longDistance = longDistanceIn;
@ -41,7 +37,7 @@ public class SPacketParticles implements Packet<IClientPlayer>
this.zOffset = zOffset;
this.particleSpeed = particleSpeedIn;
this.particleCount = particleCountIn;
this.particleArguments = particleArgumentsIn;
this.particleArgument = particleArgumentIn;
}
/**
@ -65,13 +61,8 @@ public class SPacketParticles implements Packet<IClientPlayer>
this.zOffset = buf.readFloat();
this.particleSpeed = buf.readFloat();
this.particleCount = buf.readInt();
int i = this.particleType.getArgumentCount();
this.particleArguments = new int[i];
for (int j = 0; j < i; ++j)
{
this.particleArguments[j] = buf.readVarInt();
}
if(this.particleType.hasArgument())
this.particleArgument = buf.readVarInt();
}
/**
@ -89,12 +80,8 @@ public class SPacketParticles implements Packet<IClientPlayer>
buf.writeFloat(this.zOffset);
buf.writeFloat(this.particleSpeed);
buf.writeInt(this.particleCount);
int i = this.particleType.getArgumentCount();
for (int j = 0; j < i; ++j)
{
buf.writeVarInt(this.particleArguments[j]);
}
if(this.particleType.hasArgument())
buf.writeVarInt(this.particleArgument);
}
public ParticleType getParticleType()
@ -175,9 +162,9 @@ public class SPacketParticles implements Packet<IClientPlayer>
* Gets the particle arguments. Some particles rely on block and/or item ids and sometimes metadata ids to color or
* texture the particle.
*/
public int[] getParticleArgs()
public int getParticleArg()
{
return this.particleArguments;
return this.particleArgument;
}
/**

View file

@ -1296,7 +1296,7 @@ public final class WorldServer extends AWorldServer {
public void spawnParticle(ParticleType particleType, boolean longDistance, double xCoord, double yCoord, double zCoord,
int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int[] particleArguments) {
Packet packet = new SPacketParticles(particleType, longDistance, (float)xCoord, (float)yCoord, (float)zCoord, (float)xOffset,
(float)yOffset, (float)zOffset, (float)particleSpeed, numberOfParticles, particleArguments);
(float)yOffset, (float)zOffset, (float)particleSpeed, numberOfParticles, particleArguments.length == 0 ? 0 : particleArguments[0]);
for(int i = 0; i < this.players.size(); ++i) {
EntityNPC entityplayermp = this.players.get(i);
@ -1697,11 +1697,11 @@ public final class WorldServer extends AWorldServer {
player.attackEntityFrom(DamageSource.causeExterminatusDamage(null), 5000);
Packet packet = new SPacketParticles(ParticleType.EXPLOSION_HUGE, true,
(float)player.posX, (float)this.getSeaLevel() + 4.0f, (float)player.posZ, (float)128.0,
(float)2.0, (float)128.0, (float)0.15, 1000, new int[0]);
(float)2.0, (float)128.0, (float)0.15, 1000, 0);
player.connection.sendPacket(packet);
packet = new SPacketParticles(ParticleType.CLOUD, true,
(float)player.posX, (float)this.getSeaLevel() + 4.0f, (float)player.posZ, (float)128.0,
(float)2.0, (float)128.0, (float)0.15, 1000, new int[0]);
(float)2.0, (float)128.0, (float)0.15, 1000, 0);
player.connection.sendPacket(packet);
packet = new SPacketEffect(1025, new BlockPos(player.posX, (double)this.getSeaLevel() + 4.0, player.posZ), 0);
player.connection.sendPacket(packet);