Auction Fixes

This commit is contained in:
Kam committed 2026-01-24 01:57:46 -05:00
1 parent 5992e1badc
commit 3e57b837aa
13 files changed
+555 -210

No files matched your search

@@ -2,6 +2,9 @@ package noppes.npcs.containers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.constants.EnumClaimType;
import noppes.npcs.controllers.AuctionController;
import noppes.npcs.controllers.data.AuctionClaim;
import noppes.npcs.controllers.data.AuctionListing;
@@ -13,6 +16,7 @@ import java.util.List;
/**
* Container for viewing player's auction trades.
* Shows active listings, bids, and claims in a 9x5 grid.
* Order: SOLD claims, OUTBID claims, WON claims, SELLING, BIDDING, EXPIRED claims
*/
public class ContainerAuctionTrades extends ContainerAuction {
// Grid layout
@@ -28,6 +32,10 @@ public class ContainerAuctionTrades extends ContainerAuction {
private List<AuctionClaim> claims = new ArrayList<>();
private int hiddenSlot = -1;
// Slot type tracking for proper accessor methods
private int[] slotTypes = new int[SLOT_COUNT]; // 0=empty, 1=selling, 2=bidding, 3=claim
private int[] slotDataIndex = new int[SLOT_COUNT]; // Index into respective list
public ContainerAuctionTrades(EntityNPCInterface npc, EntityPlayer player) {
super(npc, player);
displayInventory = new InventoryAuctionDisplay(SLOT_COUNT);
@@ -44,34 +52,158 @@ public class ContainerAuctionTrades extends ContainerAuction {
refreshData();
}
/** Refresh data from controller */
/** Refresh data from controller (server-side only) */
public void refreshData() {
// Clear existing data
clearData();
// Only works on server where AuctionController exists
if (AuctionController.Instance == null) return;
List<AuctionListing> newListings = AuctionController.Instance.getPlayerActiveListings(player.getUniqueID());
List<AuctionListing> newBids = AuctionController.Instance.getPlayerActiveBids(player.getUniqueID());
List<AuctionClaim> newClaims = AuctionController.Instance.getPlayerClaims(player.getUniqueID());
populateDisplay(newListings, newBids, newClaims);
}
/** Set data from NBT received from server (client-side) */
public void setTradesData(NBTTagCompound compound) {
// Clear existing data
clearData();
List<AuctionListing> newListings = new ArrayList<>();
List<AuctionListing> newBids = new ArrayList<>();
List<AuctionClaim> newClaims = new ArrayList<>();
// Parse active listings
if (compound.hasKey("ActiveListings")) {
NBTTagList listingsNBT = compound.getTagList("ActiveListings", 10);
for (int i = 0; i < listingsNBT.tagCount(); i++) {
newListings.add(AuctionListing.fromNBT(listingsNBT.getCompoundTagAt(i)));
}
}
// Parse active bids
if (compound.hasKey("ActiveBids")) {
NBTTagList bidsNBT = compound.getTagList("ActiveBids", 10);
for (int i = 0; i < bidsNBT.tagCount(); i++) {
newBids.add(AuctionListing.fromNBT(bidsNBT.getCompoundTagAt(i)));
}
}
// Parse claims
if (compound.hasKey("Claims")) {
NBTTagList claimsNBT = compound.getTagList("Claims", 10);
for (int i = 0; i < claimsNBT.tagCount(); i++) {
newClaims.add(AuctionClaim.fromNBT(claimsNBT.getCompoundTagAt(i)));
}
}
populateDisplay(newListings, newBids, newClaims);
}
/** Clear all data and reset display */
private void clearData() {
activeListings.clear();
activeBids.clear();
claims.clear();
displayInventory.clear();
if (AuctionController.Instance == null) return;
// Reset slot tracking
for (int i = 0; i < SLOT_COUNT; i++) {
slotTypes[i] = 0;
slotDataIndex[i] = -1;
}
}
activeListings = AuctionController.Instance.getPlayerActiveListings(player.getUniqueID());
activeBids = AuctionController.Instance.getPlayerActiveBids(player.getUniqueID());
claims = AuctionController.Instance.getPlayerClaims(player.getUniqueID());
/** Populate display from provided data lists */
private void populateDisplay(List<AuctionListing> newListings, List<AuctionListing> newBids, List<AuctionClaim> allClaims) {
activeListings = new ArrayList<>(newListings);
activeBids = new ArrayList<>(newBids);
// Populate display: listings first, then bids, then claims
// Sort claims into categories for proper display order
List<AuctionClaim> soldClaims = new ArrayList<>(); // CURRENCY - sold items
List<AuctionClaim> outbidClaims = new ArrayList<>(); // REFUND - outbid refunds
List<AuctionClaim> wonClaims = new ArrayList<>(); // ITEM won (isReturned=false)
List<AuctionClaim> expiredClaims = new ArrayList<>(); // ITEM returned (isReturned=true)
for (AuctionClaim claim : allClaims) {
if (claim.type == EnumClaimType.CURRENCY) {
soldClaims.add(claim);
} else if (claim.type == EnumClaimType.REFUND) {
outbidClaims.add(claim);
} else if (claim.type == EnumClaimType.ITEM) {
if (claim.isReturned) {
expiredClaims.add(claim);
} else {
wonClaims.add(claim);
}
}
}
// Populate display in order: SOLD, OUTBID, WON, SELLING, BIDDING, EXPIRED
int slot = 0;
// 1. Sold claims (green) - you have money to claim!
for (AuctionClaim claim : soldClaims) {
if (slot >= SLOT_COUNT) break;
claims.add(claim);
displayInventory.setClaimItem(slot, claim);
slotTypes[slot] = 3; // claim
slotDataIndex[slot] = claims.size() - 1;
slot++;
}
// 2. Outbid claims (yellow) - refunds available
for (AuctionClaim claim : outbidClaims) {
if (slot >= SLOT_COUNT) break;
claims.add(claim);
displayInventory.setClaimItem(slot, claim);
slotTypes[slot] = 3; // claim
slotDataIndex[slot] = claims.size() - 1;
slot++;
}
// 3. Won claims (green) - items to claim!
for (AuctionClaim claim : wonClaims) {
if (slot >= SLOT_COUNT) break;
claims.add(claim);
displayInventory.setClaimItem(slot, claim);
slotTypes[slot] = 3; // claim
slotDataIndex[slot] = claims.size() - 1;
slot++;
}
// 4. Active listings (blue) - items you're selling
int listingIdx = 0;
for (AuctionListing listing : activeListings) {
if (slot >= SLOT_COUNT) break;
if (listing.item != null) displayInventory.setInventorySlotContents(slot, listing.item.copy());
slotTypes[slot] = 1; // selling
slotDataIndex[slot] = listingIdx;
slot++;
listingIdx++;
}
// 5. Active bids (blue) - items you're bidding on
int bidIdx = 0;
for (AuctionListing bid : activeBids) {
if (slot >= SLOT_COUNT) break;
if (bid.item != null) displayInventory.setInventorySlotContents(slot, bid.item.copy());
slotTypes[slot] = 2; // bidding
slotDataIndex[slot] = bidIdx;
slot++;
bidIdx++;
}
for (AuctionClaim claim : claims) {
// 6. Expired claims (red) - returned items (lowest priority)
for (AuctionClaim claim : expiredClaims) {
if (slot >= SLOT_COUNT) break;
claims.add(claim);
displayInventory.setClaimItem(slot, claim);
slotTypes[slot] = 3; // claim
slotDataIndex[slot] = claims.size() - 1;
slot++;
}
}
@@ -80,34 +212,39 @@ public class ContainerAuctionTrades extends ContainerAuction {
/** Get listing at slot (or null if claim/empty) */
public AuctionListing getListingAt(int slot) {
if (slot >= 0 && slot < activeListings.size()) {
return activeListings.get(slot);
}
int bidIdx = slot - activeListings.size();
if (bidIdx >= 0 && bidIdx < activeBids.size()) {
return activeBids.get(bidIdx);
if (slot < 0 || slot >= SLOT_COUNT) return null;
int type = slotTypes[slot];
int idx = slotDataIndex[slot];
if (idx < 0) return null;
if (type == 1 && idx < activeListings.size()) {
return activeListings.get(idx);
} else if (type == 2 && idx < activeBids.size()) {
return activeBids.get(idx);
}
return null;
}
/** Get claim at slot (or null if listing/empty) */
public AuctionClaim getClaimAt(int slot) {
int claimIdx = slot - activeListings.size() - activeBids.size();
if (claimIdx >= 0 && claimIdx < claims.size()) {
return claims.get(claimIdx);
if (slot < 0 || slot >= SLOT_COUNT) return null;
if (slotTypes[slot] == 3) {
int idx = slotDataIndex[slot];
if (idx >= 0 && idx < claims.size()) {
return claims.get(idx);
}
}
return null;
}
/** Check if slot is player's active listing */
public boolean isSellingAt(int slot) {
return slot >= 0 && slot < activeListings.size();
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 1;
}
/** Check if slot is player's active bid */
public boolean isBiddingAt(int slot) {
int bidIdx = slot - activeListings.size();
return bidIdx >= 0 && bidIdx < activeBids.size();
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 2;
}
/** Find listing matching item */
@@ -159,24 +296,29 @@ public class ContainerAuctionTrades extends ContainerAuction {
hiddenSlot = -1;
}
/** Restore item at slot from data */
/** Restore item at slot from data using slot tracking */
private void restoreSlotItem(int slot) {
if (slot < activeListings.size()) {
AuctionListing listing = activeListings.get(slot);
if (slot < 0 || slot >= SLOT_COUNT) return;
int type = slotTypes[slot];
int idx = slotDataIndex[slot];
if (idx < 0) return;
if (type == 1 && idx < activeListings.size()) {
// Selling
AuctionListing listing = activeListings.get(idx);
if (listing != null && listing.item != null) {
displayInventory.setInventorySlotContents(slot, listing.item.copy());
}
} else if (slot < activeListings.size() + activeBids.size()) {
int bidIdx = slot - activeListings.size();
AuctionListing bid = activeBids.get(bidIdx);
} else if (type == 2 && idx < activeBids.size()) {
// Bidding
AuctionListing bid = activeBids.get(idx);
if (bid != null && bid.item != null) {
displayInventory.setInventorySlotContents(slot, bid.item.copy());
}
} else {
int claimIdx = slot - activeListings.size() - activeBids.size();
if (claimIdx < claims.size()) {
displayInventory.setClaimItem(slot, claims.get(claimIdx));
}
} else if (type == 3 && idx < claims.size()) {
// Claim
displayInventory.setClaimItem(slot, claims.get(idx));
}
}