Skip to content

Commit

Permalink
Backport to 1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed Apr 27, 2020
1 parent dc13f0e commit 9205aa0
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 258 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -10,4 +13,3 @@

## [1.15.2-2.0.2] - 2020-01-23
- Port to 1.15.2

51 changes: 19 additions & 32 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand All @@ -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"

Expand Down Expand Up @@ -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 {
Expand All @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions changes.md
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 4 additions & 25 deletions src/main/java/fr/raksrinana/fallingtree/FallingTree.java
Original file line number Diff line number Diff line change
@@ -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);
}
67 changes: 34 additions & 33 deletions src/main/java/fr/raksrinana/fallingtree/ForgeEventSubscriber.java
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
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<LeafBreakingSchedule> 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);
}

@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));
}
}
Expand All @@ -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<LeafBreakingSchedule> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,7 +27,7 @@ public BlockPos getBlockPos(){
return blockPos;
}

public ServerWorld getWorld(){
public WorldServer getWorld(){
return world;
}

Expand Down
43 changes: 19 additions & 24 deletions src/main/java/fr/raksrinana/fallingtree/config/CommonConfig.java
Original file line number Diff line number Diff line change
@@ -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){
Expand All @@ -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);
}
}
}
}
18 changes: 0 additions & 18 deletions src/main/java/fr/raksrinana/fallingtree/config/Config.java

This file was deleted.

Loading

0 comments on commit 9205aa0

Please sign in to comment.