Skip to content

Commit 95e6159

Browse files
committed
hotfix + comments
1 parent cc43c1f commit 95e6159

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,12 @@ public static void save() {
201201
private static void populate(HashMap<String, List<String>> map, JSONArray source) {
202202
for (JSONObject entry : (Iterable<JSONObject>) source) {
203203
String id = (String) entry.get("id");
204+
205+
// if user did not specify origin of block/item, we assume it is from vanilla Minecraft.
204206
if (!id.contains(":")) {
205207
id = "minecraft:" + id;
206208
}
209+
207210
List<String> list = new ArrayList<>();
208211
if (entry.containsKey("properties")) {
209212
JSONArray props = (JSONArray) entry.get("properties");

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,38 @@ private static <T extends Comparable<T>> BlockState cycle(BlockState state, Prop
3838

3939
@Inject(at = @At("HEAD"), method = "use", cancellable = true)
4040
private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, BlockPos pos, boolean update, ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
41+
// if player is not in Survival or Hardcore mode, the mod should not interfere
4142
if (player.isCreativeLevelTwoOp()) {return;}
4243

4344
Block block = state.getBlock();
4445
StateManager<Block, BlockState> stateManager = block.getStateManager();
4546
Collection<Property<?>> collection = stateManager.getProperties();
4647

48+
// check if block is modifiable by the config
4749
if (!isBlockAllowedToModify(state.getBlock()) || collection.isEmpty()) {
4850
sendMessage(player, Text.of(Config.MESSAGE_nomodify));
4951
cir.setReturnValue(false);
5052
return;
5153
}
5254

55+
// https://minecraft.fandom.com/wiki/Debug_Stick#Item_data
56+
// to remember the data of which property for which block is chosen,
57+
// Minecraft Devs decided to use NBT data for Debug Stick.
58+
// Who am I to disagree?
5359
NbtCompound nbtCompound = stack.getOrCreateSubNbt("DebugProperty");
5460

5561
String blockName = Registry.BLOCK.getId(block).toString();
5662
String propertyName = nbtCompound.getString(blockName);
5763

5864
Property<?> property = stateManager.getProperty(propertyName);
5965

60-
6166
if (player.isSneaking()) {
6267
// select next property
6368
property = getNextProperty(collection, property, block);
69+
// save chosen property in the NBT data of Debug Stick
6470
nbtCompound.putString(blockName, property.getName());
6571

72+
// send the player a message of successful selecting
6673
sendMessage(player, Text.of(
6774
String.format(
6875
Config.MESSAGE_select,
@@ -77,23 +84,29 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
7784
property = getNextProperty(collection, null, block);
7885
}
7986

80-
BlockState blockState = cycle(state, property, false);
81-
world.setBlockState(pos, blockState, 18);
87+
// generate new state of chosen block with modified property
88+
BlockState newState = cycle(state, property, false);
89+
// update chosen block with its new state
90+
world.setBlockState(pos, newState, 18);
91+
// send the player a message of successful modifying
8292
sendMessage(player, Text.of(
8393
String.format(
8494
Config.MESSAGE_change,
8595
property.getName(),
86-
getValueString(state, property)
96+
getValueString(newState, property)
8797
)
8898
)
8999
);
90100
}
91101
cir.setReturnValue(true);
92102
}
93103

104+
/**
105+
* Choose next property that is appropriate for the configuration file
106+
* */
94107
private Property<?> getNextProperty(Collection<Property<?>> collection, @Nullable Property<?> property, @Nullable Block block) {
95108
int len = collection.size();
96-
do {
109+
do { // simply scrolling through the list of properties until suitable is found
97110
property = Util.next(collection, property);
98111
len--;
99112
} while (len > 0 && !isPropertyModifiable(property, block));

0 commit comments

Comments
 (0)