1
0
Fork 0

change inventory system

This commit is contained in:
Sen 2025-09-04 16:52:31 +02:00
parent 6bb1c7c050
commit 9bd1ac3b45
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
2 changed files with 20 additions and 308 deletions

View file

@ -4,7 +4,6 @@ import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.lwjgl.opengl.GL15;
@ -28,7 +27,6 @@ import client.renderer.entity.RenderItem;
import client.window.Bind;
import client.window.Button;
import common.collect.Lists;
import common.collect.Sets;
import common.enchantment.Enchantment;
import common.entity.npc.Attribute;
import common.entity.npc.EntityNPC;
@ -69,13 +67,8 @@ public abstract class GuiContainer extends Gui
protected int ySize = 166;
public Container inventorySlots;
private Slot theSlot;
protected final Set<Slot> dragSplittingSlots = Sets.<Slot>newHashSet();
protected final List<Overlay> drawnOverlays = Lists.<Overlay>newArrayList();
protected boolean dragSplitting;
private int dragSplittingLimit;
private int dragSplittingButton;
private boolean ignoreMouseUp;
private int dragSplittingRemnant;
private long lastClickTime;
private Slot lastClickSlot;
private int lastClickButton;
@ -438,17 +431,7 @@ public abstract class GuiContainer extends Gui
int k2 = 8;
String s = null;
if (this.dragSplitting && this.dragSplittingSlots.size() > 1)
{
stack = stack.copy();
stack.setSize(this.dragSplittingRemnant);
if (stack.isEmpty())
{
s = "" + Color.YELLOW + "0";
}
}
else if(stack == this.cheatStack) {
if(stack == this.cheatStack) {
s = Color.DARK_GREEN + "+" + Color.GREEN + formatAmount(stack.getSize());
}
@ -542,38 +525,6 @@ public abstract class GuiContainer extends Gui
ItemStack itemstack1 = this.gm.player.getMouseItem();
String s = null;
if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null)
{
if (this.dragSplittingSlots.size() == 1)
{
return;
}
if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn))
{
itemstack = itemstack1.copy();
flag = true;
Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().getSize());
if (itemstack.getSize() > itemstack.getMaxStackSize())
{
s = Color.YELLOW + formatAmount(itemstack.getMaxStackSize());
itemstack.setSize(itemstack.getMaxStackSize());
}
if (itemstack.getSize() > slotIn.getItemStackLimit(itemstack))
{
s = Color.YELLOW + formatAmount(slotIn.getItemStackLimit(itemstack));
itemstack.setSize(slotIn.getItemStackLimit(itemstack));
}
}
else
{
this.dragSplittingSlots.remove(slotIn);
this.updateDragSplitting();
}
}
this.itemRender.zLevel = 100.0F;
GlState.enableDepth();
@ -583,35 +534,6 @@ public abstract class GuiContainer extends Gui
this.itemRender.zLevel = 0.0F;
}
private void updateDragSplitting()
{
ItemStack itemstack = this.gm.player.getMouseItem();
if (itemstack != null && this.dragSplitting)
{
this.dragSplittingRemnant = itemstack.getSize();
for (Slot slot : this.dragSplittingSlots)
{
ItemStack itemstack1 = itemstack.copy();
int i = slot.getStack() == null ? 0 : slot.getStack().getSize();
Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i);
if (itemstack1.getSize() > itemstack1.getMaxStackSize())
{
itemstack1.setSize(itemstack1.getMaxStackSize());
}
if (itemstack1.getSize() > slot.getItemStackLimit(itemstack1))
{
itemstack1.setSize(slot.getItemStackLimit(itemstack1));
}
this.dragSplittingRemnant -= itemstack1.getSize() - i;
}
}
}
private Slot getSlotAtPosition(int x, int y)
{
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i)
@ -680,43 +602,29 @@ public abstract class GuiContainer extends Gui
if (l != -1)
{
if (!this.dragSplitting)
if (this.gm.player.getMouseItem() == null)
{
if (this.gm.player.getMouseItem() == null)
boolean flag2 = l != -999 && this.gm.shift();
int i1 = 0;
if (flag2)
{
boolean flag2 = l != -999 && this.gm.shift();
int i1 = 0;
if (flag2)
{
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
i1 = 1;
}
else if (l == -999)
{
i1 = 4;
}
this.handleMouseClick(slot, l, mouseButton, i1);
this.ignoreMouseUp = true;
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
i1 = 1;
}
else
else if (l == -999)
{
this.dragSplitting = true;
this.dragSplittingButton = mouseButton;
this.dragSplittingSlots.clear();
if (mouseButton == 0)
{
this.dragSplittingLimit = 0;
}
else if (mouseButton == 1)
{
this.dragSplittingLimit = 1;
}
i1 = 4;
}
this.handleMouseClick(slot, l, mouseButton, i1);
this.ignoreMouseUp = true;
}
// else
// {
// this.dragSplitting = true;
// }
}
}
@ -727,16 +635,6 @@ public abstract class GuiContainer extends Gui
public void mouseDragged(int mouseX, int mouseY)
{
if(this.gm == null || this.cheatStack != null)
return;
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
ItemStack itemstack = this.gm.player.getMouseItem();
if (this.dragSplitting && slot != null && itemstack != null && itemstack.getSize() > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot))
{
this.dragSplittingSlots.add(slot);
this.updateDragSplitting();
}
}
public void mouseReleased(int mouseX, int mouseY, int state)
@ -782,32 +680,13 @@ public abstract class GuiContainer extends Gui
}
else
{
if (this.dragSplitting && this.dragSplittingButton != state)
{
this.dragSplitting = false;
this.dragSplittingSlots.clear();
this.ignoreMouseUp = true;
return;
}
if (this.ignoreMouseUp)
{
this.ignoreMouseUp = false;
return;
}
if (this.dragSplitting && !this.dragSplittingSlots.isEmpty())
{
this.handleMouseClick((Slot)null, -999, Container.getDragCode(0, this.dragSplittingLimit), 5);
for (Slot slot1 : this.dragSplittingSlots)
{
this.handleMouseClick(slot1, slot1.slotNumber, Container.getDragCode(1, this.dragSplittingLimit), 5);
}
this.handleMouseClick((Slot)null, -999, Container.getDragCode(2, this.dragSplittingLimit), 5);
}
else if (this.gm.player.getMouseItem() != null)
if (this.gm.player.getMouseItem() != null)
{
boolean flag1 = k != -999 && this.gm.shift();
@ -824,8 +703,6 @@ public abstract class GuiContainer extends Gui
{
this.lastClickTime = 0L;
}
this.dragSplitting = false;
}
private boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY)
@ -987,7 +864,6 @@ public abstract class GuiContainer extends Gui
private void setCurrentTab(CheatTab tab)
{
selectedTab = tab;
this.dragSplittingSlots.clear();
ITEM_LIST.clear();
tab.filter(ITEM_LIST);
if(!this.cheatLast.isBlank() && this.gm.player != null) {

View file

@ -9,7 +9,6 @@ import common.entity.npc.EntityNPC;
import common.item.Item;
import common.item.ItemStack;
import common.network.IPlayer;
import common.util.ExtMath;
public abstract class Container
{
@ -17,15 +16,6 @@ public abstract class Container
public List<Slot> inventorySlots = Lists.<Slot>newArrayList();
public int windowId;
private short transactionID;
/**
* The current drag mode (0 : evenly split, 1 : one item by slot, 2 : not used ?)
*/
private int dragMode = -1;
/** The current drag event (0 : start, 1 : add slot : 2 : end) */
private int dragEvent;
private final Set<Slot> dragSlots = Sets.<Slot>newHashSet();
protected List<IPlayer> crafters = Lists.<IPlayer>newArrayList();
private Set<EntityNPC> playerList = Sets.<EntityNPC>newHashSet();
@ -146,94 +136,7 @@ public abstract class Container
{
ItemStack itemstack = null;
if (mode == 5)
{
int i = this.dragEvent;
this.dragEvent = getDragEvent(clickedButton);
if ((i != 1 || this.dragEvent != 2) && i != this.dragEvent)
{
this.resetDrag();
}
else if (playerIn.getMouseItem() == null)
{
this.resetDrag();
}
else if (this.dragEvent == 0)
{
this.dragMode = extractDragMode(clickedButton);
if (isValidDragMode(this.dragMode, playerIn))
{
this.dragEvent = 1;
this.dragSlots.clear();
}
else
{
this.resetDrag();
}
}
else if (this.dragEvent == 1)
{
Slot slot = (Slot)this.inventorySlots.get(slotId);
if (slot != null && canAddItemToSlot(slot, playerIn.getMouseItem(), true) && slot.isItemValid(playerIn.getMouseItem()) && playerIn.getMouseItem().getSize() > this.dragSlots.size() && this.canDragIntoSlot(slot))
{
this.dragSlots.add(slot);
}
}
else if (this.dragEvent == 2)
{
if (!this.dragSlots.isEmpty())
{
ItemStack itemstack3 = playerIn.getMouseItem().copy();
int j = playerIn.getMouseItem().getSize();
for (Slot slot1 : this.dragSlots)
{
if (slot1 != null && canAddItemToSlot(slot1, playerIn.getMouseItem(), true) && slot1.isItemValid(playerIn.getMouseItem()) && playerIn.getMouseItem().getSize() >= this.dragSlots.size() && this.canDragIntoSlot(slot1))
{
ItemStack itemstack1 = itemstack3.copy();
int k = slot1.getHasStack() ? slot1.getStack().getSize() : 0;
computeStackSize(this.dragSlots, this.dragMode, itemstack1, k);
if (itemstack1.isOverLimit())
{
itemstack1.setSize(itemstack1.getMaxStackSize());
}
if (itemstack1.getSize() > slot1.getItemStackLimit(itemstack1))
{
itemstack1.setSize(slot1.getItemStackLimit(itemstack1));
}
j -= itemstack1.getSize() - k;
slot1.putStack(itemstack1);
}
}
itemstack3.setSize(j);
if (itemstack3.isEmpty())
{
itemstack3 = null;
}
playerIn.setMouseItem(itemstack3);
}
this.resetDrag();
}
else
{
this.resetDrag();
}
}
else if (this.dragEvent != 0)
{
this.resetDrag();
}
else if ((mode == 0 || mode == 1) && (clickedButton == 0 || clickedButton == 1))
if ((mode == 0 || mode == 1) && (clickedButton == 0 || clickedButton == 1))
{
if (slotId == -999)
{
@ -679,41 +582,6 @@ public abstract class Container
return true;
}
/**
* Extracts the drag mode. Args : eventButton. Return (0 : evenly split, 1 : one item by slot, 2 : not used ?)
*/
public static int extractDragMode(int dragCode)
{
return dragCode >> 2 & 3;
}
/**
* Args : clickedButton, Returns (0 : start drag, 1 : add slot, 2 : end drag)
*/
public static int getDragEvent(int dragCode)
{
return dragCode & 3;
}
public static int getDragCode(int dragEvent, int dragMode)
{
return dragEvent & 3 | (dragMode & 3) << 2;
}
public static boolean isValidDragMode(int dragModeIn, EntityNPC player)
{
return dragModeIn == 0 ? true : /* ( */ dragModeIn == 1; // ? true : dragModeIn == 2 && player.creative);
}
/**
* Reset the drag fields
*/
protected void resetDrag()
{
this.dragEvent = 0;
this.dragSlots.clear();
}
/**
* Checks if it's possible to add the given itemstack to the given slot.
*/
@ -728,36 +596,4 @@ public abstract class Container
return flag;
}
/**
* Compute the new stack size, Returns the stack with the new size. Args : dragSlots, dragMode, dragStack,
* slotStackSize
*/
public static void computeStackSize(Set<Slot> p_94525_0_, int p_94525_1_, ItemStack p_94525_2_, int p_94525_3_)
{
switch (p_94525_1_)
{
case 0:
p_94525_2_.setSize(ExtMath.floorf((float)p_94525_2_.getSize() / (float)p_94525_0_.size()));
break;
case 1:
p_94525_2_.setSize(1);
break;
case 2:
p_94525_2_.setSize(p_94525_2_.getItem().getMaxAmount());
}
p_94525_2_.incrSize(p_94525_3_);
}
/**
* Returns true if the player can "drag-spilt" items into this slot,. returns true by default. Called to check if
* the slot can be added to a list of Slots to split the held ItemStack across.
*/
public boolean canDragIntoSlot(Slot p_94531_1_)
{
return true;
}
}