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
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.8
yarn_mappings=1.21.8+build.1
loader_version=0.17.2
# Mod Properties
mod_version=0.2.3
mod_version=0.2.4
maven_group=moe.sebiann
archives_base_name=qol27
# Dependencies
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/moe/sebiann/qol27/client/CarpetSafety.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package moe.sebiann.qol27.client;

import moe.sebiann.qol27.config.QoL27Config;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CarpetBlock;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;


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

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

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

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

if (config.sneakOverridesCarpetPlacing() && player.isSneaking()) {
return ActionResult.PASS;
} else if (state.getBlock() instanceof CarpetBlock) {
return ActionResult.FAIL;
} else {
return ActionResult.PASS;
}
});
}

private static final Set<Item> CARPET_ITEMS = Stream.of(
Blocks.WHITE_CARPET,
Blocks.LIGHT_GRAY_CARPET,
Blocks.GRAY_CARPET,
Blocks.BLACK_CARPET,
Blocks.BROWN_CARPET,
Blocks.ORANGE_CARPET,
Blocks.MAGENTA_CARPET,
Blocks.LIGHT_BLUE_CARPET,
Blocks.YELLOW_CARPET,
Blocks.LIME_CARPET,
Blocks.PINK_CARPET,
Blocks.CYAN_CARPET,
Blocks.PURPLE_CARPET,
Blocks.BLUE_CARPET,
Blocks.GREEN_CARPET,
Blocks.RED_CARPET
).map(Block::asItem).collect(Collectors.toSet());
}
1 change: 1 addition & 0 deletions src/main/java/moe/sebiann/qol27/client/QoL27Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class QoL27Client implements ClientModInitializer {
public void onInitializeClient() {
NoSilkDetection.initialize();
WoodStrippingDetection.initialize();
CarpetSafety.initialize();

LOGGER.info("{} initialized!", MOD_ID);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/moe/sebiann/qol27/config/Config27.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public class Config27 {

// @SectionHeader("saveCoordsOnLogout")
// public boolean saveCoordsOnLogout = true;

@SectionHeader("noCarpetsOnCarpets")
public boolean noCarpetsOnCarpetsEnabled = true;
public boolean sneakOverridesCarpetPlacing = true;

}
5 changes: 4 additions & 1 deletion src/main/resources/assets/qol27/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"text.config.qol27-config.option.noStrippingEnabled":"No Stripping Detection Enabled",
"text.config.qol27-config.option.sneakOverridesStripping":"Sneak Overrides Stripping",
"text.config.qol27-config.section.saveCoordsOnLogout":"Save Coordinates on Logout",
"text.config.qol27-config.option.saveCoordsOnLogout":"Save Coordinates on Logout"
"text.config.qol27-config.option.saveCoordsOnLogout":"Save Coordinates on Logout",
"text.config.qol27-config.section.noCarpetsOnCarpets":"No Carpets on Carpets",
"text.config.qol27-config.option.noCarpetsOnCarpetsEnabled":"No Carpets on Carpets Enabled",
"text.config.qol27-config.option.sneakOverridesCarpetPlacing":"Sneak Overrides Carpet Placing"
}
Loading