Skip to content

Commit

Permalink
Prevent placing unsafe blocks and also prepare for breaking blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Oct 16, 2023
1 parent ece6ad3 commit b2aa402
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void tick(BotConnection connection) {
var heldSlot = playerInventory.getHotbarSlot(inventoryManager.getHeldItemSlot());
if (heldSlot.item() != null) {
var item = heldSlot.item();
if (ItemTypeHelper.isFullBlockItem(item.getType())) {
if (ItemTypeHelper.isSafeFullBlockItem(item.getType())) {
putOnHotbar = true;
return;
}
Expand All @@ -96,7 +96,7 @@ public void tick(BotConnection connection) {
}

var item = hotbarSlot.item();
if (!ItemTypeHelper.isFullBlockItem(item.getType())) {
if (!ItemTypeHelper.isSafeFullBlockItem(item.getType())) {
continue;
}

Expand All @@ -112,7 +112,7 @@ public void tick(BotConnection connection) {
}

var item = slot.item();
if (!ItemTypeHelper.isFullBlockItem(item.getType())) {
if (!ItemTypeHelper.isSafeFullBlockItem(item.getType())) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ProjectedInventory(PlayerInventoryContainer playerInventory) {
continue;
}

if (ItemTypeHelper.isFullBlockItem(slot.item().getType())) {
if (ItemTypeHelper.isSafeFullBlockItem(slot.item().getType())) {
blockItems += slot.item().getAmount();
} else if (ItemTypeHelper.isTool(slot.item().getType())) {
usableToolsAndNull.add(slot.item());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ public static boolean isHurtOnTouch(BlockType type) {
|| type == BlockType.SOUL_FIRE
|| type == BlockType.LAVA;
}

public static boolean isUnsafe(BlockType type) {
return type == BlockType.SAND
|| type == BlockType.GRAVEL
|| type == BlockType.ANVIL
|| type == BlockType.CHIPPED_ANVIL
|| type == BlockType.DAMAGED_ANVIL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ public class ItemTypeHelper {
private ItemTypeHelper() {
}

public static boolean isFullBlockItem(ItemType type) {
return BlockItems.getBlockType(type).isPresent();
public static boolean isSafeFullBlockItem(ItemType type) {
return BlockItems.getBlockType(type).isPresent() && !isUnsafeToPlace(type);
}

public static boolean isTool(ItemType type) {
return TierType.getTier(type).isPresent() || type == ItemType.SHEARS;
}

public static boolean isUnsafeToPlace(ItemType type) {
return type == ItemType.SAND
|| type == ItemType.GRAVEL;
}
}

0 comments on commit b2aa402

Please sign in to comment.