Skip to content

Commit

Permalink
Port to 1.21 (#699)
Browse files Browse the repository at this point in the history
* Fabric port + datapack

* Forge & NeoForge
  • Loading branch information
Rakambda authored Jun 15, 2024
1 parent c463cd0 commit 33b5f35
Show file tree
Hide file tree
Showing 51 changed files with 473 additions and 667 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ Check out the [wiki](https://github.com/Rakambda/FallingTree/wiki) for some more

* For Fabric users, **Fabric API** is required.
* For Neoforge/Forge users, **Cloth Config API** is optional on the client and allows you to have a config GUI in game.
Starting Minecraft 1.21, enchantments needs to be added separately through a datapack [available here](https://modrinth.com/datapack/fallingtree-enchantments).

NOTE: On servers this mod can be server-side only, client isn't required (except if you use the change speed feature and/or enchants configurations).
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
package fr.rakambda.fallingtree.common;

import fr.rakambda.fallingtree.common.command.ToggleCommand;
import fr.rakambda.fallingtree.common.leaf.LeafBreakingHandler;
import fr.rakambda.fallingtree.common.tree.TreeHandler;
import fr.rakambda.fallingtree.common.tree.TreePartType;
import fr.rakambda.fallingtree.common.tree.builder.TreeBuilder;
import fr.rakambda.fallingtree.common.wrapper.IBlock;
import fr.rakambda.fallingtree.common.wrapper.IBlockState;
import fr.rakambda.fallingtree.common.wrapper.IComponent;
import fr.rakambda.fallingtree.common.wrapper.IItem;
import fr.rakambda.fallingtree.common.wrapper.ILevel;
import fr.rakambda.fallingtree.common.config.IConfiguration;
import fr.rakambda.fallingtree.common.config.IToolConfiguration;
import fr.rakambda.fallingtree.common.config.proxy.ProxyConfiguration;
import fr.rakambda.fallingtree.common.config.real.Configuration;
import fr.rakambda.fallingtree.common.leaf.LeafBreakingHandler;
import fr.rakambda.fallingtree.common.network.PacketUtils;
import fr.rakambda.fallingtree.common.network.ServerPacketHandler;
import fr.rakambda.fallingtree.common.tree.TreeHandler;
import fr.rakambda.fallingtree.common.tree.TreePartType;
import fr.rakambda.fallingtree.common.tree.builder.TreeBuilder;
import fr.rakambda.fallingtree.common.wrapper.DirectionCompat;
import fr.rakambda.fallingtree.common.wrapper.IBlock;
import fr.rakambda.fallingtree.common.wrapper.IBlockPos;
import fr.rakambda.fallingtree.common.wrapper.IEnchantment;
import fr.rakambda.fallingtree.common.wrapper.IBlockState;
import fr.rakambda.fallingtree.common.wrapper.IComponent;
import fr.rakambda.fallingtree.common.wrapper.IItem;
import fr.rakambda.fallingtree.common.wrapper.IItemStack;
import fr.rakambda.fallingtree.common.wrapper.ILevel;
import fr.rakambda.fallingtree.common.wrapper.IPlayer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toSet;

@RequiredArgsConstructor
Expand Down Expand Up @@ -121,7 +118,7 @@ public boolean canPlayerBreakTree(@NotNull IPlayer player) {
}

if (getConfiguration().getEnchantment().isRequireEnchantment()
&& !heldItemStack.hasOneOfEnchantAtLeast(getChopperEnchantments(), 1)) {
&& !heldItemStack.hasChopperEnchant()) {
return false;
}

Expand Down Expand Up @@ -234,25 +231,6 @@ public TreePartType getTreePart(@NotNull IBlock checkBlock) {

public abstract boolean checkCanBreakBlock(@NotNull ILevel level, @NotNull IBlockPos blockPos, @NotNull IBlockState blockState, @NotNull IPlayer player);

public void registerEnchant() {
if (getConfiguration().getEnchantment().isRegisterEnchant()) {
performDefaultEnchantRegister();
}
if (getConfiguration().getEnchantment().isRegisterSpecificEnchant()) {
performSpecificEnchantRegister();
}
performCommitEnchantRegister();
}

protected abstract void performDefaultEnchantRegister();

protected abstract void performSpecificEnchantRegister();

protected abstract void performCommitEnchantRegister();

@NotNull
public abstract Collection<IEnchantment> getChopperEnchantments();

@NotNull
public abstract IItemStack getEmptyItemStack();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package fr.rakambda.fallingtree.common.config;

public interface IEnchantmentConfiguration{
boolean isRegisterEnchant();

boolean isRegisterSpecificEnchant();

boolean isRequireEnchantment();

boolean isHideEnchant();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

@Data
public class EnchantmentConfiguration implements IEnchantmentConfiguration{
@Expose
private boolean registerEnchant = false;
@Expose
private boolean registerSpecificEnchant = false;
@Expose
private boolean hideEnchant = false;
@Expose
private boolean requireEnchantment = false;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package fr.rakambda.fallingtree.common.tree;

import fr.rakambda.fallingtree.common.tree.breaking.*;
import fr.rakambda.fallingtree.common.tree.builder.TreeTooBigException;
import fr.rakambda.fallingtree.common.FallingTreeCommon;
import fr.rakambda.fallingtree.common.config.enums.BreakMode;
import fr.rakambda.fallingtree.common.tree.breaking.BreakTreeTooBigException;
import fr.rakambda.fallingtree.common.tree.breaking.FallingAnimationTreeBreakingHandler;
import fr.rakambda.fallingtree.common.tree.breaking.ITreeBreakingHandler;
import fr.rakambda.fallingtree.common.tree.breaking.InstantaneousTreeBreakingHandler;
import fr.rakambda.fallingtree.common.tree.breaking.ShiftDownTreeBreakingHandler;
import fr.rakambda.fallingtree.common.tree.builder.TreeTooBigException;
import fr.rakambda.fallingtree.common.utils.CacheSpeed;
import fr.rakambda.fallingtree.common.wrapper.IBlockPos;
import fr.rakambda.fallingtree.common.wrapper.IEnchantment;
import fr.rakambda.fallingtree.common.wrapper.IItemStack;
import fr.rakambda.fallingtree.common.wrapper.ILevel;
import fr.rakambda.fallingtree.common.wrapper.IPlayer;
Expand Down Expand Up @@ -68,8 +71,7 @@ public IBreakAttemptResult breakTree(@NotNull ILevel level, @NotNull IPlayer pla

@NotNull
private BreakMode getBreakMode(@NotNull IItemStack itemStack){
return itemStack.getAnyEnchant(mod.getChopperEnchantments())
.flatMap(IEnchantment::getBreakMode)
return itemStack.getBreakModeFromEnchant()
.orElseGet(() -> mod.getConfiguration().getTrees().getBreakMode());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package fr.rakambda.fallingtree.common.wrapper;

import fr.rakambda.fallingtree.common.config.enums.BreakMode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Optional;

public interface IItemStack extends IWrapper{
Expand All @@ -19,12 +18,10 @@ public interface IItemStack extends IWrapper{
@NotNull
IItem getItem();

int getEnchantLevel(@Nullable IEnchantment enchantment);

boolean hasOneOfEnchantAtLeast(@NotNull Collection<IEnchantment> enchantments, int minLevel);
boolean hasChopperEnchant();

@NotNull
Optional<IEnchantment> getAnyEnchant(@NotNull Collection<IEnchantment> enchantments);
Optional<BreakMode> getBreakModeFromEnchant();

boolean canPerformAxeAction();
}
32 changes: 32 additions & 0 deletions datapack/data/fallingtree/enchantment/tools/chopper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"anvil_cost": 6,
"description": {
"translate": "enchantment.fallingtree.chopper",
"fallback": "Chopper"
},
"effects": {
"minecraft:block_experience": [
{
"effect": {
"type": "minecraft:set",
"value": 0
}
}
]
},
"max_cost": {
"base": 65,
"per_level_above_first": 0
},
"max_level": 1,
"min_cost": {
"base": 15,
"per_level_above_first": 0
},
"slots": [
"mainhand"
],
"exclusive_set": "#fallingtree:exclusive_set/chopper",
"supported_items": "#minecraft:enchantable/mining_loot",
"weight": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"anvil_cost": 6,
"description": {
"translate": "enchantment.fallingtree.chopper_fall_all_block",
"fallback": "Chopper (fall all block)"
},
"effects": {
"minecraft:block_experience": [
{
"effect": {
"type": "minecraft:set",
"value": 0
}
}
]
},
"max_cost": {
"base": 65,
"per_level_above_first": 0
},
"max_level": 1,
"min_cost": {
"base": 15,
"per_level_above_first": 0
},
"slots": [
"mainhand"
],
"exclusive_set": "#fallingtree:exclusive_set/chopper",
"supported_items": "#minecraft:enchantable/mining_loot",
"weight": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"anvil_cost": 6,
"description": {
"translate": "enchantment.fallingtree.chopper_fall_block",
"fallback": "Chopper (fall block)"
},
"effects": {
"minecraft:block_experience": [
{
"effect": {
"type": "minecraft:set",
"value": 0
}
}
]
},
"max_cost": {
"base": 65,
"per_level_above_first": 0
},
"max_level": 1,
"min_cost": {
"base": 15,
"per_level_above_first": 0
},
"slots": [
"mainhand"
],
"exclusive_set": "#fallingtree:exclusive_set/chopper",
"supported_items": "#minecraft:enchantable/mining_loot",
"weight": 1
}
32 changes: 32 additions & 0 deletions datapack/data/fallingtree/enchantment/tools/chopper_fall_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"anvil_cost": 6,
"description": {
"translate": "enchantment.fallingtree.chopper_fall_item",
"fallback": "Chopper (fall item)"
},
"effects": {
"minecraft:block_experience": [
{
"effect": {
"type": "minecraft:set",
"value": 0
}
}
]
},
"max_cost": {
"base": 65,
"per_level_above_first": 0
},
"max_level": 1,
"min_cost": {
"base": 15,
"per_level_above_first": 0
},
"slots": [
"mainhand"
],
"exclusive_set": "#fallingtree:exclusive_set/chopper",
"supported_items": "#minecraft:enchantable/mining_loot",
"weight": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"anvil_cost": 6,
"description": {
"translate": "enchantment.fallingtree.chopper_instantaneous",
"fallback": "Chopper (instantaneous)"
},
"effects": {
"minecraft:block_experience": [
{
"effect": {
"type": "minecraft:set",
"value": 0
}
}
]
},
"max_cost": {
"base": 65,
"per_level_above_first": 0
},
"max_level": 1,
"min_cost": {
"base": 15,
"per_level_above_first": 0
},
"slots": [
"mainhand"
],
"exclusive_set": "#fallingtree:exclusive_set/chopper",
"supported_items": "#minecraft:enchantable/mining_loot",
"weight": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"anvil_cost": 6,
"description": {
"translate": "enchantment.fallingtree.chopper_shift_down",
"fallback": "Chopper (shift down)"
},
"effects": {
"minecraft:block_experience": [
{
"effect": {
"type": "minecraft:set",
"value": 0
}
}
]
},
"max_cost": {
"base": 65,
"per_level_above_first": 0
},
"max_level": 1,
"min_cost": {
"base": 15,
"per_level_above_first": 0
},
"slots": [
"mainhand"
],
"exclusive_set": "#fallingtree:exclusive_set/chopper",
"supported_items": "#minecraft:enchantable/mining_loot",
"weight": 1
}
10 changes: 10 additions & 0 deletions datapack/data/fallingtree/tags/enchantment/chopper_all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"values": [
"fallingtree:tools/chopper",
"fallingtree:tools/chopper_fall_all_block",
"fallingtree:tools/chopper_fall_block",
"fallingtree:tools/chopper_fall_item",
"fallingtree:tools/chopper_instantaneous",
"fallingtree:tools/chopper_shift_down"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"fallingtree:tools/chopper_fall_all_block"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"fallingtree:tools/chopper_fall_block"
]
}
Loading

0 comments on commit 33b5f35

Please sign in to comment.