Skip to content

Commit 9568794

Browse files
author
DragonEggBedrockBreaking
committed
Add gamerule to toggle blocks/cats stopping containers being opened
1 parent d099e10 commit 9568794

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

src/main/java/uk/debb/vanilla_disable/gamerules/RegisterGamerules.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ public static MinecraftServer getServer() {
382382
public static GameRules.Key<GameRules.BooleanValue> CROSSBOW_SPAMMING;
383383
public static GameRules.Key<GameRules.BooleanValue> CREATIVE_SWORD_CAN_BREAK_BLOCKS;
384384
public static GameRules.Key<GameRules.BooleanValue> PUSHABLE_BUDDING_AMETHYST;
385+
public static GameRules.Key<GameRules.BooleanValue> CONTAINER_OPENING_BLOCKED;
385386

386387
@Override
387388
public void onInitialize() {
@@ -1097,6 +1098,8 @@ public void onInitialize() {
10971098
"creativeSwordCanBreakBlocks", CreateGameruleCategories.VD_MISC, GameRuleFactory.createBooleanRule(false));
10981099
PUSHABLE_BUDDING_AMETHYST = GameRuleRegistry.register(
10991100
"pushableBuddingAmethyst", CreateGameruleCategories.VD_MISC, GameRuleFactory.createBooleanRule(false));
1101+
CONTAINER_OPENING_BLOCKED = GameRuleRegistry.register(
1102+
"containerOpeningBlocked", CreateGameruleCategories.VD_MISC, GameRuleFactory.createBooleanRule(true));
11001103
}
11011104

11021105
// Registering the Minecraft server to when it actually starts
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package uk.debb.vanilla_disable.mixin.misc;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.injection.At;
5+
import org.spongepowered.asm.mixin.injection.Inject;
6+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
7+
import net.minecraft.core.BlockPos;
8+
import net.minecraft.world.level.LevelAccessor;
9+
import net.minecraft.world.level.block.ChestBlock;
10+
import uk.debb.vanilla_disable.gamerules.RegisterGamerules;
11+
12+
@Mixin(ChestBlock.class)
13+
public abstract class MixinChestBlock {
14+
/**
15+
* @author DragonEggBedrockBreaking
16+
* @reason prevent containers from being blocked
17+
* @param levelAccessor the accessor for the level
18+
* @param blockPos the position of the chest
19+
* @param cir the returnable callback info (Boolean)
20+
*/
21+
@Inject(method = "isChestBlockedAt", at = @At("HEAD"), cancellable = true)
22+
private static void chestNotBlocked(LevelAccessor levelAccessor, BlockPos blockPos, CallbackInfoReturnable<Boolean> cir) {
23+
if (RegisterGamerules.getServer() == null) return;
24+
if (!RegisterGamerules.getServer().getGameRules().getBoolean(RegisterGamerules.CONTAINER_OPENING_BLOCKED)) {
25+
cir.setReturnValue(false);
26+
}
27+
}
28+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package uk.debb.vanilla_disable.mixin.misc;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.world.InteractionHand;
5+
import net.minecraft.world.entity.player.Player;
6+
import net.minecraft.world.level.BlockGetter;
7+
import net.minecraft.world.level.Level;
8+
import net.minecraft.world.level.block.EnderChestBlock;
9+
import net.minecraft.world.level.block.state.BlockState;
10+
import net.minecraft.world.phys.BlockHitResult;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.Redirect;
14+
import uk.debb.vanilla_disable.gamerules.RegisterGamerules;
15+
16+
@Mixin(EnderChestBlock.class)
17+
public abstract class MixinEnderChestBlock {
18+
/**
19+
* @author DragonEggBedrockBreaking
20+
* @param blockState the state of the block above the echest
21+
* @param blockGetter the getter of the block above the echest
22+
* @param blockPos the position of the block above the echest
23+
* @param blockState2 the state of the block above the echest
24+
* @param level the level the echest is in
25+
* @param blockPos2 the position of the block above the echest
26+
* @param player the player trying to open the echest
27+
* @param interactionHand the hand the player is trying to open the echest with
28+
* @param blockHitResult the result of the player trying to open the echest
29+
* @return whether or not the player can open the echest
30+
*/
31+
@Redirect(
32+
method = "use",
33+
at = @At(
34+
value = "INVOKE",
35+
target = "Lnet/minecraft/world/level/block/state/BlockState;isRedstoneConductor(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Z"
36+
)
37+
)
38+
private boolean isFullBlock(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, BlockState blockState2, Level level, BlockPos blockPos2, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
39+
if (RegisterGamerules.getServer() == null) return blockState.isRedstoneConductor(blockGetter, blockPos);
40+
if (!RegisterGamerules.getServer().getGameRules().getBoolean(RegisterGamerules.CONTAINER_OPENING_BLOCKED)) {
41+
return false;
42+
}
43+
return blockState.isRedstoneConductor(blockGetter, blockPos);
44+
}
45+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package uk.debb.vanilla_disable.mixin.misc;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.injection.At;
5+
import org.spongepowered.asm.mixin.injection.Inject;
6+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
7+
import net.minecraft.core.BlockPos;
8+
import net.minecraft.world.level.Level;
9+
import net.minecraft.world.level.block.ShulkerBoxBlock;
10+
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
11+
import net.minecraft.world.level.block.state.BlockState;
12+
import uk.debb.vanilla_disable.gamerules.RegisterGamerules;
13+
14+
@Mixin(ShulkerBoxBlock.class)
15+
public abstract class MixinShulkerBoxBlock {
16+
/**
17+
* @author DragonEggBedrockBreaking
18+
* @param blockState the state of the shulker box
19+
* @param level the level the shulker box is in
20+
* @param blockPos the position of the shulker box
21+
* @param shulkerBoxBlockEntity the block entity code for the shulker box
22+
* @param cir the returnable callback info (Boolean)
23+
*/
24+
@Inject(method = "canOpen", at = @At("HEAD"), cancellable = true)
25+
private static void canAlwaysOpen(BlockState blockState, Level level, BlockPos blockPos, ShulkerBoxBlockEntity shulkerBoxBlockEntity, CallbackInfoReturnable<Boolean> cir) {
26+
if (RegisterGamerules.getServer() == null) return;
27+
if (!RegisterGamerules.getServer().getGameRules().getBoolean(RegisterGamerules.CONTAINER_OPENING_BLOCKED)) {
28+
cir.setReturnValue(true);
29+
}
30+
}
31+
}

src/main/resources/assets/vanilla_disable/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@
355355
"gamerule.crossbowSpamming": "Toggle whether crossbows have no cooldown",
356356
"gamerule.creativeSwordCanBreakBlocks": "Toggle whether a sword can break blocks in creative mode",
357357
"gamerule.pushableBuddingAmethyst": "Toggle whether budding amethyst blocks can be pushed by pistons",
358+
"gamerule.containerOpeningBlocked": "Toggle whether blocks or cats above containers block them",
358359

359360
"gamerule.category.vd.damage": "VanillaDisable Damage",
360361
"gamerule.category.vd.knockback": "VanillaDisable Knockback",

src/main/resources/vanilla_disable.mixins.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@
4242
"misc.MixinBlock",
4343
"misc.MixinBowItem",
4444
"misc.MixinBuddingAmethystBlock",
45+
"misc.MixinChestBlock",
4546
"misc.MixinConduitBlockEntity",
4647
"misc.MixinCrossbowItem",
48+
"misc.MixinEnderChestBlock",
4749
"misc.MixinEndPortalBlock",
4850
"misc.MixinEntity",
4951
"misc.MixinFarmBlock",
5052
"misc.MixinLivingEntity",
5153
"misc.MixinNetherPortalBlock",
54+
"misc.MixinShulkerBoxBlock",
5255
"misc.MixinSwordItem",
5356
"misc.MixinTheEndGatewayBlockEntity",
5457
"misc.hunger.MixinFoodData",

0 commit comments

Comments
 (0)