From 9205aa09ceb82f0d6eb9450d10e1caa8585c7561 Mon Sep 17 00:00:00 2001 From: Thomas Couchoud Date: Mon, 27 Apr 2020 20:52:54 +0200 Subject: [PATCH] Backport to 1.12.2 --- CHANGELOG.md | 4 +- build.gradle | 51 ++++++-------- changes.md | 3 +- gradle.properties | 12 ++-- .../raksrinana/fallingtree/FallingTree.java | 29 ++------ .../fallingtree/ForgeEventSubscriber.java | 67 ++++++++++--------- .../fallingtree/LeafBreakingSchedule.java | 8 +-- .../fallingtree/config/CommonConfig.java | 43 ++++++------ .../raksrinana/fallingtree/config/Config.java | 18 ----- .../fallingtree/config/ToolConfiguration.java | 54 +++++++++------ .../fallingtree/config/TreeConfiguration.java | 65 +++++++++++------- .../fallingtree/tree/TreeHandler.java | 58 ++++++++-------- src/main/resources/META-INF/mods.toml | 27 -------- src/main/resources/mcmod.info | 14 ++++ src/main/resources/pack.mcmeta | 6 -- update.json | 13 ++-- 16 files changed, 214 insertions(+), 258 deletions(-) delete mode 100644 src/main/java/fr/raksrinana/fallingtree/config/Config.java delete mode 100644 src/main/resources/META-INF/mods.toml create mode 100644 src/main/resources/mcmod.info delete mode 100644 src/main/resources/pack.mcmeta diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c404ede..f2244767 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.12.2-2.1.0] - 2020-04-27 +- Backport to 1.12.2 + ## [1.15.2-2.1.0] - 2020-03-08 - Refactor configuration by using categories thus making it a bit clearer than having everything stacked up at the same place. (/!\ You may have to redo your configuration if you changed values so back up the configuration before updating in order to copy values after) - Break leaves without sound when using force breaking leaves (the option with the radius) to avoid breaking your ears (#7) @@ -10,4 +13,3 @@ ## [1.15.2-2.0.2] - 2020-01-23 - Port to 1.15.2 - diff --git a/build.gradle b/build.gradle index dfc688b9..090b2fc3 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { mavenCentral() } dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' } } @@ -25,7 +25,7 @@ buildProperties { } apply plugin: 'scala' -apply plugin: 'net.minecraftforge.gradle' +apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'eclipse' apply plugin: "com.github.breadmoirai.github-release" @@ -56,36 +56,9 @@ def build_num = getBuildNumber() sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' minecraft { - mappings channel: project.mcp_channel.toString(), version: project.mcp_mappings.toString() - - runs { - client { - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - property 'forge.logging.console.level', 'debug' - workingDirectory project.file('run-client') - - mods { - edit_sign { - source sourceSets.main - } - } - } - - server { - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - property 'forge.logging.console.level', 'debug' - workingDirectory project.file('run-server') - mods { - edit_sign { - source sourceSets.main - } - } - } - } -} - -dependencies { - minecraft "net.minecraftforge:forge:${project.forge_version}" + version = "${project.forge_version}" + runDir = "run" + mappings = "${project.mcp_channel}_${project.mcp_mappings}" } jar { @@ -101,6 +74,20 @@ jar { } } +processResources { + inputs.property "version", version + inputs.property "mcversion", project.mc_version + + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version': version, 'mcversion': project.mc_version + } + + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} + task deobfJar(type: Jar) { appendix = "${project.mc_version}" classifier = 'deobf' diff --git a/changes.md b/changes.md index 62bd8b13..b1e31479 100644 --- a/changes.md +++ b/changes.md @@ -1,2 +1 @@ -- Refactor configuration by using categories thus making it a bit clearer than having everything stacked up at the same place. (/!\ You may have to redo your configuration if you changed values so back up the configuration before updating in order to copy values after) -- Break leaves without sound when using force breaking leaves (the option with the radius) to avoid breaking your ears (#7) +- Backport to 1.12.2 \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 56fae3a3..f58abde2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,16 +9,16 @@ mod_id = falling_tree repoName = FallingTree name = Falling Tree vcsUrl = https://github.com/RakSrinaNa/FallingTree.git -changelogUrl = https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md +changelogUrl = https://github.com/RakSrinaNa/FallingTree/blob/1.12.2/CHANGELOG.md -mc_version = 1.15.2 +mc_version = 1.12.2 -forge_version = 1.15.2-31.1.18 -mcp_channel=snapshot -mcp_mappings=20200308-1.15.1 +forge_version = 1.12.2-14.23.5.2847 +mcp_channel=stable +mcp_mappings=39 curseforge_project_id=349559 -curseforge_release_type=release +curseforge_release_type=beta doDeobfJar = true doSourceJar = true diff --git a/src/main/java/fr/raksrinana/fallingtree/FallingTree.java b/src/main/java/fr/raksrinana/fallingtree/FallingTree.java index 1886b000..a259daf3 100644 --- a/src/main/java/fr/raksrinana/fallingtree/FallingTree.java +++ b/src/main/java/fr/raksrinana/fallingtree/FallingTree.java @@ -1,34 +1,13 @@ package fr.raksrinana.fallingtree; -import fr.raksrinana.fallingtree.config.Config; -import net.minecraftforge.fml.ModContainer; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.forgespi.language.IModInfo; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import javax.annotation.Nonnull; +import java.util.logging.LogManager; +import java.util.logging.Logger; -@Mod(FallingTree.MOD_ID) +@Mod(modid = FallingTree.MOD_ID, version = FallingTree.VERSION) public class FallingTree{ public static final String MOD_ID = "falling_tree"; public static final String MOD_NAME = "Falling Tree"; public static final String VERSION = "2.1.0"; - public static final Logger LOGGER = LogManager.getLogger(MOD_ID); - - public FallingTree(){ - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.COMMON_SPEC); - } - - @Nonnull - public static String getVersion(){ - return ModList.get().getModContainerById(MOD_ID).map(ModContainer::getModInfo).map(IModInfo::getVersion).map(ArtifactVersion::toString).orElse("NONE"); - } - - public static boolean isDevBuild(){ - return "NONE".equals(getVersion()); - } + public static final Logger LOGGER = LogManager.getLogManager().getLogger(MOD_ID); } diff --git a/src/main/java/fr/raksrinana/fallingtree/ForgeEventSubscriber.java b/src/main/java/fr/raksrinana/fallingtree/ForgeEventSubscriber.java index 9129ae21..20da4a27 100644 --- a/src/main/java/fr/raksrinana/fallingtree/ForgeEventSubscriber.java +++ b/src/main/java/fr/raksrinana/fallingtree/ForgeEventSubscriber.java @@ -1,54 +1,55 @@ package fr.raksrinana.fallingtree; -import fr.raksrinana.fallingtree.config.Config; +import fr.raksrinana.fallingtree.config.CommonConfig; +import fr.raksrinana.fallingtree.config.TreeConfiguration; import fr.raksrinana.fallingtree.tree.TreeHandler; import io.netty.util.internal.ConcurrentSet; import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; +import net.minecraft.block.BlockLeaves; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.event.TickEvent; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.world.WorldServer; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.LogicalSide; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.Side; import javax.annotation.Nonnull; import java.util.Iterator; +import java.util.Objects; import java.util.Set; -@Mod.EventBusSubscriber(modid = FallingTree.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) +@Mod.EventBusSubscriber(modid = FallingTree.MOD_ID) public final class ForgeEventSubscriber{ private static final Set scheduledLeavesBreaking = new ConcurrentSet<>(); @SubscribeEvent public static void onBlockBreakEvent(@Nonnull BlockEvent.BreakEvent event){ - if(!event.isCanceled() && !event.getWorld().isRemote()){ - if(isPlayerInRightState(event.getPlayer()) && event.getWorld() instanceof World){ - TreeHandler.getTree((World) event.getWorld(), event.getPos()).ifPresent(tree -> { - if(Config.COMMON.getTreesConfiguration().getMaxSize() >= tree.getLogCount()){ - if(TreeHandler.destroy(tree, event.getPlayer(), event.getPlayer().getHeldItem(Hand.MAIN_HAND))){ + if(!event.isCanceled() && !event.getWorld().isRemote){ + if(isPlayerInRightState(event.getPlayer()) && Objects.nonNull(event.getWorld())){ + TreeHandler.getTree(event.getWorld(), event.getPos()).ifPresent(tree -> { + if(TreeConfiguration.getMaxSize() >= tree.getLogCount()){ + if(TreeHandler.destroy(tree, event.getPlayer(), event.getPlayer().getHeldItem(EnumHand.MAIN_HAND))){ event.setCanceled(true); } } else{ - event.getPlayer().sendMessage(new TranslationTextComponent("chat.falling_tree.tree_too_big", tree.getLogCount(), Config.COMMON.getTreesConfiguration().getMaxSize())); + event.getPlayer().sendMessage(new TextComponentTranslation("chat.falling_tree.tree_too_big", tree.getLogCount(), TreeConfiguration.getMaxSize())); } }); } } } - private static boolean isPlayerInRightState(PlayerEntity player){ - if(player.abilities.isCreativeMode && !FallingTree.isDevBuild()){ + private static boolean isPlayerInRightState(EntityPlayer player){ + if(player.isCreative()){ return false; } - if(Config.COMMON.isReverseSneaking() != player.isCrouching()){ + if(CommonConfig.reverseSneaking != player.isSneaking()){ return false; } return TreeHandler.canPlayerBreakTree(player); @@ -56,17 +57,17 @@ private static boolean isPlayerInRightState(PlayerEntity player){ @SubscribeEvent public static void onNeighborNotifyEvent(BlockEvent.NeighborNotifyEvent event){ - if(Config.COMMON.getTreesConfiguration().isLavesBreaking() && !event.getWorld().isRemote()){ - ServerWorld world = (ServerWorld) event.getWorld(); - BlockState eventState = event.getState(); + if(TreeConfiguration.isLavesBreaking() && !event.getWorld().isRemote){ + WorldServer world = (WorldServer) event.getWorld(); + IBlockState eventState = event.getState(); Block eventBlock = eventState.getBlock(); BlockPos eventPos = event.getPos(); if(eventBlock.isAir(eventState, world, eventPos)){ - for(Direction facing : event.getNotifiedSides()){ + for(EnumFacing facing : event.getNotifiedSides()){ BlockPos neighborPos = eventPos.offset(facing); if(world.isBlockLoaded(neighborPos)){ - BlockState neighborState = event.getWorld().getBlockState(neighborPos); - if(BlockTags.LEAVES.contains(neighborState.getBlock())){ + IBlockState neighborState = event.getWorld().getBlockState(neighborPos); + if(neighborState.getBlock() instanceof BlockLeaves){ scheduledLeavesBreaking.add(new LeafBreakingSchedule(world, neighborPos, 4)); } } @@ -77,17 +78,17 @@ public static void onNeighborNotifyEvent(BlockEvent.NeighborNotifyEvent event){ @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event){ - if(event.side == LogicalSide.SERVER && event.phase == TickEvent.Phase.END){ + if(event.side == Side.SERVER && event.phase == TickEvent.Phase.END){ Iterator leavesBreak = scheduledLeavesBreaking.iterator(); while(leavesBreak.hasNext()){ LeafBreakingSchedule leafBreakingSchedule = leavesBreak.next(); - ServerWorld world = leafBreakingSchedule.getWorld(); + WorldServer world = leafBreakingSchedule.getWorld(); if(leafBreakingSchedule.getRemainingTicks() <= 0){ if(world.isBlockLoaded(leafBreakingSchedule.getBlockPos())){ - BlockState state = world.getBlockState(leafBreakingSchedule.getBlockPos()); + IBlockState state = world.getBlockState(leafBreakingSchedule.getBlockPos()); Block block = state.getBlock(); - if(BlockTags.LEAVES.contains(block)){ - block.randomTick(state, world, leafBreakingSchedule.getBlockPos(), world.getRandom()); + if(block instanceof BlockLeaves){ + block.randomTick(world, leafBreakingSchedule.getBlockPos(), state, world.rand); } else{ leavesBreak.remove(); diff --git a/src/main/java/fr/raksrinana/fallingtree/LeafBreakingSchedule.java b/src/main/java/fr/raksrinana/fallingtree/LeafBreakingSchedule.java index 2d9cfacd..68b12a8a 100644 --- a/src/main/java/fr/raksrinana/fallingtree/LeafBreakingSchedule.java +++ b/src/main/java/fr/raksrinana/fallingtree/LeafBreakingSchedule.java @@ -1,15 +1,15 @@ package fr.raksrinana.fallingtree; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.world.WorldServer; import java.util.Objects; public class LeafBreakingSchedule{ - private final ServerWorld world; + private final WorldServer world; private final BlockPos blockPos; private int remainingTicks; - public LeafBreakingSchedule(ServerWorld world, BlockPos blockPos, int remainingTicks){ + public LeafBreakingSchedule(WorldServer world, BlockPos blockPos, int remainingTicks){ this.world = world; this.blockPos = blockPos; this.remainingTicks = remainingTicks; @@ -27,7 +27,7 @@ public BlockPos getBlockPos(){ return blockPos; } - public ServerWorld getWorld(){ + public WorldServer getWorld(){ return world; } diff --git a/src/main/java/fr/raksrinana/fallingtree/config/CommonConfig.java b/src/main/java/fr/raksrinana/fallingtree/config/CommonConfig.java index 89a39784..ee850002 100644 --- a/src/main/java/fr/raksrinana/fallingtree/config/CommonConfig.java +++ b/src/main/java/fr/raksrinana/fallingtree/config/CommonConfig.java @@ -1,27 +1,21 @@ package fr.raksrinana.fallingtree.config; +import fr.raksrinana.fallingtree.FallingTree; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.common.config.Config; +import net.minecraftforge.common.config.ConfigManager; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.registry.ForgeRegistries; import javax.annotation.Nullable; +@Config(modid = FallingTree.MOD_ID) public class CommonConfig{ - private final TreeConfiguration trees; - private final ToolConfiguration tools; - private final ForgeConfigSpec.BooleanValue reverseSneaking; - - public CommonConfig(ForgeConfigSpec.Builder builder){ - builder.comment("Falling Tree configuration"); - builder.push("trees"); - trees = new TreeConfiguration(builder); - builder.pop(); - builder.push("tools"); - tools = new ToolConfiguration(builder); - builder.pop(); - reverseSneaking = builder.comment("When set to true, a tree will only be chopped down if the player is sneaking").define("reverse_sneaking", false); - } + @Config.Name("reverse_sneaking") + @Config.Comment("When set to true, a tree will only be chopped down if the player is sneaking") + public static boolean reverseSneaking = false; @Nullable public static Block getBlock(String name){ @@ -43,15 +37,16 @@ public static Item getItem(String name){ } } - public ToolConfiguration getToolsConfiguration(){ - return this.tools; - } - - public TreeConfiguration getTreesConfiguration(){ - return this.trees; + public boolean isReverseSneaking(){ + return reverseSneaking; } - public boolean isReverseSneaking(){ - return this.reverseSneaking.get(); + @Mod.EventBusSubscriber(modid = FallingTree.MOD_ID) + private static class Handler{ + public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event){ + if(event.getModID().equals(FallingTree.MOD_ID)){ + ConfigManager.sync(FallingTree.MOD_ID, Config.Type.INSTANCE); + } + } } } diff --git a/src/main/java/fr/raksrinana/fallingtree/config/Config.java b/src/main/java/fr/raksrinana/fallingtree/config/Config.java deleted file mode 100644 index 665412fa..00000000 --- a/src/main/java/fr/raksrinana/fallingtree/config/Config.java +++ /dev/null @@ -1,18 +0,0 @@ -package fr.raksrinana.fallingtree.config; - -import fr.raksrinana.fallingtree.FallingTree; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.common.Mod; -import org.apache.commons.lang3.tuple.Pair; - -@Mod.EventBusSubscriber(modid = FallingTree.MOD_ID) -public class Config{ - public static final ForgeConfigSpec COMMON_SPEC; - public static final CommonConfig COMMON; - - static { - Pair commonPair = new ForgeConfigSpec.Builder().configure(CommonConfig::new); - COMMON = commonPair.getLeft(); - COMMON_SPEC = commonPair.getRight(); - } -} diff --git a/src/main/java/fr/raksrinana/fallingtree/config/ToolConfiguration.java b/src/main/java/fr/raksrinana/fallingtree/config/ToolConfiguration.java index a4cb881f..df1fcc09 100644 --- a/src/main/java/fr/raksrinana/fallingtree/config/ToolConfiguration.java +++ b/src/main/java/fr/raksrinana/fallingtree/config/ToolConfiguration.java @@ -1,38 +1,52 @@ package fr.raksrinana.fallingtree.config; -import com.google.common.collect.Lists; +import fr.raksrinana.fallingtree.FallingTree; import net.minecraft.item.Item; -import net.minecraftforge.common.ForgeConfigSpec; -import java.util.List; +import net.minecraftforge.common.config.Config; +import net.minecraftforge.common.config.ConfigManager; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.Mod; +import java.util.Arrays; import java.util.Objects; import java.util.stream.Stream; +@Config(modid = FallingTree.MOD_ID, category = "tools") public class ToolConfiguration{ - private final ForgeConfigSpec.ConfigValue> whitelisted; - private final ForgeConfigSpec.ConfigValue> blacklisted; - private final ForgeConfigSpec.BooleanValue ignoreDurabilityLoss; - private final ForgeConfigSpec.BooleanValue preserve; + @Config.Name("whitelisted") + @Config.Comment("Additional list of tools (those marked with the axe tag will already be whitelisted) that can be used to chop down a tree") + public static String[] whitelisted = {}; + @Config.Name("blacklisted") + @Config.Comment("List of tools that should not be considered as tools (this wins over the whitelist)") + public static String[] blacklisted = {}; + @Config.Name("ignore_durability") + @Config.Comment("Ignore the durability loss of breaking all the logs. If set to true, no harm will be done to the tool") + public static boolean ignoreDurabilityLoss = false; + @Config.Name("preserve") + @Config.Comment("When set to true, when a tree is broken and the tool is about to break we will just break one block and not the whole tree.") + public static boolean preserve = false; - public ToolConfiguration(ForgeConfigSpec.Builder builder){ - whitelisted = builder.comment("Additional list of tools (those marked with the axe tag will already be whitelisted) that can be used to chop down a tree").defineList("whitelisted", Lists.newArrayList(), Objects::nonNull); - blacklisted = builder.comment("List of tools that should not be considered as tools (this wins over the whitelist)").defineList("blacklisted", Lists.newArrayList(), Objects::nonNull); - ignoreDurabilityLoss = builder.comment("Ignore the durability loss of breaking all the logs. If set to true, no harm will be done to the tool").define("ignore_durability", false); - preserve = builder.comment("When set to true, when a tree is broken and the tool is about to break we will just break one block and not the whole tree.").define("preserve", false); + public static Stream getBlacklisted(){ + return Arrays.stream(blacklisted).map(CommonConfig::getItem).filter(Objects::nonNull); } - public Stream getBlacklisted(){ - return blacklisted.get().stream().map(CommonConfig::getItem).filter(Objects::nonNull); + public static Stream getWhitelisted(){ + return Arrays.stream(whitelisted).map(CommonConfig::getItem).filter(Objects::nonNull); } - public Stream getWhitelisted(){ - return whitelisted.get().stream().map(CommonConfig::getItem).filter(Objects::nonNull); + public static boolean isIgnoreDurabilityLoss(){ + return ignoreDurabilityLoss; } - public boolean isIgnoreDurabilityLoss(){ - return this.ignoreDurabilityLoss.get(); + public static boolean isPreserve(){ + return preserve; } - public boolean isPreserve(){ - return this.preserve.get(); + @Mod.EventBusSubscriber(modid = FallingTree.MOD_ID) + private static class Handler{ + public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event){ + if(event.getModID().equals(FallingTree.MOD_ID)){ + ConfigManager.sync(FallingTree.MOD_ID, Config.Type.INSTANCE); + } + } } } diff --git a/src/main/java/fr/raksrinana/fallingtree/config/TreeConfiguration.java b/src/main/java/fr/raksrinana/fallingtree/config/TreeConfiguration.java index a7758f5e..8f48bac6 100644 --- a/src/main/java/fr/raksrinana/fallingtree/config/TreeConfiguration.java +++ b/src/main/java/fr/raksrinana/fallingtree/config/TreeConfiguration.java @@ -1,44 +1,61 @@ package fr.raksrinana.fallingtree.config; -import com.google.common.collect.Lists; +import fr.raksrinana.fallingtree.FallingTree; import net.minecraft.block.Block; -import net.minecraftforge.common.ForgeConfigSpec; -import java.util.List; +import net.minecraftforge.common.config.Config; +import net.minecraftforge.common.config.ConfigManager; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.Mod; +import java.util.Arrays; import java.util.Objects; import java.util.stream.Stream; +@Config(modid = FallingTree.MOD_ID, category = "trees") public class TreeConfiguration{ - private final ForgeConfigSpec.ConfigValue> whitelistedLogs; - private final ForgeConfigSpec.ConfigValue> blacklistedLogs; - private final ForgeConfigSpec.IntValue maxSize; - private final ForgeConfigSpec.BooleanValue lavesBreaking; - private final ForgeConfigSpec.IntValue lavesBreakingForceRadius; + @Config.Name("logs_whitelisted") + @Config.Comment("Additional list of blocks (those marked with the log tag will already be whitelisted) considered as logs and that will be destroyed all at once") + public static String[] whitelistedLogs = {}; + @Config.Name("logs_blacklisted") + @Config.Comment("List of blocks that should not be considered as logs (this wins over the whitelist)") + public static String[] blacklistedLogs = {}; + @Config.Name("logs_max_count") + @Config.Comment("The maximum size of a tree. If there's more logs than this value the tree won't be cut.") + @Config.RangeInt(min = 1) + public static int maxSize = 100; + @Config.Name("leaves_breaking") + @Config.Comment("When set to true, leaves that should naturally break will be broken instantly") + public static boolean lavesBreaking = false; + @Config.Name("leaves_breaking_force_radius") + @Config.Comment("Radius to force break leaves. If another tree is still holding the leaves they'll still be broken. If the leaves are persistent (placed by player) they'll also be destroyed. The radius is applied from one of the top most log blocks. break_leaves must be activated for this to take effect.") + @Config.RangeInt(min = 0, max = 10) + public static int lavesBreakingForceRadius = 0; - public TreeConfiguration(ForgeConfigSpec.Builder builder){ - whitelistedLogs = builder.comment("Additional list of blocks (those marked with the log tag will already be whitelisted) considered as logs and that will be destroyed all at once").defineList("logs_whitelisted", Lists.newArrayList(), Objects::nonNull); - blacklistedLogs = builder.comment("List of blocks that should not be considered as logs (this wins over the whitelist)").defineList("logs_blacklisted", Lists.newArrayList(), Objects::nonNull); - maxSize = builder.comment("The maximum size of a tree. If there's more logs than this value the tree won't be cut.").defineInRange("logs_max_count", 100, 1, Integer.MAX_VALUE); - lavesBreaking = builder.comment("When set to true, leaves that should naturally break will be broken instantly").define("leaves_breaking", false); - lavesBreakingForceRadius = builder.comment("Radius to force break leaves. If another tree is still holding the leaves they'll still be broken. If the leaves are persistent (placed by player) they'll also be destroyed. The radius is applied from one of the top most log blocks. break_leaves must be activated for this to take effect.").defineInRange("leaves_breaking_force_radius", 0, 0, 10); + public static Stream getBlacklistedLogs(){ + return Arrays.stream(blacklistedLogs).map(CommonConfig::getBlock).filter(Objects::nonNull); } - public Stream getBlacklistedLogs(){ - return blacklistedLogs.get().stream().map(CommonConfig::getBlock).filter(Objects::nonNull); + public static int getLavesBreakingForceRadius(){ + return lavesBreakingForceRadius; } - public int getLavesBreakingForceRadius(){ - return this.lavesBreakingForceRadius.get(); + public static int getMaxSize(){ + return maxSize; } - public int getMaxSize(){ - return this.maxSize.get(); + public static Stream getWhitelistedLogs(){ + return Arrays.stream(whitelistedLogs).map(CommonConfig::getBlock).filter(Objects::nonNull); } - public Stream getWhitelistedLogs(){ - return whitelistedLogs.get().stream().map(CommonConfig::getBlock).filter(Objects::nonNull); + public static boolean isLavesBreaking(){ + return lavesBreaking; } - public boolean isLavesBreaking(){ - return this.lavesBreaking.get(); + @Mod.EventBusSubscriber(modid = FallingTree.MOD_ID) + private static class Handler{ + public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event){ + if(event.getModID().equals(FallingTree.MOD_ID)){ + ConfigManager.sync(FallingTree.MOD_ID, Config.Type.INSTANCE); + } + } } } diff --git a/src/main/java/fr/raksrinana/fallingtree/tree/TreeHandler.java b/src/main/java/fr/raksrinana/fallingtree/tree/TreeHandler.java index 038bf5b5..56d58f8b 100644 --- a/src/main/java/fr/raksrinana/fallingtree/tree/TreeHandler.java +++ b/src/main/java/fr/raksrinana/fallingtree/tree/TreeHandler.java @@ -1,15 +1,17 @@ package fr.raksrinana.fallingtree.tree; -import fr.raksrinana.fallingtree.config.Config; +import fr.raksrinana.fallingtree.config.CommonConfig; +import fr.raksrinana.fallingtree.config.ToolConfiguration; +import fr.raksrinana.fallingtree.config.TreeConfiguration; import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.AxeItem; +import net.minecraft.block.BlockLeaves; +import net.minecraft.block.BlockLog; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemStack; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.Hand; +import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -38,20 +40,20 @@ public static Optional getTree(@Nonnull World world, @Nonnull BlockPos blo return Optional.of(tree); } - public static boolean isTreeBlock(@Nonnull IWorld world, @Nonnull BlockPos blockPos){ + public static boolean isTreeBlock(@Nonnull World world, @Nonnull BlockPos blockPos){ final Block block = world.getBlockState(blockPos).getBlock(); - final boolean isWhitelistedBlock = block.isIn(BlockTags.LOGS) || Config.COMMON.getTreesConfiguration().getWhitelistedLogs().anyMatch(log -> log.equals(block)); + final boolean isWhitelistedBlock = block instanceof BlockLog || TreeConfiguration.getWhitelistedLogs().anyMatch(log -> log.equals(block)); if(isWhitelistedBlock){ - final boolean isBlacklistedBlock = Config.COMMON.getTreesConfiguration().getBlacklistedLogs().anyMatch(log -> log.equals(block)); + final boolean isBlacklistedBlock = TreeConfiguration.getBlacklistedLogs().anyMatch(log -> log.equals(block)); return !isBlacklistedBlock; } return false; } @Nonnull - private static Collection neighborLogs(@Nonnull IWorld world, @Nonnull Block logBlock, @Nonnull BlockPos blockPos, @Nonnull Collection analyzedPos){ + private static Collection neighborLogs(@Nonnull World world, @Nonnull Block logBlock, @Nonnull BlockPos blockPos, @Nonnull Collection analyzedPos){ List neighborLogs = new LinkedList<>(); - final BlockPos.Mutable checkPos = new BlockPos.Mutable(); + final BlockPos.MutableBlockPos checkPos = new BlockPos.MutableBlockPos(); for(int x = -1; x <= 1; x++){ for(int z = -1; z <= 1; z++){ for(int y = -1; y <= 1; y++){ @@ -66,40 +68,40 @@ private static Collection neighborLogs(@Nonnull IWorld world, @Nonnull return neighborLogs; } - private static boolean isSameLog(@Nonnull IWorld world, @Nonnull BlockPos blockPos, @Nullable Block logBlock){ + private static boolean isSameLog(@Nonnull World world, @Nonnull BlockPos blockPos, @Nullable Block logBlock){ return world.getBlockState(blockPos).getBlock().equals(logBlock); } - public static boolean destroy(@Nonnull Tree tree, @Nonnull PlayerEntity player, @Nonnull ItemStack tool){ + public static boolean destroy(@Nonnull Tree tree, @Nonnull EntityPlayer player, @Nonnull ItemStack tool){ final World world = tree.getWorld(); - int toolUsesLeft = (!tool.isDamageable() || Config.COMMON.getToolsConfiguration().isIgnoreDurabilityLoss()) ? Integer.MAX_VALUE : tool.getMaxDamage() - tool.getDamage(); - if(Config.COMMON.getToolsConfiguration().isPreserve()){ + int toolUsesLeft = (!tool.isItemStackDamageable() || ToolConfiguration.isIgnoreDurabilityLoss()) ? Integer.MAX_VALUE : tool.getMaxDamage() - tool.getItemDamage(); + if(ToolConfiguration.isPreserve()){ toolUsesLeft--; } if(toolUsesLeft < 1){ return false; } - final boolean isFullyBroken = Config.COMMON.getToolsConfiguration().isIgnoreDurabilityLoss() || (tool.getMaxDamage() - tool.getDamage()) >= tree.getLogCount(); + final boolean isFullyBroken = ToolConfiguration.isIgnoreDurabilityLoss() || (tool.getMaxDamage() - tool.getItemDamage()) >= tree.getLogCount(); tree.getLogs().stream().limit(toolUsesLeft).forEachOrdered(logBlock -> { - if(!Config.COMMON.getToolsConfiguration().isIgnoreDurabilityLoss()){ + if(!ToolConfiguration.isIgnoreDurabilityLoss()){ tool.onBlockDestroyed(world, world.getBlockState(logBlock), logBlock, player); } world.destroyBlock(logBlock, true); }); if(isFullyBroken){ - final int radius = Config.COMMON.getTreesConfiguration().getLavesBreakingForceRadius(); + final int radius = TreeConfiguration.getLavesBreakingForceRadius(); if(radius > 0){ tree.getLogs().stream().max(Comparator.comparingInt(BlockPos::getY)).ifPresent(topLog -> { - BlockPos.Mutable checkPos = new BlockPos.Mutable(); + BlockPos.MutableBlockPos checkPos = new BlockPos.MutableBlockPos(); for(int dx = -radius; dx < radius; dx++){ for(int dy = -radius; dy < radius; dy++){ for(int dz = -radius; dz < radius; dz++){ checkPos.setPos(topLog.getX() + dx, topLog.getY() + dy, topLog.getZ() + dz); - final BlockState checkState = world.getBlockState(checkPos); + final IBlockState checkState = world.getBlockState(checkPos); final Block checkBlock = checkState.getBlock(); - if(BlockTags.LEAVES.contains(checkBlock)){ - Block.spawnDrops(checkState, world, checkPos); - world.removeBlock(checkPos, false); + if(checkBlock instanceof BlockLeaves){ + checkBlock.dropBlockAsItem(world, checkPos, checkState, 0); + world.destroyBlock(checkPos, false); } } } @@ -110,11 +112,11 @@ public static boolean destroy(@Nonnull Tree tree, @Nonnull PlayerEntity player, return true; } - public static boolean canPlayerBreakTree(@Nonnull PlayerEntity player){ - final ItemStack heldItem = player.getHeldItem(Hand.MAIN_HAND); - final boolean isWhitelistedTool = heldItem.getItem() instanceof AxeItem || Config.COMMON.getToolsConfiguration().getWhitelisted().anyMatch(tool -> tool.equals(heldItem.getItem())); + public static boolean canPlayerBreakTree(@Nonnull EntityPlayer player){ + final ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND); + final boolean isWhitelistedTool = heldItem.getItem() instanceof ItemAxe || ToolConfiguration.getWhitelisted().anyMatch(tool -> tool.equals(heldItem.getItem())); if(isWhitelistedTool){ - final boolean isBlacklistedTool = Config.COMMON.getToolsConfiguration().getBlacklisted().anyMatch(tool -> tool.equals(heldItem.getItem())); + final boolean isBlacklistedTool = ToolConfiguration.getBlacklisted().anyMatch(tool -> tool.equals(heldItem.getItem())); return !isBlacklistedTool; } return false; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml deleted file mode 100644 index bd4a09ad..00000000 --- a/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,27 +0,0 @@ -modLoader="javafml" -loaderVersion="[31,)" -issueTrackerURL="https://github.com/RakSrinaNa/FallingTree/issues" -displayURL="https://www.curseforge.com/minecraft/mc-mods/falling-tree" -logoFile="logo.png" -# credits="" -authors="RakSrinaNa" - -[[mods]] #mandatory - modId="falling_tree" - version="${file.jarVersion}" - displayName="Falling Tree" - updateJSONURL="https://raw.githubusercontent.com/RakSrinaNa/FallingTree/1.15.2/update.json" - description='''Cut trees in one cut''' - -[[dependencies.falling_tree]] - modId="forge" - mandatory=true - versionRange="[31.0.0,)" - ordering="NONE" - side="BOTH" -[[dependencies.falling_tree]] - modId="minecraft" - mandatory=true - versionRange="[1.15.2]" - ordering="NONE" - side="BOTH" diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 00000000..cb25a274 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,14 @@ +[{ + "modid": "falling_tree", + "name": "Falling Tree", + "description": "Cut trees in one cut", + "version": "${version}", + "mcversion": "${mcversion}", + "url": "https://www.curseforge.com/minecraft/mc-mods/falling-tree", + "updateUrl": "https://raw.githubusercontent.com/RakSrinaNa/FallingTree/1.12.2/update.json", + "authorList": ["RakSrinaNa"], + "credits": "", + "logoFile": "logo.png", + "screenshots": [], + "dependencies": [] +}] \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta deleted file mode 100644 index 0c4c7fd0..00000000 --- a/src/main/resources/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack": { - "description": "Falling Tree", - "pack_format": 5 - } -} diff --git a/update.json b/update.json index c539b56f..2e76d060 100644 --- a/update.json +++ b/update.json @@ -1,14 +1,11 @@ { "homepage": "https://github.com/RakSrinaNa/FallingTree", - "changelog": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md", - "1.15.2": { - "2.1.0": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md", - "2.0.4": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md", - "2.0.3": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md", - "2.0.2": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md" + "changelog": "https://github.com/RakSrinaNa/FallingTree/blob/1.12.2/CHANGELOG.md", + "1.12.2": { + "2.1.0": "https://github.com/RakSrinaNa/FallingTree/blob/1.12.2/CHANGELOG.md" }, "promos": { - "1.15.2-latest": "2.1.0", - "1.15.2-recommended": "2.1.0" + "1.12.2-latest": "2.1.0", + "1.12.2-recommended": "2.1.0" } } \ No newline at end of file