Skip to content

Commit

Permalink
Properly remove items from inv
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Jun 27, 2023
1 parent 6ebcbe3 commit 3d1d918
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ private void processUpkeep(Inventory inventory, Map<Material, AmountAndModel> fu
}

if (itemMeta instanceof Damageable d) {
d.setDamage(d.getDamage() + 1);
d.setDamage(d.getDamage() + amountAndModel.amount);
if (d.getDamage() >= content.getType().getMaxDurability()) {
inventory.getContents()[i] = null;

inventory.setItem(i, null);
} else {
content.setItemMeta(d);
fulfilled.remove(content.getType());
Expand All @@ -299,7 +298,7 @@ private void processUpkeep(Inventory inventory, Map<Material, AmountAndModel> fu
fulfilled.remove(content.getType());

} else {
inventory.getContents()[i] = null;
inventory.setItem(i, null);
amountAndModel.amount -= amount;
}

Expand All @@ -317,7 +316,6 @@ public boolean anyInventoryIsBeingAccessed(LoadedStructure structure) {
return false;
}


private record StructAndInv(UUID structureId, Inventory inventory, Location location) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public String id() {

@Override
public boolean check(TownContext townContext, ItemList configContext) {
Set<ItemStack> itemStackSet = new HashSet<>();
for (ItemList.ConfigItem configItem : configContext.configItems) {
ItemStack itemStack = configItem.toItemStack();
itemStackSet.add(itemStack);
}

//todo TownyCivs.injector.getInstance(StructureInventoryService.class).canTakeProducedItems(townContext.loadedStructure, itemStackSet);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ private void handleTick(LoadedStructure structure, TownContext ctx) {
}
}

for (Structure.LoadedPair<Mechanic<Object>, Object> m : structure.structureDef.production) {
if (!m.mechanic.check(ctx, m.configValue)) {
return;
}
}

for (Structure.LoadedPair<Mechanic<Object>, Object> m : upkeep) {
m.mechanic.postAction(ctx, m.configValue);
}
Expand Down

0 comments on commit 3d1d918

Please sign in to comment.