Skip to content

Commit

Permalink
add data tags for miner and breaker so you can ignore custom blocks v…
Browse files Browse the repository at this point in the history
…ia datapack & modpack
  • Loading branch information
Lothrazar committed Nov 1, 2024
1 parent ef5697e commit 6984a35
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
15 changes: 11 additions & 4 deletions src/main/java/com/lothrazar/cyclic/block/breaker/TileBreaker.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,21 +45,26 @@ public void tick() {
return;
}
BlockPos target = pos.offset(this.getCurrentFacing());
if (this.isValid(target)) {
if (this.isTargetValid(target)) {
this.world.destroyBlock(target, true);
}
}

/**
* 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) {
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/lothrazar/cyclic/block/miner/TileMiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/lothrazar/cyclic/data/DataTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class DataTags {
public static final INamedTag<Block> CACTUS = BlockTags.makeWrapperTag("forge:cactus");
public static final INamedTag<Block> CROP_BLOCKS = BlockTags.makeWrapperTag("forge:crop_blocks");
public static final INamedTag<Block> EXCAVATE_IGNORED = BlockTags.makeWrapperTag("cyclic:ignored/excavate");
public static final INamedTag<Block> BREAKER_IGNORED = BlockTags.makeWrapperTag("cyclic:ignored/breaker");
public static final INamedTag<Block> MINER_IGNORED = BlockTags.makeWrapperTag("cyclic:ignored/miner");
public static final INamedTag<Item> FISHING_RODS = ItemTags.makeWrapperTag("forge:fishing_rods");
public static final INamedTag<Item> BOOKS = ItemTags.makeWrapperTag("forge:books");
public static final INamedTag<Item> ANVIL_IMMUNE = ItemTags.makeWrapperTag("cyclic:anvil_immune");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
{"required":false, "id": "minecraft:command_block"}
]
}
6 changes: 6 additions & 0 deletions src/main/resources/data/cyclic/tags/blocks/ignored/miner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"#cyclic:ignored/breaker"
]
}
2 changes: 1 addition & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
}
}

0 comments on commit 6984a35

Please sign in to comment.