Skip to content

Commit

Permalink
Merge pull request #21 from ModFest/mf-1.21
Browse files Browse the repository at this point in the history
create tag blocking sneak click interacts
  • Loading branch information
HamaIndustries authored Nov 29, 2024
2 parents 26d3667 + 846f0f7 commit 14f5605
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public class FireblanketConstants {
public static final String MOD_ID = "fireblanket";

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,15 +28,15 @@ public abstract class MixinItemStack {
private void fireblanket$filterItemUseOnBlockByTag(ItemUsageContext context, CallbackInfoReturnable<ActionResult> 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();
}
}

@Inject(method = "use", at = @At("HEAD"), cancellable = true)
private void fireblanket$filterItemUseByTag(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,10 +24,10 @@ public class MixinServerPlayerInteractionManager {
)
private ItemActionResult fireblanket$filterItemBlockInteractByTag(BlockState blockState, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hitResult, Operation<ItemActionResult> 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;
}
}
Expand All @@ -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<ActionResult> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,8 +29,8 @@ public class MixinClientPlayerInteractionManager {
cancellable = true)
private void fireblanket$filterEntityInteractByTag(PlayerEntity player, Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> 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();
}
Expand All @@ -42,8 +43,8 @@ public class MixinClientPlayerInteractionManager {
)
private void fireblanket$filterEntityInteractAtLocationByTag(PlayerEntity player, Entity entity, EntityHitResult hitResult, Hand hand, CallbackInfoReturnable<ActionResult> 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();
}
Expand All @@ -55,10 +56,10 @@ public class MixinClientPlayerInteractionManager {
)
private ItemActionResult fireblanket$filterItemBlockInteractByTag(BlockState blockState, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hitResult, Operation<ItemActionResult> 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;
}
}
Expand All @@ -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<ActionResult> 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);
Expand All @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"#minecraft:fence_gates",
"minecraft:barrel",
"minecraft:chest",
"minecraft:trapped_chest",
"minecraft:chiseled_bookshelf",
"minecraft:repeater",
"minecraft:comparator",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:lectern"
]
}

0 comments on commit 14f5605

Please sign in to comment.