Added tree_cutter_universal_logs tree chopping config (#228).
This commit is contained in:
parent
7df8dce5e3
commit
1e2c8fe7eb
5 changed files with 54 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"homepage": "https://www.curseforge.com/minecraft/mc-mods/engineers-decor/",
|
||||
"1.19.2": {
|
||||
"1.3.28": "[F] Steel Mesh Fence help typo fixed (issue #227, ty shrad).\n[A] Added \"tree_cutter_universal_logs\" server config to enable chopping of modded resource wood blocks (e.g. rubber, issue #228).",
|
||||
"1.3.27": "[F] Refactored deprecated forge capability references.\n[F] Fixed Factory Hopper on-break item retention bug (issue #226, ty sunekaer/ftb).",
|
||||
"1.3.26": "[U] Ported to 1.19.2.\n[F] Fixed Mineral Melting Furnace fluid extraction (issue #223, ty adkinss).",
|
||||
"1.2.25": "[U] Ported to 1.19.1.",
|
||||
|
@ -62,7 +63,7 @@
|
|||
"1.1.2-b1": "[U] Ported to MC1.16.2."
|
||||
},
|
||||
"promos": {
|
||||
"1.19.2-recommended": "1.3.27",
|
||||
"1.19.2-latest": "1.3.27"
|
||||
"1.19.2-recommended": "1.3.28",
|
||||
"1.19.2-latest": "1.3.28"
|
||||
}
|
||||
}
|
|
@ -11,7 +11,9 @@ Mod sources for Minecraft version 1.18.x.
|
|||
|
||||
## Version history
|
||||
|
||||
~ v1.3.28 [F] Steel Mesh Fence help typo fixed (issue #227, ty shrad).
|
||||
- v1.3.28 [F] Steel Mesh Fence help typo fixed (issue #227, ty shrad).
|
||||
[A] Added "tree_cutter_universal_logs" server config to enable chopping of modded
|
||||
resource wood blocks (e.g. rubber, issue #228).
|
||||
|
||||
- v1.3.27 [F] Refactored deprecated forge capability references.
|
||||
[F] Fixed Factory Hopper on-break item retention bug (issue #226, ty sunekaer/ftb).
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import wile.engineersdecor.blocks.*;
|
||||
import wile.engineersdecor.detail.TreeCutting;
|
||||
import wile.engineersdecor.libmc.SlabSliceBlock;
|
||||
import wile.engineersdecor.libmc.VariantSlabBlock;
|
||||
import wile.engineersdecor.libmc.Auxiliaries;
|
||||
|
@ -139,6 +140,7 @@ public class ModConfig
|
|||
public final ForgeConfigSpec.IntValue tree_cutter_energy_consumption;
|
||||
public final ForgeConfigSpec.IntValue tree_cutter_cutting_time_needed;
|
||||
public final ForgeConfigSpec.BooleanValue tree_cutter_requires_power;
|
||||
public final ForgeConfigSpec.ConfigValue<List<String>> tree_cutter_universal_logs;
|
||||
public final ForgeConfigSpec.IntValue milking_machine_energy_consumption;
|
||||
public final ForgeConfigSpec.IntValue milking_machine_milking_delay;
|
||||
|
||||
|
@ -299,6 +301,10 @@ public class ModConfig
|
|||
.translation(MODID + ".config.tree_cutter_requires_power")
|
||||
.comment("Defines if the Small Tree Cutter does not work without RF power.")
|
||||
.define("tree_cutter_requires_power", false);
|
||||
tree_cutter_universal_logs = builder
|
||||
.translation(MODID + ".config.tree_cutter_universal_logs")
|
||||
.comment("Defines a list of resource locations which blocks are always to be treated as part of a tree. This is usefull for special log blocks containing resources like rubber.")
|
||||
.define("tree_cutter_universal_logs", new ArrayList<>());
|
||||
milking_machine_energy_consumption = builder
|
||||
.translation(MODID + ".config.milking_machine_energy_consumption")
|
||||
.comment("Defines how much time the Small Milking Machine needs work. " +
|
||||
|
@ -449,6 +455,13 @@ public class ModConfig
|
|||
EdMineralSmelter.on_config(144, 2);
|
||||
EdWasteIncinerator.on_config(8);
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
final List<String> universal_logs = new ArrayList<>(SERVER.tree_cutter_universal_logs.get());
|
||||
// Fixed known blocks. @todo, also check AE/menril, etc.
|
||||
universal_logs.add("myrtrees:filled_rubberwood_log");
|
||||
TreeCutting.on_config(universal_logs);
|
||||
}
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
// Check if the config is already synchronized or has to be synchronised.
|
||||
server_config_.putBoolean("tree_cutter_requires_power", SERVER.tree_cutter_requires_power.get());
|
||||
|
|
|
@ -233,7 +233,7 @@ public class EdTreeCutter
|
|||
if(!(device_state.getBlock() instanceof TreeCutterBlock)) return;
|
||||
final BlockPos tree_pos = worldPosition.relative(device_state.getValue(TreeCutterBlock.HORIZONTAL_FACING));
|
||||
final BlockState tree_state = level.getBlockState(tree_pos);
|
||||
if(!TreeCutting.canChop(tree_state) || (level.hasNeighborSignal(worldPosition))) {
|
||||
if(!TreeCutting.canChop(level, tree_state, tree_pos) || (level.hasNeighborSignal(worldPosition))) {
|
||||
if(device_state.getValue(TreeCutterBlock.ACTIVE)) level.setBlock(worldPosition, device_state.setValue(TreeCutterBlock.ACTIVE, false), 1|2);
|
||||
proc_time_elapsed_ = 0;
|
||||
active_timer_ = 0;
|
||||
|
|
|
@ -11,6 +11,7 @@ package wile.engineersdecor.detail;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
@ -18,14 +19,37 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.LeavesBlock;
|
||||
import net.minecraft.world.level.block.VineBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import wile.engineersdecor.libmc.Auxiliaries;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class TreeCutting
|
||||
{
|
||||
public static boolean canChop(BlockState state)
|
||||
{ return isLog(state); }
|
||||
private static final Set<Block> universal_logs_ = new HashSet<>();
|
||||
|
||||
public static void on_config(List<String> universal_logs)
|
||||
{
|
||||
universal_logs_.clear();
|
||||
if(universal_logs.isEmpty()) return;
|
||||
try {
|
||||
universal_logs.forEach(rls->{
|
||||
final ResourceLocation rl = ResourceLocation.tryParse(rls);
|
||||
if((rl == null) || (!ForgeRegistries.BLOCKS.containsKey(rl))) return;
|
||||
universal_logs_.add(ForgeRegistries.BLOCKS.getValue(rl));
|
||||
});
|
||||
} catch(Throwable ex) {
|
||||
Auxiliaries.logError("Unexpected exception parsing universal log blocks: " + ex.getMessage());
|
||||
}
|
||||
if(!universal_logs_.isEmpty()) {
|
||||
Auxiliaries.logger().info("Tree cutting: Universal logs:" + universal_logs_.stream().map(Block::toString).collect(Collectors.joining()) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canChop(Level world, BlockState state, BlockPos pos)
|
||||
{ return isLog(state) || (universal_logs_.contains(state.getBlock()) && isLog(world.getBlockState(pos.above()))); }
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -39,7 +63,11 @@ public class TreeCutting
|
|||
{ return (state.is(BlockTags.LOGS)); }
|
||||
|
||||
private static boolean isSameLog(BlockState a, BlockState b)
|
||||
{ return (a.getBlock()==b.getBlock()); }
|
||||
{
|
||||
final Block ba = a.getBlock();
|
||||
final Block bb = b.getBlock();
|
||||
return (ba==bb) || (universal_logs_.contains(ba) && isLog(b)) || (universal_logs_.contains(bb) && isLog(a)) || (universal_logs_.contains(ba) && universal_logs_.contains(bb));
|
||||
}
|
||||
|
||||
private static boolean isLeaves(BlockState state)
|
||||
{
|
||||
|
@ -75,7 +103,9 @@ public class TreeCutting
|
|||
|
||||
public static int chopTree(Level world, BlockState broken_state, BlockPos startPos, int max_blocks_to_break, boolean without_target_block)
|
||||
{
|
||||
if(world.isClientSide || !isLog(broken_state)) return 0;
|
||||
if(world.isClientSide) return 0;
|
||||
if(universal_logs_.contains(broken_state.getBlock())) broken_state = world.getBlockState(startPos.above()); // For safe detection, at least the block above must be a normal log block.
|
||||
if(!isLog(broken_state)) return 0;
|
||||
final long ymin = startPos.getY();
|
||||
final long max_leaf_distance = 8;
|
||||
Set<BlockPos> checked = new HashSet<>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue