diff --git a/gradle.properties b/gradle.properties index 10879ef..8c18db7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ authors=jaskarth, unascribed contributors=Patbox, IThundxr license=AGPL-3.0-or-later # Mod Version -baseVersion=0.6.0 +baseVersion=0.6.1 # Branch Metadata branch=1.21 tagBranch=1.21 diff --git a/src/main/java/net/modfest/fireblanket/FireblanketConstants.java b/src/main/java/net/modfest/fireblanket/FireblanketConstants.java index dd1a109..de0de31 100644 --- a/src/main/java/net/modfest/fireblanket/FireblanketConstants.java +++ b/src/main/java/net/modfest/fireblanket/FireblanketConstants.java @@ -13,8 +13,11 @@ public class FireblanketConstants { public static final String MOD_ID = "fireblanket"; public static final TagKey BLOCK_INTERACTION_RESTRICTED = tag(RegistryKeys.BLOCK, "block_interaction_restricted"); + public static final TagKey BLOCK_SNEAK_INTERACTION_RESTRICTED = tag(RegistryKeys.BLOCK, "block_sneak_interaction_restricted"); public static final TagKey ITEM_INTERACTION_RESTRICTED = tag(RegistryKeys.ITEM, "item_interaction_restricted"); + public static final TagKey ITEM_SNEAK_INTERACTION_RESTRICTED = tag(RegistryKeys.ITEM, "item_sneak_interaction_restricted"); public static final TagKey> ENTITY_INTERACTION_RESTRICTED = tag(RegistryKeys.ENTITY_TYPE, "entity_interaction_restricted"); + public static final TagKey> ENTITY_SNEAK_INTERACTION_RESTRICTED = tag(RegistryKeys.ENTITY_TYPE, "entity_sneak_interaction_restricted"); public static final TagKey> ENTITY_ATTACK_RESTRICTED = tag(RegistryKeys.ENTITY_TYPE, "entity_attack_restricted"); diff --git a/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinItemStack.java b/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinItemStack.java index 85c491b..014adc4 100644 --- a/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinItemStack.java +++ b/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinItemStack.java @@ -10,6 +10,7 @@ import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import net.modfest.fireblanket.FireblanketConstants; +import net.modfest.fireblanket.mixinsupport.InteractionCheck; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -27,7 +28,7 @@ public abstract class MixinItemStack { private void fireblanket$filterItemUseOnBlockByTag(ItemUsageContext context, CallbackInfoReturnable ci) { PlayerEntity player = context.getPlayer(); if (player == null) return; - if (!player.getAbilities().allowModifyWorld && this.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) { + if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventUseItem(player, (ItemStack)(Object)this)) { ci.setReturnValue(ActionResult.FAIL); ci.cancel(); } @@ -35,7 +36,7 @@ public abstract class MixinItemStack { @Inject(method = "use", at = @At("HEAD"), cancellable = true) private void fireblanket$filterItemUseByTag(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> ci) { - if (!user.getAbilities().allowModifyWorld && this.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) { + if (!user.getAbilities().allowModifyWorld && InteractionCheck.preventUseItem(user, (ItemStack)(Object)this)) { ci.setReturnValue(TypedActionResult.fail(user.getStackInHand(hand))); ci.cancel(); } diff --git a/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinPlayerInteractEntityC2SPacketHandler.java b/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinPlayerInteractEntityC2SPacketHandler.java index ae99c98..d75abc9 100644 --- a/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinPlayerInteractEntityC2SPacketHandler.java +++ b/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinPlayerInteractEntityC2SPacketHandler.java @@ -6,6 +6,7 @@ import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.util.Hand; import net.modfest.fireblanket.FireblanketConstants; +import net.modfest.fireblanket.mixinsupport.InteractionCheck; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -34,9 +35,8 @@ public class MixinPlayerInteractEntityC2SPacketHandler { private void fireblanket$filterEntityInteractByTag(Hand hand, ServerPlayNetworkHandler.Interaction action, CallbackInfo ci) { PlayerEntity player = field_28963.player; ItemStack stack = player.getStackInHand(hand); - if (!player.getAbilities().allowModifyWorld && ( - stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED) || - field_28962.getType().isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED))) { + if (!player.getAbilities().allowModifyWorld && + (InteractionCheck.preventUseItem(player, stack) || InteractionCheck.preventUseEntity(player, field_28962.getType()))) { ci.cancel(); } } @@ -48,7 +48,7 @@ public class MixinPlayerInteractEntityC2SPacketHandler { ) private void fireblanket$filterAttackEntityByTag(CallbackInfo ci) { PlayerEntity player = field_28963.player; - if (!player.getAbilities().allowModifyWorld && field_28962.getType().isIn(FireblanketConstants.ENTITY_ATTACK_RESTRICTED)) { + if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventAttackEntity(player, field_28962.getType())) { ci.cancel(); } } diff --git a/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinServerPlayerInteractionManager.java b/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinServerPlayerInteractionManager.java index ad9e2df..a20269e 100644 --- a/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinServerPlayerInteractionManager.java +++ b/src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinServerPlayerInteractionManager.java @@ -12,6 +12,7 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.world.World; import net.modfest.fireblanket.FireblanketConstants; +import net.modfest.fireblanket.mixinsupport.InteractionCheck; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -23,10 +24,10 @@ public class MixinServerPlayerInteractionManager { ) private ItemActionResult fireblanket$filterItemBlockInteractByTag(BlockState blockState, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hitResult, Operation op) { if (!player.getAbilities().allowModifyWorld) { - if (stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) { + if (InteractionCheck.preventUseItem(player, stack)) { return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } - if (blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) { + if (InteractionCheck.preventUseBlock(player, blockState)) { return ItemActionResult.FAIL; } } @@ -38,7 +39,7 @@ public class MixinServerPlayerInteractionManager { 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;") ) private ActionResult fireblanket$filterBlockInteractByTag(BlockState blockState, World world, PlayerEntity player, BlockHitResult hitResult, Operation op) { - if (!player.getAbilities().allowModifyWorld && blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) { + if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventUseBlock(player, blockState)) { return ActionResult.FAIL; } return op.call(blockState, world, player, hitResult); diff --git a/src/main/java/net/modfest/fireblanket/mixin/client/adventure_fix/MixinClientPlayerInteractionManager.java b/src/main/java/net/modfest/fireblanket/mixin/client/adventure_fix/MixinClientPlayerInteractionManager.java index 12aa279..1f6e1e2 100644 --- a/src/main/java/net/modfest/fireblanket/mixin/client/adventure_fix/MixinClientPlayerInteractionManager.java +++ b/src/main/java/net/modfest/fireblanket/mixin/client/adventure_fix/MixinClientPlayerInteractionManager.java @@ -14,6 +14,7 @@ import net.minecraft.util.hit.EntityHitResult; import net.minecraft.world.World; import net.modfest.fireblanket.FireblanketConstants; +import net.modfest.fireblanket.mixinsupport.InteractionCheck; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -28,8 +29,8 @@ public class MixinClientPlayerInteractionManager { cancellable = true) private void fireblanket$filterEntityInteractByTag(PlayerEntity player, Entity entity, Hand hand, CallbackInfoReturnable ci) { if (!player.getAbilities().allowModifyWorld && ( - entity.getType().isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED) || - player.getStackInHand(hand).isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED))) { + InteractionCheck.preventUseEntity(player, entity.getType()) || + InteractionCheck.preventUseItem(player, player.getStackInHand(hand)))) { ci.setReturnValue(ActionResult.FAIL); ci.cancel(); } @@ -42,8 +43,8 @@ public class MixinClientPlayerInteractionManager { ) private void fireblanket$filterEntityInteractAtLocationByTag(PlayerEntity player, Entity entity, EntityHitResult hitResult, Hand hand, CallbackInfoReturnable ci) { if (!player.getAbilities().allowModifyWorld && ( - entity.getType().isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED) || - player.getStackInHand(hand).isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED))) { + InteractionCheck.preventUseEntity(player, entity.getType()) || + InteractionCheck.preventUseItem(player, player.getStackInHand(hand)))) { ci.setReturnValue(ActionResult.FAIL); ci.cancel(); } @@ -55,10 +56,10 @@ public class MixinClientPlayerInteractionManager { ) private ItemActionResult fireblanket$filterItemBlockInteractByTag(BlockState blockState, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hitResult, Operation op) { if (!player.getAbilities().allowModifyWorld) { - if (stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED)) { + if (InteractionCheck.preventUseItem(player, stack)) { return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } - if (blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) { + if (InteractionCheck.preventUseBlock(player, blockState)) { return ItemActionResult.FAIL; } } @@ -70,7 +71,7 @@ public class MixinClientPlayerInteractionManager { 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;") ) private ActionResult fireblanket$filterBlockInteractByTag(BlockState blockState, World world, PlayerEntity player, BlockHitResult hitResult, Operation op) { - if (!player.getAbilities().allowModifyWorld && blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED)) { + if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventUseBlock(player, blockState)) { return ActionResult.FAIL; } return op.call(blockState, world, player, hitResult); @@ -82,7 +83,7 @@ public class MixinClientPlayerInteractionManager { cancellable = true ) private void fireblanket$filterAttackEntityByTag(PlayerEntity player, Entity target, CallbackInfo ci) { - if (!player.getAbilities().allowModifyWorld && target.getType().isIn(FireblanketConstants.ENTITY_ATTACK_RESTRICTED)) { + if (!player.getAbilities().allowModifyWorld && InteractionCheck.preventAttackEntity(player, target.getType())) { ci.cancel(); } } diff --git a/src/main/java/net/modfest/fireblanket/mixinsupport/InteractionCheck.java b/src/main/java/net/modfest/fireblanket/mixinsupport/InteractionCheck.java new file mode 100644 index 0000000..3d45997 --- /dev/null +++ b/src/main/java/net/modfest/fireblanket/mixinsupport/InteractionCheck.java @@ -0,0 +1,29 @@ +package net.modfest.fireblanket.mixinsupport; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.modfest.fireblanket.FireblanketConstants; + +public class InteractionCheck { + public static boolean preventUseItem(PlayerEntity player, ItemStack stack) { + return stack.isIn(FireblanketConstants.ITEM_INTERACTION_RESTRICTED) + || (player.isSneaking() && stack.isIn(FireblanketConstants.ITEM_SNEAK_INTERACTION_RESTRICTED)); + } + + public static boolean preventUseBlock(PlayerEntity player, BlockState blockState) { + return blockState.isIn(FireblanketConstants.BLOCK_INTERACTION_RESTRICTED) + || (player.isSneaking() && blockState.isIn(FireblanketConstants.BLOCK_SNEAK_INTERACTION_RESTRICTED)); + } + + public static boolean preventUseEntity(PlayerEntity player, EntityType entity) { + return entity.isIn(FireblanketConstants.ENTITY_INTERACTION_RESTRICTED) + || (player.isSneaking() && entity.isIn(FireblanketConstants.ENTITY_SNEAK_INTERACTION_RESTRICTED)); + } + + public static boolean preventAttackEntity(PlayerEntity player, EntityType entity) { + return entity.isIn(FireblanketConstants.ENTITY_ATTACK_RESTRICTED); + } +} diff --git a/src/main/resources/data/fireblanket/tags/block/block_interaction_restricted.json b/src/main/resources/data/fireblanket/tags/block/block_interaction_restricted.json index 2ab9d96..a6404c3 100644 --- a/src/main/resources/data/fireblanket/tags/block/block_interaction_restricted.json +++ b/src/main/resources/data/fireblanket/tags/block/block_interaction_restricted.json @@ -5,7 +5,6 @@ "#minecraft:fence_gates", "minecraft:barrel", "minecraft:chest", - "minecraft:trapped_chest", "minecraft:chiseled_bookshelf", "minecraft:repeater", "minecraft:comparator", diff --git a/src/main/resources/data/fireblanket/tags/block/block_sneak_interaction_restricted.json b/src/main/resources/data/fireblanket/tags/block/block_sneak_interaction_restricted.json new file mode 100644 index 0000000..7ca5019 --- /dev/null +++ b/src/main/resources/data/fireblanket/tags/block/block_sneak_interaction_restricted.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:lectern" + ] +}