Skip to content

Commit

Permalink
Add shulker to in chest count (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSolaris committed Feb 10, 2023
1 parent 42249a8 commit a493c12
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.scheduler.BukkitTask;

import com.bgsoftware.wildstacker.api.WildStackerAPI;
Expand Down Expand Up @@ -445,10 +443,16 @@ private void scanChests(Chunk chunk) {
}

private void countItemStack(ItemStack i) {
if (i != null && i.getType().isBlock()) {
for (int c = 0; c < i.getAmount(); c++) {
checkBlock(i.getType(), false);
if (i == null || !i.getType().isBlock()) return;

for (int c = 0; c < i.getAmount(); c++) {
if (addon.getSettings().isIncludeShulkersInChest()
&& i.getItemMeta() instanceof BlockStateMeta blockStateMeta
&& blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBox) {
shulkerBox.getSnapshotInventory().forEach(this::countItemStack);
}

checkBlock(i.getType(), false);
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/world/bentobox/level/config/ConfigSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public class ConfigSettings implements ConfigObject {
@ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k")
@ConfigEntry(path = "shorthand")
private boolean shorthand = false;
@ConfigComment("")
@ConfigComment("Include Shulker Box content in chests in level calculations.")
@ConfigComment("Will count blocks in Shulker Boxes inside of chests.")
@ConfigComment("NOTE: include-chests needs to be enabled for this to work!.")
@ConfigEntry(path = "include-shulkers-in-chest")
private boolean includeShulkersInChest = false;


/**
Expand Down Expand Up @@ -385,4 +391,17 @@ public void setLogReportToConsole(boolean logReportToConsole) {
this.logReportToConsole = logReportToConsole;
}

/**
* @return includeShulkersInChest
*/
public boolean isIncludeShulkersInChest() {
return includeShulkersInChest;
}

/**
* @param includeShulkersInChest the includeChests to set
*/
public void setIncludeShulkersInChest(boolean includeShulkersInChest) {
this.includeShulkersInChest = includeShulkersInChest;
}
}

0 comments on commit a493c12

Please sign in to comment.