Skip to content

Commit e1e2f34

Browse files
committed
backport
1 parent 3e51889 commit e1e2f34

File tree

6 files changed

+33
-47
lines changed

6 files changed

+33
-47
lines changed

gradle.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G
33
org.gradle.java.home=C:/Program Files/Microsoft/jdk-21.0.4.7-hotspot
44

55
# Fabric Properties
6-
minecraft_version=1.21
7-
yarn_mappings=1.21+build.2
8-
loader_version=0.15.11
6+
minecraft_version=1.19.4
7+
yarn_mappings=1.19.4+build.2
8+
loader_version=0.16.3
99

10-
#Fabric api
11-
fabric_version=0.100.3+1.21
10+
# Fabric API
11+
fabric_version=0.87.2+1.19.4
1212

1313
# Mod Properties
14-
mod_version = 1.2.2_1.21
14+
mod_version = 1.2.2_1.19.34
1515
maven_group = net.just_s
1616
archives_base_name = survival-debug-mod

src/main/java/net/just_s/sds/SDSMod.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import net.fabricmc.api.ModInitializer;
44
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
55
import net.just_s.sds.config.Config;
6-
import net.minecraft.component.ComponentChanges;
7-
import net.minecraft.component.DataComponentTypes;
8-
import net.minecraft.component.type.NbtComponent;
96
import net.minecraft.item.ItemStack;
107
import net.minecraft.item.Items;
118
import net.minecraft.nbt.NbtCompound;
@@ -46,22 +43,13 @@ public void onInitialize() {
4643

4744
// So I decided to put custom nbt timer to prevent spamming
4845
// (It is still buggy, suggestions appreciated)
49-
NbtComponent component = stack.get(DataComponentTypes.CUSTOM_DATA);
50-
if (component != null) {
51-
NbtCompound nbtData = component.copyNbt();
52-
long lastModified = nbtData.getLong("LastModified");
53-
if (world.getTime() < lastModified + 5) {
54-
return ActionResult.PASS;
55-
}
46+
NbtCompound nbtData = stack.getOrCreateNbt();
47+
long lastModified = nbtData.getLong("LastModified");
48+
if (world.getTime() < lastModified + 5) {
49+
return ActionResult.PASS;
5650
}
5751

58-
NbtCompound newNbtData = new NbtCompound();
59-
newNbtData.put("LastModified", NbtLong.of(world.getTime()));
60-
stack.applyChanges(
61-
ComponentChanges.builder()
62-
.add(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(newNbtData))
63-
.build()
64-
);
52+
nbtData.put("LastModified", NbtLong.of(world.getTime()));
6553
stack.getItem().canMine(world.getBlockState(pos), world, pos, player);
6654
return ActionResult.PASS;
6755
}

src/main/java/net/just_s/sds/config/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ protected static SDSConfig getData() {
3232
protected static JsonElement serialize() {
3333
return SDSConfig.CODEC
3434
.encode(getData(), JsonOps.INSTANCE, JsonOps.INSTANCE.empty())
35-
.getOrThrow();
35+
.getOrThrow(false, JsonParseException::new);
3636
}
3737

3838
protected static void deserialize(JsonElement element) {
39-
sdsConfig = SDSConfig.CODEC.decode(JsonOps.INSTANCE, element).getOrThrow().getFirst();
39+
sdsConfig = SDSConfig.CODEC.decode(JsonOps.INSTANCE, element).getOrThrow(false, JsonParseException::new).getFirst();
4040
}
4141

4242
public static void save() {

src/main/java/net/just_s/sds/mixin/DebugStickMixin.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import net.just_s.sds.config.Config;
44
import net.minecraft.block.Block;
55
import net.minecraft.block.BlockState;
6-
import net.minecraft.component.DataComponentTypes;
7-
import net.minecraft.component.type.DebugStickStateComponent;
86
import net.minecraft.entity.player.PlayerEntity;
97
import net.minecraft.item.DebugStickItem;
108
import net.minecraft.item.Item;
119
import net.minecraft.item.ItemStack;
12-
import net.minecraft.registry.entry.RegistryEntry;
10+
import net.minecraft.nbt.NbtCompound;
11+
import net.minecraft.registry.Registries;
1312
import net.minecraft.state.StateManager;
1413
import net.minecraft.state.property.Property;
1514
import net.minecraft.text.Text;
@@ -53,28 +52,27 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
5352
if (player.isCreativeLevelTwoOp()) {return;}
5453

5554
Block block = state.getBlock();
56-
RegistryEntry<Block> registryEntry = state.getRegistryEntry();
57-
StateManager<Block, BlockState> stateManager = (registryEntry.value()).getStateManager();
55+
String blockIdAsString = Registries.BLOCK.getId(block).toString();
56+
StateManager<Block, BlockState> stateManager = block.getStateManager();
5857
Collection<Property<?>> collection = stateManager.getProperties();
5958

6059
// check if block is modifiable by the config
6160
if (!isBlockAllowedToModify(block) || collection.isEmpty()) {
62-
sendMessage(player, Text.translatable(this.getTranslationKey() + ".empty", new Object[]{registryEntry.getIdAsString()}));
61+
sendMessage(player, Text.translatable(this.getTranslationKey() + ".empty", new Object[]{blockIdAsString}));
6362
cir.setReturnValue(false);
6463
return;
6564
}
6665

67-
// https://minecraft.wiki/w/Debug_Stick
66+
// https://minecraft.fandom.com/wiki/Debug_Stick#Item_data
6867
// to remember the data of which property for which block is chosen,
69-
// Minecraft Devs decided to use Component for Debug Stick.
70-
// Who am I to disagree? (btw thx to @MrBretze for example code)
71-
DebugStickStateComponent stateComponent = stack.get(DataComponentTypes.DEBUG_STICK_STATE);
68+
// Minecraft Devs decided to use NBT data for Debug Stick.
69+
// Who am I to disagree?
70+
NbtCompound nbtCompound = stack.getOrCreateSubNbt("DebugProperty");
7271

73-
if (stateComponent == null) {
74-
return;
75-
}
72+
String blockName = Registries.BLOCK.getId(block).toString();
73+
String propertyName = nbtCompound.getString(blockName);
7674

77-
Property<?> property = stateComponent.properties().get(registryEntry);
75+
Property<?> property = stateManager.getProperty(propertyName);
7876

7977
if (update) {
8078
// change value of property
@@ -83,7 +81,7 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
8381
}
8482
// check if given property is allowed
8583
if (!isPropertyModifiable(property, block)) {
86-
sendMessage(player, Text.translatable(this.getTranslationKey() + ".empty", new Object[]{registryEntry.getIdAsString()}));
84+
sendMessage(player, Text.translatable(this.getTranslationKey() + ".empty", new Object[]{blockIdAsString}));
8785
cir.setReturnValue(false);
8886
return;
8987
}
@@ -105,12 +103,12 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
105103
property = getNextProperty(collection, property, block, player.shouldCancelInteraction());
106104
// check if given property is allowed
107105
if (!isPropertyModifiable(property, block)) {
108-
sendMessage(player, Text.translatable(this.getTranslationKey() + ".empty", new Object[]{registryEntry.getIdAsString()}));
106+
sendMessage(player, Text.translatable(this.getTranslationKey() + ".empty", new Object[]{blockIdAsString}));
109107
cir.setReturnValue(false);
110108
return;
111109
}
112110
// save chosen property in the NBT data of Debug Stick
113-
stack.set(DataComponentTypes.DEBUG_STICK_STATE, stateComponent.with(registryEntry, property));
111+
nbtCompound.putString(blockName, property.getName());
114112

115113
// send the player a message of successful selecting
116114
sendMessage(

src/main/resources/data/sds/recipes/debug_stick.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{"item": "minecraft:chorus_fruit"}
66
],
77
"result": {
8-
"id": "minecraft:debug_stick",
8+
"item": "minecraft:debug_stick",
99
"count": 1
1010
}
1111
}

src/main/resources/fabric.mod.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
],
2828

2929
"depends": {
30-
"fabricloader": ">=0.15.10",
30+
"fabricloader": ">=0.14.6",
3131
"fabric": "*",
32-
"minecraft": ">=1.20.5",
33-
"java": ">=21"
32+
"minecraft": ["1.19.3", "1.19.4"],
33+
"java": ">=17"
3434
},
3535
"suggests": {
3636
"another-mod": "*"
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)