Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ publishing {
// retrieving dependencies.
}
}

loom {
accessWidenerPath = file("src/main/resources/WoodStrippingDetection.accesswidener")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.21.5
yarn_mappings=1.21.5+build.1
loader_version=0.16.14
# Mod Properties
mod_version=0.1.0
mod_version=0.2.0
maven_group=moe.sebiann
archives_base_name=qol27
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package moe.sebiann.qol27;
package moe.sebiann.qol27.client;

import moe.sebiann.qol27.config.QoL27Config;
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package moe.sebiann.qol27;
package moe.sebiann.qol27.client;

import moe.sebiann.qol27.config.QoL27Config;
import net.fabricmc.api.ClientModInitializer;
Expand All @@ -13,6 +13,7 @@ public class QoL27Client implements ClientModInitializer {
@Override
public void onInitializeClient() {
NoSilkDetection.initialize();
WoodStrippingDetection.initialize();

LOGGER.info("{} initialized!", MOD_ID);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package moe.sebiann.qol27;
package moe.sebiann.qol27.client;

public class SaveCoordinates {
}
37 changes: 37 additions & 0 deletions src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package moe.sebiann.qol27.client;

import moe.sebiann.qol27.config.QoL27Config;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.BlockState;
import net.minecraft.item.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;


public class WoodStrippingDetection {
public static void initialize() {
QoL27Config config = QoL27Client.getConfig();

UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> {
if (!config.noStrippingEnabled()) {
return ActionResult.PASS;
}
if (!world.isClient) return ActionResult.PASS;

ItemStack heldItem = player.getStackInHand(hand);
if (!(heldItem.getItem() instanceof AxeItem)) return ActionResult.PASS;

BlockPos pos = hitResult.getBlockPos();
BlockState state = world.getBlockState(pos);

if (config.sneakOverridesStripping() && player.isSneaking()) {
// If the player is sneaking, we allow the action regardless of enchantments
return ActionResult.PASS;
} else if (AxeItem.STRIPPED_BLOCKS.containsKey(state.getBlock())) {
return ActionResult.FAIL;
} else {
return ActionResult.PASS;
}
});
}
}
9 changes: 7 additions & 2 deletions src/main/java/moe/sebiann/qol27/config/Config27.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import io.wispforest.owo.config.annotation.Config;
import io.wispforest.owo.config.annotation.Modmenu;
import io.wispforest.owo.config.annotation.SectionHeader;

@Modmenu(modId = "qol27")
@Config(name = "qol27-config", wrapperName = "QoL27Config")
public class Config27 {
// @SectionHeader("No Silk Touch Detection")
@SectionHeader("No Silk Touch Detection")
public boolean noSilkDetectionEnabled = true;
public boolean sneakOverridesDetection = true;

// @SectionHeader("Save Coordinates on Logout")
@SectionHeader("Wood Stripping Detection")
public boolean noStrippingEnabled = true;
public boolean sneakOverridesStripping = true;

@SectionHeader("Save Coordinates on Logout")
public boolean saveCoordsOnLogout = true;
}
2 changes: 2 additions & 0 deletions src/main/resources/WoodStrippingDetection.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accessWidener v2 named
accessible field net/minecraft/item/AxeItem STRIPPED_BLOCKS Ljava/util/Map;
5 changes: 3 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
"icon": "assets/qol27/icon.png",
"environment": "client",
"entrypoints": {
"client": ["moe.sebiann.qol27.QoL27Client"]
"client": ["moe.sebiann.qol27.client.QoL27Client"]
},
"mixins": [],
"depends": {
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "${minecraft_version}",
"owo": "*"
}
},
"accessWidener": "WoodStrippingDetection.accesswidener"
}