Skip to content

Commit

Permalink
Fix for #209: custom inventories act trapped config.
Browse files Browse the repository at this point in the history
Simple configuration option that causes custom inventories to act like
trapped chests by updating neighbours and neighbours below when set to
true.
  • Loading branch information
noobanidus committed Jan 25, 2024
1 parent 99465b6 commit e274129
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/noobanidus/mods/lootr/block/LootrInventoryBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -115,6 +116,30 @@ public int getAnalogOutputSignal(BlockState pBlockState, Level pLevel, BlockPos
}
}

@Override
public boolean isSignalSource(BlockState pState) {
return ConfigManager.TRAPPED_CUSTOM.get();
}

@Override
public int getSignal(BlockState pBlockState, BlockGetter pBlockAccess, BlockPos pPos, Direction pSide) {
if (ConfigManager.TRAPPED_CUSTOM.get()) {
return Mth.clamp(LootrChestBlockEntity.getOpenCount(pBlockAccess, pPos), 0, 15);
} else {
return 0;
}
}

@Override
public int getDirectSignal(BlockState pBlockState, BlockGetter pBlockAccess, BlockPos pPos, Direction pSide) {
if (ConfigManager.TRAPPED_CUSTOM.get()) {
return pSide == Direction.UP ? pBlockState.getSignal(pBlockAccess, pPos, pSide) : 0;
} else {
return 0;
}
}


@Override
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState, BlockEntityType<T> pBlockEntityType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import noobanidus.mods.lootr.config.ConfigManager;
import noobanidus.mods.lootr.init.ModBlockEntities;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -57,4 +60,14 @@ public void setCustomInventory(NonNullList<ItemStack> customInventory) {
public void onDataPacket(@Nonnull Connection net, @Nonnull ClientboundBlockEntityDataPacket pkt) {
load(pkt.getTag());
}

@Override
protected void signalOpenCount(Level level, BlockPos pos, BlockState state, int p_155868_, int p_155869_) {
super.signalOpenCount(level, pos, state, p_155868_, p_155869_);
if (ConfigManager.TRAPPED_CUSTOM.get() && p_155868_ != p_155869_) {
Block block = state.getBlock();
level.updateNeighborsAt(pos, block);
level.updateNeighborsAt(pos.below(), block);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/noobanidus/mods/lootr/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class ConfigManager {
public static final ForgeConfigSpec.BooleanValue BLAST_IMMUNE;
public static final ForgeConfigSpec.IntValue NOTIFICATION_DELAY;
public static final ForgeConfigSpec.BooleanValue DISABLE_NOTIFICATIONS;
public static final ForgeConfigSpec.BooleanValue TRAPPED_CUSTOM;

// Client-only
public static final ForgeConfigSpec.BooleanValue VANILLA_TEXTURES;
Expand Down Expand Up @@ -155,6 +156,7 @@ public class ConfigManager {
CHECK_WORLD_BORDER = COMMON_BUILDER.comment("disregard chests and chunks that are outside of the world border; enable this option if you are using a world border and are suffering consistent TPS issues; if you change the world border, you will need to restart your client").define("check_world_border", false);
ENABLE_FAKE_PLAYER_BREAK = COMMON_BUILDER.comment("allows fake players to destroy Lootr chests without having to sneak, overrides the `disable_break` option for fake players").define("enable_fake_player_break", false);
POWER_COMPARATORS = COMMON_BUILDER.comment("when true, comparators on Lootr containers will give an output of 1; when false, they will give an output of 0").define("power_comparators", true);
TRAPPED_CUSTOM = COMMON_BUILDER.comment("when true, custom inventories will act like trapped chests when opened").define("trapped_custom", false);
BLAST_RESISTANT = COMMON_BUILDER.comment("lootr chests cannot be destroyed by creeper or TNT explosions").define("blast_resistant", false);
BLAST_IMMUNE = COMMON_BUILDER.comment("lootr chests cannot be destroyed by any explosion").define("blast_immune", false);
DISABLE_NOTIFICATIONS = COMMON_BUILDER.comment("prevent notifications of decaying or refreshed chests").define("disable_notifications", false);
Expand Down

0 comments on commit e274129

Please sign in to comment.