Skip to content

Commit 14f5605

Browse files
Merge pull request #21 from ModFest/mf-1.21
create tag blocking sneak click interacts
2 parents 26d3667 + 846f0f7 commit 14f5605

File tree

9 files changed

+58
-19
lines changed

9 files changed

+58
-19
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ authors=jaskarth, unascribed
1717
contributors=Patbox, IThundxr
1818
license=AGPL-3.0-or-later
1919
# Mod Version
20-
baseVersion=0.6.0
20+
baseVersion=0.6.1
2121
# Branch Metadata
2222
branch=1.21
2323
tagBranch=1.21

src/main/java/net/modfest/fireblanket/FireblanketConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ public class FireblanketConstants {
1313
public static final String MOD_ID = "fireblanket";
1414

1515
public static final TagKey<Block> BLOCK_INTERACTION_RESTRICTED = tag(RegistryKeys.BLOCK, "block_interaction_restricted");
16+
public static final TagKey<Block> BLOCK_SNEAK_INTERACTION_RESTRICTED = tag(RegistryKeys.BLOCK, "block_sneak_interaction_restricted");
1617
public static final TagKey<Item> ITEM_INTERACTION_RESTRICTED = tag(RegistryKeys.ITEM, "item_interaction_restricted");
18+
public static final TagKey<Item> ITEM_SNEAK_INTERACTION_RESTRICTED = tag(RegistryKeys.ITEM, "item_sneak_interaction_restricted");
1719
public static final TagKey<EntityType<?>> ENTITY_INTERACTION_RESTRICTED = tag(RegistryKeys.ENTITY_TYPE, "entity_interaction_restricted");
20+
public static final TagKey<EntityType<?>> ENTITY_SNEAK_INTERACTION_RESTRICTED = tag(RegistryKeys.ENTITY_TYPE, "entity_sneak_interaction_restricted");
1821

1922
public static final TagKey<EntityType<?>> ENTITY_ATTACK_RESTRICTED = tag(RegistryKeys.ENTITY_TYPE, "entity_attack_restricted");
2023

src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinItemStack.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.util.TypedActionResult;
1111
import net.minecraft.world.World;
1212
import net.modfest.fireblanket.FireblanketConstants;
13+
import net.modfest.fireblanket.mixinsupport.InteractionCheck;
1314
import org.spongepowered.asm.mixin.Mixin;
1415
import org.spongepowered.asm.mixin.Shadow;
1516
import org.spongepowered.asm.mixin.injection.At;
@@ -27,15 +28,15 @@ public abstract class MixinItemStack {
2728
private void fireblanket$filterItemUseOnBlockByTag(ItemUsageContext context, CallbackInfoReturnable<ActionResult> ci) {
2829
PlayerEntity player = context.getPlayer();
2930
if (player == null) return;
30-
if (!player.getAbilities().allowModifyWorld && this.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) {
31+
if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventUseItem(player, (ItemStack)(Object)this)) {
3132
ci.setReturnValue(ActionResult.FAIL);
3233
ci.cancel();
3334
}
3435
}
3536

3637
@Inject(method = "use", at = @At("HEAD"), cancellable = true)
3738
private void fireblanket$filterItemUseByTag(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> ci) {
38-
if (!user.getAbilities().allowModifyWorld && this.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) {
39+
if (!user.getAbilities().allowModifyWorld && InteractionCheck.preventUseItem(user, (ItemStack)(Object)this)) {
3940
ci.setReturnValue(TypedActionResult.fail(user.getStackInHand(hand)));
4041
ci.cancel();
4142
}

src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinPlayerInteractEntityC2SPacketHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.server.network.ServerPlayNetworkHandler;
77
import net.minecraft.util.Hand;
88
import net.modfest.fireblanket.FireblanketConstants;
9+
import net.modfest.fireblanket.mixinsupport.InteractionCheck;
910
import org.spongepowered.asm.mixin.Final;
1011
import org.spongepowered.asm.mixin.Mixin;
1112
import org.spongepowered.asm.mixin.Shadow;
@@ -34,9 +35,8 @@ public class MixinPlayerInteractEntityC2SPacketHandler {
3435
private void fireblanket$filterEntityInteractByTag(Hand hand, ServerPlayNetworkHandler.Interaction action, CallbackInfo ci) {
3536
PlayerEntity player = field_28963.player;
3637
ItemStack stack = player.getStackInHand(hand);
37-
if (!player.getAbilities().allowModifyWorld && (
38-
stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED) ||
39-
field_28962.getType().isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED))) {
38+
if (!player.getAbilities().allowModifyWorld &&
39+
(InteractionCheck.preventUseItem(player, stack) || InteractionCheck.preventUseEntity(player, field_28962.getType()))) {
4040
ci.cancel();
4141
}
4242
}
@@ -48,7 +48,7 @@ public class MixinPlayerInteractEntityC2SPacketHandler {
4848
)
4949
private void fireblanket$filterAttackEntityByTag(CallbackInfo ci) {
5050
PlayerEntity player = field_28963.player;
51-
if (!player.getAbilities().allowModifyWorld && field_28962.getType().isIn(FireblanketConstants.ENTITY_ATTACK_RESTRICTED)) {
51+
if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventAttackEntity(player, field_28962.getType())) {
5252
ci.cancel();
5353
}
5454
}

src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinServerPlayerInteractionManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.util.hit.BlockHitResult;
1313
import net.minecraft.world.World;
1414
import net.modfest.fireblanket.FireblanketConstants;
15+
import net.modfest.fireblanket.mixinsupport.InteractionCheck;
1516
import org.spongepowered.asm.mixin.Mixin;
1617
import org.spongepowered.asm.mixin.injection.At;
1718

@@ -23,10 +24,10 @@ public class MixinServerPlayerInteractionManager {
2324
)
2425
private ItemActionResult fireblanket$filterItemBlockInteractByTag(BlockState blockState, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hitResult, Operation<ItemActionResult> op) {
2526
if (!player.getAbilities().allowModifyWorld) {
26-
if (stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) {
27+
if (InteractionCheck.preventUseItem(player, stack)) {
2728
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
2829
}
29-
if (blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) {
30+
if (InteractionCheck.preventUseBlock(player, blockState)) {
3031
return ItemActionResult.FAIL;
3132
}
3233
}
@@ -38,7 +39,7 @@ public class MixinServerPlayerInteractionManager {
3839
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")
3940
)
4041
private ActionResult fireblanket$filterBlockInteractByTag(BlockState blockState, World world, PlayerEntity player, BlockHitResult hitResult, Operation<ActionResult> op) {
41-
if (!player.getAbilities().allowModifyWorld && blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) {
42+
if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventUseBlock(player, blockState)) {
4243
return ActionResult.FAIL;
4344
}
4445
return op.call(blockState, world, player, hitResult);

src/main/java/net/modfest/fireblanket/mixin/client/adventure_fix/MixinClientPlayerInteractionManager.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.minecraft.util.hit.EntityHitResult;
1515
import net.minecraft.world.World;
1616
import net.modfest.fireblanket.FireblanketConstants;
17+
import net.modfest.fireblanket.mixinsupport.InteractionCheck;
1718
import org.spongepowered.asm.mixin.Mixin;
1819
import org.spongepowered.asm.mixin.injection.At;
1920
import org.spongepowered.asm.mixin.injection.Inject;
@@ -28,8 +29,8 @@ public class MixinClientPlayerInteractionManager {
2829
cancellable = true)
2930
private void fireblanket$filterEntityInteractByTag(PlayerEntity player, Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> ci) {
3031
if (!player.getAbilities().allowModifyWorld && (
31-
entity.getType().isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED) ||
32-
player.getStackInHand(hand).isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED))) {
32+
InteractionCheck.preventUseEntity(player, entity.getType()) ||
33+
InteractionCheck.preventUseItem(player, player.getStackInHand(hand)))) {
3334
ci.setReturnValue(ActionResult.FAIL);
3435
ci.cancel();
3536
}
@@ -42,8 +43,8 @@ public class MixinClientPlayerInteractionManager {
4243
)
4344
private void fireblanket$filterEntityInteractAtLocationByTag(PlayerEntity player, Entity entity, EntityHitResult hitResult, Hand hand, CallbackInfoReturnable<ActionResult> ci) {
4445
if (!player.getAbilities().allowModifyWorld && (
45-
entity.getType().isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED) ||
46-
player.getStackInHand(hand).isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED))) {
46+
InteractionCheck.preventUseEntity(player, entity.getType()) ||
47+
InteractionCheck.preventUseItem(player, player.getStackInHand(hand)))) {
4748
ci.setReturnValue(ActionResult.FAIL);
4849
ci.cancel();
4950
}
@@ -55,10 +56,10 @@ public class MixinClientPlayerInteractionManager {
5556
)
5657
private ItemActionResult fireblanket$filterItemBlockInteractByTag(BlockState blockState, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hitResult, Operation<ItemActionResult> op) {
5758
if (!player.getAbilities().allowModifyWorld) {
58-
if (stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) {
59+
if (InteractionCheck.preventUseItem(player, stack)) {
5960
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
6061
}
61-
if (blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) {
62+
if (InteractionCheck.preventUseBlock(player, blockState)) {
6263
return ItemActionResult.FAIL;
6364
}
6465
}
@@ -70,7 +71,7 @@ public class MixinClientPlayerInteractionManager {
7071
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")
7172
)
7273
private ActionResult fireblanket$filterBlockInteractByTag(BlockState blockState, World world, PlayerEntity player, BlockHitResult hitResult, Operation<ActionResult> op) {
73-
if (!player.getAbilities().allowModifyWorld && blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) {
74+
if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventUseBlock(player, blockState)) {
7475
return ActionResult.FAIL;
7576
}
7677
return op.call(blockState, world, player, hitResult);
@@ -82,7 +83,7 @@ public class MixinClientPlayerInteractionManager {
8283
cancellable = true
8384
)
8485
private void fireblanket$filterAttackEntityByTag(PlayerEntity player, Entity target, CallbackInfo ci) {
85-
if (!player.getAbilities().allowModifyWorld && target.getType().isIn(FireblanketConstants.ENTITY_ATTACK_RESTRICTED)) {
86+
if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventAttackEntity(player, target.getType())) {
8687
ci.cancel();
8788
}
8889
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.modfest.fireblanket.mixinsupport;
2+
3+
import net.minecraft.block.BlockState;
4+
import net.minecraft.entity.Entity;
5+
import net.minecraft.entity.EntityType;
6+
import net.minecraft.entity.player.PlayerEntity;
7+
import net.minecraft.item.ItemStack;
8+
import net.modfest.fireblanket.FireblanketConstants;
9+
10+
public class InteractionCheck {
11+
public static boolean preventUseItem(PlayerEntity player, ItemStack stack) {
12+
return stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)
13+
|| (player.isSneaking() && stack.isIn(FireblanketConstants.ITEM_SNEAK_INTERACTION_RESTRICTED));
14+
}
15+
16+
public static boolean preventUseBlock(PlayerEntity player, BlockState blockState) {
17+
return blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)
18+
|| (player.isSneaking() && blockState.isIn(FireblanketConstants.BLOCK_SNEAK_INTERACTION_RESTRICTED));
19+
}
20+
21+
public static boolean preventUseEntity(PlayerEntity player, EntityType<?> entity) {
22+
return entity.isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED)
23+
|| (player.isSneaking() && entity.isIn(FireblanketConstants.ENTITY_SNEAK_INTERACTION_RESTRICTED));
24+
}
25+
26+
public static boolean preventAttackEntity(PlayerEntity player, EntityType<?> entity) {
27+
return entity.isIn(FireblanketConstants.ENTITY_ATTACK_RESTRICTED);
28+
}
29+
}

src/main/resources/data/fireblanket/tags/block/block_interaction_restricted.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"#minecraft:fence_gates",
66
"minecraft:barrel",
77
"minecraft:chest",
8-
"minecraft:trapped_chest",
98
"minecraft:chiseled_bookshelf",
109
"minecraft:repeater",
1110
"minecraft:comparator",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"values": [
3+
"minecraft:lectern"
4+
]
5+
}

0 commit comments

Comments
 (0)