From 6984a356f82ad6f73dbb2c10efb1db1b324176cf Mon Sep 17 00:00:00 2001 From: lothrazar Date: Fri, 1 Nov 2024 16:16:49 -0700 Subject: [PATCH] add data tags for miner and breaker so you can ignore custom blocks via datapack & modpack --- .../cyclic/block/breaker/TileBreaker.java | 15 +++++++++++---- .../cyclic/block/miner/TileMiner.java | 18 ++++++++++++------ .../com/lothrazar/cyclic/data/DataTags.java | 2 ++ .../cyclic/tags/blocks/ignored/breaker.json | 6 ++++++ .../data/cyclic/tags/blocks/ignored/miner.json | 6 ++++++ update.json | 2 +- 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/data/cyclic/tags/blocks/ignored/breaker.json create mode 100644 src/main/resources/data/cyclic/tags/blocks/ignored/miner.json diff --git a/src/main/java/com/lothrazar/cyclic/block/breaker/TileBreaker.java b/src/main/java/com/lothrazar/cyclic/block/breaker/TileBreaker.java index ea4872763..89a9fb8f6 100644 --- a/src/main/java/com/lothrazar/cyclic/block/breaker/TileBreaker.java +++ b/src/main/java/com/lothrazar/cyclic/block/breaker/TileBreaker.java @@ -1,6 +1,8 @@ package com.lothrazar.cyclic.block.breaker; +import com.lothrazar.cyclic.ModCyclic; import com.lothrazar.cyclic.base.TileEntityBase; +import com.lothrazar.cyclic.data.DataTags; import com.lothrazar.cyclic.registry.TileRegistry; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -43,7 +45,7 @@ public void tick() { return; } BlockPos target = pos.offset(this.getCurrentFacing()); - if (this.isValid(target)) { + if (this.isTargetValid(target)) { this.world.destroyBlock(target, true); } } @@ -51,13 +53,18 @@ public void tick() { /** * Avoid mining source liquid blocks and unbreakable */ - private boolean isValid(BlockPos target) { + private boolean isTargetValid(BlockPos targetPos) { World level = world; - BlockState state = level.getBlockState(target); + BlockState state = level.getBlockState(targetPos); if (state.getBlock() == Blocks.AIR) { return false; } - if (state.getBlockHardness(level, target) < 0) { + if (state.getBlockHardness(level, targetPos) < 0) { + return false; + } + //check the tag ignore list so modpack/datapack can filter this + if (state.isIn(DataTags.BREAKER_IGNORED)) { + ModCyclic.LOGGER.info("breaker/ignored tag skips " + targetPos); return false; } if (state.getFluidState() != null && state.getFluidState().isEmpty() == false) { diff --git a/src/main/java/com/lothrazar/cyclic/block/miner/TileMiner.java b/src/main/java/com/lothrazar/cyclic/block/miner/TileMiner.java index fa4ee7d54..ab5a3aefa 100644 --- a/src/main/java/com/lothrazar/cyclic/block/miner/TileMiner.java +++ b/src/main/java/com/lothrazar/cyclic/block/miner/TileMiner.java @@ -3,6 +3,7 @@ import com.lothrazar.cyclic.ModCyclic; import com.lothrazar.cyclic.base.TileEntityBase; import com.lothrazar.cyclic.capability.CustomEnergyStorage; +import com.lothrazar.cyclic.data.DataTags; import com.lothrazar.cyclic.data.PreviewOutlineType; import com.lothrazar.cyclic.item.datacard.BlockStateMatcher; import com.lothrazar.cyclic.item.datacard.BlockstateCard; @@ -262,24 +263,29 @@ private boolean isTargetValid() { return false; //dont mine air or liquid. } //is this valid - BlockState blockSt = world.getBlockState(targetPos); - if (blockSt.hardness < 0) { + BlockState state = world.getBlockState(targetPos); + if (state.hardness < 0) { return false; //unbreakable } + //check the tag ignore list so modpack/datapack can filter this + if (state.isIn(DataTags.MINER_IGNORED)) { + ModCyclic.LOGGER.info("miner/ignored tag skips " + targetPos); + return false; + } //water logged is - if (blockSt.getFluidState() != null && blockSt.getFluidState().isEmpty() == false) { + if (state.getFluidState() != null && state.getFluidState().isEmpty() == false) { //am i PURE liquid? or just a WATERLOGGED block - if (blockSt.hasProperty(BlockStateProperties.WATERLOGGED) == false) { + if (state.hasProperty(BlockStateProperties.WATERLOGGED) == false) { // ModCyclic.LOGGER.info(targetPos + " Mining FLUID is not valid " + blockSt); //pure liquid. but this will make canHarvestBlock go true , which is a lie actually so, no. dont get stuck here return false; } } - if (!this.isValidTarget(blockSt)) { + if (!this.isValidTarget(state)) { return false; } //its a solid non-air, non-fluid block (but might be like waterlogged stairs or something) - boolean canHarvest = blockSt.canHarvestBlock(world, targetPos, fakePlayer.get()); + boolean canHarvest = state.canHarvestBlock(world, targetPos, fakePlayer.get()); if (!canHarvest) { // ModCyclic.LOGGER.info(targetPos + " Mining target is not valid " + blockSt); } diff --git a/src/main/java/com/lothrazar/cyclic/data/DataTags.java b/src/main/java/com/lothrazar/cyclic/data/DataTags.java index b976a8ff1..1cd730a38 100644 --- a/src/main/java/com/lothrazar/cyclic/data/DataTags.java +++ b/src/main/java/com/lothrazar/cyclic/data/DataTags.java @@ -22,6 +22,8 @@ public class DataTags { public static final INamedTag CACTUS = BlockTags.makeWrapperTag("forge:cactus"); public static final INamedTag CROP_BLOCKS = BlockTags.makeWrapperTag("forge:crop_blocks"); public static final INamedTag EXCAVATE_IGNORED = BlockTags.makeWrapperTag("cyclic:ignored/excavate"); + public static final INamedTag BREAKER_IGNORED = BlockTags.makeWrapperTag("cyclic:ignored/breaker"); + public static final INamedTag MINER_IGNORED = BlockTags.makeWrapperTag("cyclic:ignored/miner"); public static final INamedTag FISHING_RODS = ItemTags.makeWrapperTag("forge:fishing_rods"); public static final INamedTag BOOKS = ItemTags.makeWrapperTag("forge:books"); public static final INamedTag ANVIL_IMMUNE = ItemTags.makeWrapperTag("cyclic:anvil_immune"); diff --git a/src/main/resources/data/cyclic/tags/blocks/ignored/breaker.json b/src/main/resources/data/cyclic/tags/blocks/ignored/breaker.json new file mode 100644 index 000000000..4355fff9f --- /dev/null +++ b/src/main/resources/data/cyclic/tags/blocks/ignored/breaker.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + {"required":false, "id": "minecraft:command_block"} + ] +} \ No newline at end of file diff --git a/src/main/resources/data/cyclic/tags/blocks/ignored/miner.json b/src/main/resources/data/cyclic/tags/blocks/ignored/miner.json new file mode 100644 index 000000000..731a9f0c3 --- /dev/null +++ b/src/main/resources/data/cyclic/tags/blocks/ignored/miner.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "#cyclic:ignored/breaker" + ] +} \ No newline at end of file diff --git a/update.json b/update.json index ae61720ab..4743fe5bd 100644 --- a/update.json +++ b/update.json @@ -81,6 +81,6 @@ ,"1.5.22":"Fix #2351 advanced crafting stick not opening. " ,"1.5.23":"Growth enchantment now uses the same logic as Sprinkler & Terra Soil (only minecraft:crops or minecraft::saplings can grow, respect IGrowable::canUseBonemeal). New gloomIgnored config Gloom enchant (cyclic:curse) to ignore and not use these effects #2217 #2325. Fix Soundproofing block not muting Mekanism sounds #2389 (for example Precision Sawmill and others - you may need four or more soundproofing blocks for the desired effect). Patch an edge-case where User might drop items on the ground. New config [cyclic.blocks.soundproofing] radius = 6 to control the area. Fix item cable routing #2245 #2230. New config under [cyclic.blocks] wireless_transfer_dimensional = true allowing transfer nodes to connect across dimensions #1913. Balance recipe changes for #2372. Balance changes made for Excavate enchant it will no longer trigger if the tool is not 'mineable' effective for example axe on dirt. New feature for Excavate enchant #2116 it will not trigger on anything matching the block data-tag 'cyclic:ignored/excavate'. [Backported changes from mc1.20.1] #2182 candle model assets; Block Breaker no longer tries (and fails) to mine liquid source blocks; Block Randomizer use wireframe rendering only of non-air instead of solid shading; Glistering & Corrupted chorus only restores 1 food-unit down from 3; a few recipes tweaked/backported to match mc1.20.1+, ported crafttweaker zenscript support for generator_fluid and generator_item; backported item data tags for use in recipes for example forge:vines, forge:sandstone, forge:mushrooms " ,"1.5.24":"Fixed bug in the item cyclic:offset_scepter #2427. Tweaked block model visuals of the Transfer Nodes. Fix Mattock not saving contents of Shulker Boxes when mined #2411. " - ,"":"Many blocks now allow minecraft:comparator to pull a redstone signal based on inventory contents. Fluid collector will now place air and scoop up the fluid if the itemslot is empty. New feature: some machines can now be placed facing Up or Down vertically for convenience (harvester, forester, miner, item collector, fluid collector, dropper). Backported machine feature 'Preview Outline' mode on machines that already have the button. Backported cable (fluid & energy) buffer and flow speed configs from 1.20.1 " + ,"":"Add new block data tags cyclic:ignored/breaker and cyclic:ignored/miner so that pack devs can customize these machines to not break certain blocks. Many blocks now allow minecraft:comparator to pull a redstone signal based on inventory contents. Fluid collector will now place air and scoop up the fluid if the itemslot is empty. New feature: some machines can now be placed facing Up or Down vertically for convenience (harvester, forester, miner, item collector, fluid collector, dropper). Backported machine feature 'Preview Outline' mode on machines that already have the button. Backported cable (fluid & energy) buffer and flow speed configs from 1.20.1 " } }