fancier redstone visualization

This commit is contained in:
yrsegal@gmail.com 2022-04-24 13:00:04 -04:00
parent 827ae99f69
commit b424198a0e
5 changed files with 49 additions and 37 deletions

View file

@ -37,6 +37,8 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
@ -115,9 +117,11 @@ public abstract class BlockEntityAbstractImpetus extends PaucalBlockEntity imple
this.stepCircle();
}
@OnlyIn(Dist.CLIENT)
public void applyScryingLensOverlay(List<Pair<ItemStack, Component>> lines,
BlockState state, BlockPos pos,
LocalPlayer observer, ClientLevel world, InteractionHand lensHand) {
LocalPlayer observer, ClientLevel world,
Direction hitFace, InteractionHand lensHand) {
if (world.getBlockEntity(pos) instanceof BlockEntityAbstractImpetus beai) {
var dustCount = (float) beai.getMana() / (float) HexConfig.dustManaAmount.get();
var dustCmp = new TranslatableComponent("hexcasting.tooltip.lens.impetus.mana",

View file

@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
@ -111,16 +112,16 @@ public final class ScryingLensOverlayRegistry {
*/
public static @NotNull List<Pair<ItemStack, Component>> getLines(BlockState state, BlockPos pos,
LocalPlayer observer, ClientLevel world,
@Nullable InteractionHand lensHand) {
Direction hitFace, @Nullable InteractionHand lensHand) {
List<Pair<ItemStack, Component>> lines = Lists.newArrayList();
var idLookedup = ID_LOOKUP.get(state.getBlock().getRegistryName());
if (idLookedup != null) {
idLookedup.addLines(lines, state, pos, observer, world, lensHand);
idLookedup.addLines(lines, state, pos, observer, world, hitFace, lensHand);
}
for (var pair : PREDICATE_LOOKUP) {
if (pair.getFirst().test(state, pos, observer, world, lensHand)) {
pair.getSecond().addLines(lines, state, pos, observer, world, lensHand);
if (pair.getFirst().test(state, pos, observer, world, hitFace, lensHand)) {
pair.getSecond().addLines(lines, state, pos, observer, world, hitFace, lensHand);
}
}
@ -137,7 +138,7 @@ public final class ScryingLensOverlayRegistry {
void addLines(List<Pair<ItemStack, Component>> lines,
BlockState state, BlockPos pos, LocalPlayer observer,
ClientLevel world,
@Nullable InteractionHand lensHand);
Direction hitFace, @Nullable InteractionHand lensHand);
}
/**
@ -145,6 +146,8 @@ public final class ScryingLensOverlayRegistry {
*/
@FunctionalInterface
public interface OverlayPredicate {
boolean test(BlockState state, BlockPos pos, LocalPlayer observer, ClientLevel world, @Nullable InteractionHand lensHand);
boolean test(BlockState state, BlockPos pos, LocalPlayer observer,
ClientLevel world,
Direction hitFace, @Nullable InteractionHand lensHand);
}
}

View file

@ -173,7 +173,7 @@ public class HexAdditionalRenderers {
var pos = bhr.getBlockPos();
var bs = mc.level.getBlockState(pos);
var lines = ScryingLensOverlayRegistry.getLines(bs, pos, mc.player, mc.level, lensHand);
var lines = ScryingLensOverlayRegistry.getLines(bs, pos, mc.player, mc.level, bhr.getDirection(), lensHand);
if (!lines.isEmpty()) {
var window = mc.getWindow();
var x = window.getGuiScaledWidth() / 2f + 8f;

View file

@ -33,10 +33,7 @@ import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ComparatorBlock;
import net.minecraft.world.level.block.RepeaterBlock;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.properties.ComparatorMode;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
@ -106,15 +103,15 @@ public class RegisterClientStuff {
private static void addScryingLensStuff() {
ScryingLensOverlayRegistry.addPredicateDisplayer(
(state, pos, observer, world, lensHand) -> state.getBlock() instanceof BlockAbstractImpetus,
(lines, state, pos, observer, world, lensHand) -> {
(state, pos, observer, world, direction, lensHand) -> state.getBlock() instanceof BlockAbstractImpetus,
(lines, state, pos, observer, world, direction, lensHand) -> {
if (world.getBlockEntity(pos) instanceof BlockEntityAbstractImpetus beai) {
beai.applyScryingLensOverlay(lines, state, pos, observer, world, lensHand);
beai.applyScryingLensOverlay(lines, state, pos, observer, world, direction, lensHand);
}
});
ScryingLensOverlayRegistry.addDisplayer(HexBlocks.AKASHIC_BOOKSHELF.get(),
(lines, state, pos, observer, world, lensHand) -> {
(lines, state, pos, observer, world, direction, lensHand) -> {
if (world.getBlockEntity(pos) instanceof BlockEntityAkashicBookshelf tile) {
var recordPos = tile.getRecordPos();
var pattern = tile.getPattern();
@ -131,7 +128,7 @@ public class RegisterClientStuff {
});
ScryingLensOverlayRegistry.addDisplayer(HexBlocks.AKASHIC_RECORD.get(),
(lines, state, pos, observer, world, lensHand) -> {
(lines, state, pos, observer, world, direction, lensHand) -> {
if (world.getBlockEntity(pos) instanceof BlockEntityAkashicRecord tile) {
int count = tile.getCount();
@ -142,16 +139,8 @@ public class RegisterClientStuff {
}
});
ScryingLensOverlayRegistry.addDisplayer(Blocks.REDSTONE_WIRE,
(lines, state, pos, observer, world, lensHand) -> lines.add(
new Pair<>(
new ItemStack(Items.REDSTONE),
new TextComponent(String.valueOf(state.getValue(BlockStateProperties.POWER)))
.withStyle(ChatFormatting.RED))
));
ScryingLensOverlayRegistry.addDisplayer(Blocks.COMPARATOR,
(lines, state, pos, observer, world, lensHand) -> {
(lines, state, pos, observer, world, direction, lensHand) -> {
int comparatorValue = ScryingLensOverlayRegistry.getComparatorValue(true);
lines.add(new Pair<>(
new ItemStack(Items.REDSTONE),
@ -165,20 +154,31 @@ public class RegisterClientStuff {
});
ScryingLensOverlayRegistry.addDisplayer(Blocks.REPEATER,
(lines, state, pos, observer, world, lensHand) -> {
lines.add(new Pair<>(
(lines, state, pos, observer, world, direction, lensHand) -> lines.add(new Pair<>(
new ItemStack(Items.CLOCK),
new TextComponent(String.valueOf(state.getValue(RepeaterBlock.DELAY)))
.withStyle(ChatFormatting.YELLOW))));
ScryingLensOverlayRegistry.addPredicateDisplayer(
(state, pos, observer, world, direction, lensHand) -> state.isSignalSource() && !state.is(Blocks.COMPARATOR),
(lines, state, pos, observer, world, direction, lensHand) -> {
int signalStrength;
if (state.getBlock() instanceof DiodeBlock)
signalStrength = state.getSignal(world, pos, state.getValue(DiodeBlock.FACING));
else if (state.getBlock() instanceof RedStoneWireBlock)
signalStrength = state.getValue(RedStoneWireBlock.POWER);
else
signalStrength = state.getSignal(world, pos, direction);
lines.add(0, new Pair<>(
new ItemStack(Items.REDSTONE),
new TextComponent(String.valueOf(state.getValue(RepeaterBlock.POWERED) ? 15 : 0))
new TextComponent(String.valueOf(signalStrength))
.withStyle(ChatFormatting.RED)));
lines.add(new Pair<>(
new ItemStack(Items.CLOCK),
new TextComponent(String.valueOf(state.getValue(RepeaterBlock.DELAY)))
.withStyle(ChatFormatting.YELLOW)));
});
ScryingLensOverlayRegistry.addPredicateDisplayer(
(state, pos, observer, world, lensHand) -> state.hasAnalogOutputSignal(),
(lines, state, pos, observer, world, lensHand) -> {
(state, pos, observer, world, direction, lensHand) -> state.hasAnalogOutputSignal(),
(lines, state, pos, observer, world, direction, lensHand) -> {
int comparatorValue = ScryingLensOverlayRegistry.getComparatorValue(false);
lines.add(
new Pair<>(

View file

@ -6,6 +6,7 @@ import com.mojang.datafixers.util.Pair;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
@ -15,6 +16,8 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@ -50,10 +53,12 @@ public class BlockEntityStoredPlayerImpetus extends BlockEntityAbstractImpetus {
}
@Override
@OnlyIn(Dist.CLIENT)
public void applyScryingLensOverlay(List<Pair<ItemStack, Component>> lines,
BlockState state, BlockPos pos, LocalPlayer observer,
ClientLevel world, InteractionHand lensHand) {
super.applyScryingLensOverlay(lines, state, pos, observer, world, lensHand);
ClientLevel world,
Direction hitFace, InteractionHand lensHand) {
super.applyScryingLensOverlay(lines, state, pos, observer, world, hitFace, lensHand);
var bound = this.getPlayer();
if (bound != null) {