Skip to content

Commit

Permalink
Fabric; Fix: access to value behaviours wont get falsely blocked anym…
Browse files Browse the repository at this point in the history
…ore.
  • Loading branch information
SammyForReal committed Aug 13, 2023
1 parent 1262413 commit fdacf88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cc.tweaked_programs.cccbridge.common.mixin.scroller;

import cc.tweaked_programs.cccbridge.common.minecraft.block.ScrollerBlock;
import cc.tweaked_programs.cccbridge.common.create.behaviour.LuaScrollValueBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueRenderer;
import com.simibubi.create.foundation.utility.AdventureUtil;
Expand All @@ -9,20 +9,22 @@
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ScrollValueRenderer.class)
public abstract class MixinScrollValueRenderer {
@Unique
private static boolean isPhysicalPlayer(Player player) {
return player != null && !player.isSpectator();
}

@Redirect(method = "addBox", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/foundation/utility/AdventureUtil;isAdventure(Lnet/minecraft/world/entity/player/Player;)Z"), remap = false)
@Redirect(method = "addBox", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/foundation/utility/AdventureUtil;isAdventure(Lnet/minecraft/world/entity/player/Player;)Z"))
private static boolean cccbridge$addBox$redirectIsAdventure(Player player, ClientLevel world, BlockPos pos, Direction face, ScrollValueBehaviour behaviour, boolean highlight) {
if (world.getBlockState(pos).getBlock() instanceof ScrollerBlock)
if (behaviour instanceof LuaScrollValueBehaviour)
return isPhysicalPlayer(player);

return AdventureUtil.isAdventure(player);
return !AdventureUtil.isAdventure(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,27 @@
import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsInputHandler;
import com.simibubi.create.foundation.utility.AdventureUtil;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ValueSettingsInputHandler.class)
public class MixinValueSettingsInputHandler {
private static boolean isPhysicalPlayer(Player player) {
return player != null && !player.isSpectator();
}

@Redirect(method = "canInteract", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/foundation/utility/AdventureUtil;isAdventure(Lnet/minecraft/world/entity/player/Player;)Z"), remap = false)
@Redirect(method = "canInteract", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/foundation/utility/AdventureUtil;isAdventure(Lnet/minecraft/world/entity/player/Player;)Z"))
private static boolean cccbridge$canInteract$redirectIsAdventure(Player player) {
Level level = player.level();
HitResult hitResult = player.pick(5, 1, false);

if (hitResult instanceof BlockHitResult blockHit) {
BlockEntity blockEntity = level.getBlockEntity(blockHit.getBlockPos());
BlockEntity blockEntity = player.level().getBlockEntity(blockHit.getBlockPos());

if (blockEntity instanceof ScrollerBlockEntity)
return !isPhysicalPlayer(player);
return false;
}

return !AdventureUtil.isAdventure(player);
return AdventureUtil.isAdventure(player);
}
}

0 comments on commit fdacf88

Please sign in to comment.