mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 09:54:25 +00:00
Large Auction Cleanup + Auction Events
- Auction Enums - Better Notification Handling - Auction Cancelation Events - Lang Key Cleanup
This commit is contained in:
1 parent
0512588a7a
commit
4510b3bbd1
31 files changed
+889
-578
No files matched your search
@@ -14,9 +14,9 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
*/
|
||||
public class ContainerAuctionBidding extends ContainerAuction {
|
||||
// Display slot layout
|
||||
private int itemSlotX = 71;
|
||||
private int itemSlotY = 76;
|
||||
private int itemSlotIndex = PLAYER_INV_SLOT_COUNT;
|
||||
private static final int ITEM_SLOT_X = 71;
|
||||
private static final int ITEM_SLOT_Y = 76;
|
||||
private static final int ITEM_SLOT_INDEX = PLAYER_INV_SLOT_COUNT;
|
||||
|
||||
private final IInventory displayInventory;
|
||||
private AuctionListing listing;
|
||||
@@ -26,7 +26,7 @@ public class ContainerAuctionBidding extends ContainerAuction {
|
||||
displayInventory = new InventoryBasic("Display", false, 1);
|
||||
|
||||
// Display slot (read-only)
|
||||
addSlotToContainer(new Slot(displayInventory, 0, itemSlotX, itemSlotY) {
|
||||
addSlotToContainer(new Slot(displayInventory, 0, ITEM_SLOT_X, ITEM_SLOT_Y) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) { return false; }
|
||||
@Override
|
||||
@@ -58,6 +58,6 @@ public class ContainerAuctionBidding extends ContainerAuction {
|
||||
* Check if this is the display slot.
|
||||
*/
|
||||
public boolean isDisplaySlot(int slotIndex) {
|
||||
return slotIndex == itemSlotIndex;
|
||||
return slotIndex == ITEM_SLOT_INDEX;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
* Items are cloned from inventory, not moved. Validation happens on submit.
|
||||
*/
|
||||
public class ContainerAuctionSell extends ContainerAuction {
|
||||
private int sellSlotX = 59;
|
||||
private int sellSlotY = 101;
|
||||
private int sellSlotIndex = PLAYER_INV_SLOT_COUNT;
|
||||
private int maxStack = 64;
|
||||
private static final int SELL_SLOT_X = 59;
|
||||
private static final int SELL_SLOT_Y = 101;
|
||||
private static final int SELL_SLOT_INDEX = PLAYER_INV_SLOT_COUNT;
|
||||
private static final int MAX_STACK = 64;
|
||||
|
||||
private final IInventory sellInventory;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
sellInventory = new InventoryBasic("Sell", false, 1);
|
||||
|
||||
// Sell slot blocks direct interaction
|
||||
addSlotToContainer(new Slot(sellInventory, 0, sellSlotX, sellSlotY) {
|
||||
addSlotToContainer(new Slot(sellInventory, 0, SELL_SLOT_X, SELL_SLOT_Y) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) { return false; }
|
||||
@Override
|
||||
@@ -59,11 +59,11 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
if (sellStack == null) {
|
||||
// Empty slot - create new stack
|
||||
ItemStack newStack = source.copy();
|
||||
newStack.stackSize = Math.min(toAdd, maxStack);
|
||||
newStack.stackSize = Math.min(toAdd, MAX_STACK);
|
||||
sellInventory.setInventorySlotContents(0, newStack);
|
||||
} else if (itemsMatch(sellStack, source)) {
|
||||
// Same item - add to existing (capped at 64)
|
||||
int space = maxStack - sellStack.stackSize;
|
||||
int space = MAX_STACK - sellStack.stackSize;
|
||||
int add = Math.min(toAdd, space);
|
||||
if (add > 0) {
|
||||
sellStack.stackSize += add;
|
||||
@@ -71,7 +71,7 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
} else {
|
||||
// Different item - replace
|
||||
ItemStack newStack = source.copy();
|
||||
newStack.stackSize = Math.min(toAdd, maxStack);
|
||||
newStack.stackSize = Math.min(toAdd, MAX_STACK);
|
||||
sellInventory.setInventorySlotContents(0, newStack);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
|
||||
/** Check if sell slot is this container slot index */
|
||||
public boolean isSellSlot(int slotIndex) {
|
||||
return slotIndex == sellSlotIndex;
|
||||
return slotIndex == SELL_SLOT_INDEX;
|
||||
}
|
||||
|
||||
/** Check if two stacks match using NoppesUtilPlayer.compareItems (same item, damage, and NBT) */
|
||||
|
||||
@@ -6,11 +6,13 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.constants.EnumTradeSlotType;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -34,7 +36,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
private int maxTradeSlots = 8; // Player's max trade slots (permission-aware, synced from server)
|
||||
|
||||
// Slot type tracking for proper accessor methods
|
||||
private int[] slotTypes = new int[SLOT_COUNT]; // 0=empty, 1=selling, 2=bidding, 3=claim
|
||||
private EnumTradeSlotType[] slotTypes = new EnumTradeSlotType[SLOT_COUNT];
|
||||
private int[] slotDataIndex = new int[SLOT_COUNT]; // Index into respective list
|
||||
|
||||
public ContainerAuctionTrades(EntityNPCInterface npc, EntityPlayer player) {
|
||||
@@ -117,8 +119,8 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
displayInventory.clear();
|
||||
|
||||
// Reset slot tracking
|
||||
Arrays.fill(slotTypes, EnumTradeSlotType.EMPTY);
|
||||
for (int i = 0; i < SLOT_COUNT; i++) {
|
||||
slotTypes[i] = 0;
|
||||
slotDataIndex[i] = -1;
|
||||
}
|
||||
}
|
||||
@@ -156,7 +158,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -166,7 +168,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -176,7 +178,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -186,7 +188,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
for (AuctionListing listing : activeListings) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
if (listing.item != null) displayInventory.setInventorySlotContents(slot, listing.item.copy());
|
||||
slotTypes[slot] = 1; // selling
|
||||
slotTypes[slot] = EnumTradeSlotType.SELLING;
|
||||
slotDataIndex[slot] = listingIdx;
|
||||
slot++;
|
||||
listingIdx++;
|
||||
@@ -197,7 +199,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
for (AuctionListing bid : activeBids) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
if (bid.item != null) displayInventory.setInventorySlotContents(slot, bid.item.copy());
|
||||
slotTypes[slot] = 2; // bidding
|
||||
slotTypes[slot] = EnumTradeSlotType.BIDDING;
|
||||
slotDataIndex[slot] = bidIdx;
|
||||
slot++;
|
||||
bidIdx++;
|
||||
@@ -208,7 +210,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -219,13 +221,13 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
/** Get listing at slot (or null if claim/empty) */
|
||||
public AuctionListing getListingAt(int slot) {
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return null;
|
||||
int type = slotTypes[slot];
|
||||
EnumTradeSlotType type = slotTypes[slot];
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx < 0) return null;
|
||||
|
||||
if (type == 1 && idx < activeListings.size()) {
|
||||
if (type == EnumTradeSlotType.SELLING && idx < activeListings.size()) {
|
||||
return activeListings.get(idx);
|
||||
} else if (type == 2 && idx < activeBids.size()) {
|
||||
} else if (type == EnumTradeSlotType.BIDDING && idx < activeBids.size()) {
|
||||
return activeBids.get(idx);
|
||||
}
|
||||
return null;
|
||||
@@ -234,7 +236,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
/** Get claim at slot (or null if listing/empty) */
|
||||
public AuctionClaim getClaimAt(int slot) {
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return null;
|
||||
if (slotTypes[slot] == 3) {
|
||||
if (slotTypes[slot] == EnumTradeSlotType.CLAIM) {
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx >= 0 && idx < claims.size()) {
|
||||
return claims.get(idx);
|
||||
@@ -245,12 +247,12 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
|
||||
/** Check if slot is player's active listing */
|
||||
public boolean isSellingAt(int slot) {
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 1;
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == EnumTradeSlotType.SELLING;
|
||||
}
|
||||
|
||||
/** Check if slot is player's active bid */
|
||||
public boolean isBiddingAt(int slot) {
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 2;
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == EnumTradeSlotType.BIDDING;
|
||||
}
|
||||
|
||||
/** Find listing matching item (searches both selling and bidding) */
|
||||
@@ -324,23 +326,23 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
private void restoreSlotItem(int slot) {
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return;
|
||||
|
||||
int type = slotTypes[slot];
|
||||
EnumTradeSlotType type = slotTypes[slot];
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx < 0) return;
|
||||
|
||||
if (type == 1 && idx < activeListings.size()) {
|
||||
if (type == EnumTradeSlotType.SELLING && idx < activeListings.size()) {
|
||||
// Selling
|
||||
AuctionListing listing = activeListings.get(idx);
|
||||
if (listing != null && listing.item != null) {
|
||||
displayInventory.setInventorySlotContents(slot, listing.item.copy());
|
||||
}
|
||||
} else if (type == 2 && idx < activeBids.size()) {
|
||||
} else if (type == EnumTradeSlotType.BIDDING && idx < activeBids.size()) {
|
||||
// Bidding
|
||||
AuctionListing bid = activeBids.get(idx);
|
||||
if (bid != null && bid.item != null) {
|
||||
displayInventory.setInventorySlotContents(slot, bid.item.copy());
|
||||
}
|
||||
} else if (type == 3 && idx < claims.size()) {
|
||||
} else if (type == EnumTradeSlotType.CLAIM && idx < claims.size()) {
|
||||
// Claim
|
||||
displayInventory.setClaimItem(slot, claims.get(idx));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user