Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PotatoPresident committed Nov 13, 2022
1 parent 3edfd88 commit a8d0d29
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class HTMConfig {
.setPrettyPrinting()
.create();

public boolean canTrustedPlayersBreakChests;
public boolean canTrustedPlayersBreakChests = false;

public final Map<String, Boolean> defaultFlags = new HashMap<>();

Expand Down Expand Up @@ -56,10 +56,8 @@ public class HTMConfig {

public HTMConfig() {
defaultFlags.put("hoppers", true);
canTrustedPlayersBreakChests = false;
}


public static HTMConfig loadConfig(File file) {
HTMConfig config;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static boolean onBeforeBreak(World world, PlayerEntity player, BlockPos

if (!lock.isLocked()) return true;

if (lock.isOwner((ServerPlayerEntity) player) || (HTM.config.canTrustedPlayersBreakChests && lock.getTrusted().contains(((ServerPlayerEntity) player).getUuid()))) {
if (lock.isOwner((ServerPlayerEntity) player) || (HTM.config.canTrustedPlayersBreakChests && lock.getTrusted().contains(player.getUuid()))) {
if (state.getBlock() instanceof LockableChestBlock) {
Optional<BlockEntity> unlocked = ((LockableChestBlock) state.getBlock()).getUnlockedPart(state, world, pos);
if (unlocked.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,19 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

@Mixin(HopperBlockEntity.class)
public abstract class HopperBlockEntityMixin {
/*
@Redirect(method = "getInventoryAt(Lnet/minecraft/world/World;DDD)Lnet/minecraft/inventory/Inventory;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/entity/BlockEntity;"))
private static BlockEntity getProtectedInventory(World world, BlockPos pos) {
BlockEntity blockEntity = Objects.requireNonNull(world.getBlockEntity(pos));
if (world.isClient) return blockEntity;
HTMContainerLock lock = InteractionManager.getLock((ServerWorld) world, blockEntity);
if (lock == null) {
return blockEntity;
}
if (!lock.isLocked()) {
return blockEntity;
}
if (lock.getFlags().get("hoppers")) {
return blockEntity;
}
return null;
}
*/

@Inject(method = "extract(Lnet/minecraft/world/World;Lnet/minecraft/block/entity/Hopper;)Z", at = @At("HEAD"), cancellable = true)
@Inject(method = "extract(Lnet/minecraft/world/World;Lnet/minecraft/block/entity/Hopper;)Z", at = @At(value = "FIELD", target = "Lnet/minecraft/util/math/Direction;DOWN:Lnet/minecraft/util/math/Direction;", shift = At.Shift.AFTER), cancellable = true)
private static void extractHTMCheck(World world, Hopper hopper, CallbackInfoReturnable<Boolean> cir) {
// only checks extraction, so only needs to check block above hopper
if (!isBlockContainerHopperable(world, new BlockPos(hopper.getHopperX(), hopper.getHopperY(), hopper.getHopperZ()).offset(Direction.UP)))
cir.setReturnValue(true); // if block is not hopperable, cancel the extract method call
// otherwise continue the extract method as normal
}

//TODO optimize better
private static boolean isBlockContainerHopperable(World world, BlockPos pos) {
if (world.isClient) return true;

Expand Down

0 comments on commit a8d0d29

Please sign in to comment.