Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/simibubi/create/AllKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public enum AllKeys {
SHIFT_MODIFIER("shift_modifier", GLFW.GLFW_KEY_LEFT_SHIFT, "Shift Modifier", true),
CTRL_MODIFIER("ctrl_modifier", GLFW.GLFW_KEY_LEFT_CONTROL, "Ctrl Modifier", true),
ALT_MODIFIER("alt_modifier", GLFW.GLFW_KEY_LEFT_ALT, "Alt Modifier", true),

TOGGLE_GOGGLES("toggle_goggles", GLFW.GLFW_KEY_UNKNOWN, "Toggle Engineer's Goggles"),
;

private KeyMapping keybind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;

import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation;
import com.simibubi.create.content.logistics.filter.FilterItem;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;
Expand All @@ -17,9 +19,12 @@
import net.createmod.catnip.lang.Lang;
import net.createmod.catnip.math.AngleHelper;
import net.createmod.catnip.math.VecHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.EntityBlock;
Expand All @@ -31,7 +36,7 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

public class RollerBlockEntity extends SmartBlockEntity {
public class RollerBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation {

// For simulations such as Ponder
private float manuallyAnimatedSpeed;
Expand Down Expand Up @@ -144,6 +149,51 @@ public void shareValuesToAdjacent() {
}
}


@Override
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
CreateLang.translate("tooltip.mechanical_roller.header")
.forGoggles(tooltip);

boolean hasFilter = addFilterTooltip(tooltip);
if (!hasFilter) {
tooltip.remove(0);
return false;
}
return true;
}

private boolean addFilterTooltip(List<Component> tooltip) {
// Get filter blocks and items
ItemStack filterStack = filtering == null ? ItemStack.EMPTY : filtering.getFilter();
// Verify if the roller has a filter
if (filterStack.isEmpty())
return false;

tooltip.add(CommonComponents.EMPTY);
List<Component> filterSummary;

CreateLang.translate("gui.filter.allow_item")
.style(ChatFormatting.GOLD)
.forGoggles(tooltip);
filterSummary = List.of(Component.literal("- ").append(filterStack.getHoverName())
.withStyle(ChatFormatting.GRAY));

// If the filter summary is not empty, add it to the tooltip
if (!filterSummary.isEmpty()) {
// Add the filter type (allow or deny) in the goggles tooltip format
CreateLang.builder()
.add(filterSummary.get(0))
.forGoggles(tooltip);
// Add the filter blocks and items in the goggles tooltip format
for (int i = 1; i < filterSummary.size(); i++)
CreateLang.builder()
.add(filterSummary.get(i))
.forGoggles(tooltip, 1);
}
return true;
}

static enum RollingMode implements INamedIconOptions {

TUNNEL_PAVE(AllIcons.I_ROLLER_PAVE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -147,4 +148,10 @@ public String getTranslationKey() {

}

@Override
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
super.addToGoggleTooltip(tooltip, isPlayerSneaking);
addToGoggleRotationDirectionTooltip(tooltip);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.simibubi.create.content.equipment.goggles;

import com.simibubi.create.AllKeys;
import net.minecraft.client.Minecraft;

public class GoggleInputHandler {

public static void onKeyInput(int key, boolean pressed) {
if (!pressed)
return;

if (AllKeys.TOGGLE_GOGGLES.doesModifierAndCodeMatch(key)) {
GoggleOverlayRenderer.toggleGoggleOverlay();
Minecraft.getInstance().player.displayClientMessage(
net.minecraft.network.chat.Component.literal("Goggle overlay " +
(GoggleOverlayRenderer.goggleOverlayEnabled ? "enabled" : "disabled")),
true);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public class GoggleOverlayRenderer {
public static int hoverTicks = 0;
public static BlockPos lastHovered = null;

public static boolean goggleOverlayEnabled = true;

public static void toggleGoggleOverlay() {

if (GogglesItem.isWearingGoggles(Minecraft.getInstance().player))
goggleOverlayEnabled = !goggleOverlayEnabled;
}

public static void renderOverlay(GuiGraphics guiGraphics, DeltaTracker deltaTracker) {
Minecraft mc = Minecraft.getInstance();
if (mc.options.hideGui || mc.gameMode.getPlayerMode() == GameType.SPECTATOR)
Expand Down Expand Up @@ -106,7 +114,10 @@ public static void renderOverlay(GuiGraphics guiGraphics, DeltaTracker deltaTrac
if (be instanceof IHaveCustomOverlayIcon customOverlayIcon)
item = customOverlayIcon.getIcon(isShifting);

if (hasGoggleInformation && wearingGoggles) {

boolean showGoggleInfo = wearingGoggles && goggleOverlayEnabled;

if (hasGoggleInformation && showGoggleInfo) {
IHaveGoggleInformation gte = (IHaveGoggleInformation) be;
goggleAddedInformation = gte.addToGoggleTooltip(tooltip, isShifting);
}
Expand Down Expand Up @@ -142,7 +153,7 @@ public static void renderOverlay(GuiGraphics guiGraphics, DeltaTracker deltaTrac

// check for piston poles if goggles are worn
BlockState state = world.getBlockState(pos);
if (wearingGoggles && AllBlocks.PISTON_EXTENSION_POLE.has(state)) {
if (showGoggleInfo && AllBlocks.PISTON_EXTENSION_POLE.has(state)) {
Direction[] directions = Iterate.directionsInAxis(state.getValue(PistonExtensionPoleBlock.FACING)
.getAxis());
int poles = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
import java.util.List;

import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation;
import com.simibubi.create.content.fluids.FluidPropagator;
import com.simibubi.create.content.fluids.pipes.StraightPipeBlockEntity.StraightPipeFluidTransportBehaviour;
import com.simibubi.create.content.logistics.filter.FilterItem;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;
import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour;
import com.simibubi.create.foundation.utility.CreateLang;

import dev.engine_room.flywheel.lib.transform.TransformStack;
import net.createmod.catnip.math.AngleHelper;
import net.createmod.catnip.math.VecHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Clearable;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelAccessor;
Expand All @@ -26,7 +32,7 @@

import net.neoforged.neoforge.fluids.FluidStack;

public class SmartFluidPipeBlockEntity extends SmartBlockEntity implements Clearable {
public class SmartFluidPipeBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation, Clearable {
private FilteringBehaviour filter;

public SmartFluidPipeBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
Expand All @@ -51,6 +57,57 @@ private void onFilterChanged(ItemStack newFilter) {
FluidPropagator.propagateChangedPipe(level, worldPosition, getBlockState());
}

@Override
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
CreateLang.translate("tooltip.smart_fluid_pipe.header")
.forGoggles(tooltip);

boolean hasFilter = addFilterTooltip(tooltip);
if (!hasFilter) {
tooltip.remove(0);
return false;
}
return true;
}

private boolean addFilterTooltip(List<Component> tooltip) {
// Get filter blocks and items
ItemStack filterStack = filter == null ? ItemStack.EMPTY : filter.getFilter();
// Verify if the smart fluid pipe has a filter
if (filterStack.isEmpty())
return false;

tooltip.add(CommonComponents.EMPTY);
List<Component> filterSummary;
// If the filter is an item filter, use its summary, otherwise just show the item
if (filterStack.getItem() instanceof FilterItem filterItem) {
filterSummary = filterItem.makeSummary(filterStack);
} else {
CreateLang.translate("gui.filter.allow_item")
.style(ChatFormatting.GOLD)
.forGoggles(tooltip);
filterSummary = List.of(Component.literal("- ").append(filterStack.getHoverName())
.withStyle(ChatFormatting.GRAY));
}
// If the filter summary is not empty, add it to the tooltip
if (!filterSummary.isEmpty()) {
// Add the filter type (allow or deny) in the goggles tooltip format
CreateLang.builder()
.add(filterSummary.get(0))
.forGoggles(tooltip);
// Add the filter blocks and items in the goggles tooltip format
for (int i = 1; i < filterSummary.size(); i++)
CreateLang.builder()
.add(filterSummary.get(i))
.forGoggles(tooltip, 1);
} else {
CreateLang.translate("gui.filter.empty")
.style(ChatFormatting.DARK_GRAY)
.forGoggles(tooltip);
}
return true;
}

class SmartPipeBehaviour extends StraightPipeFluidTransportBehaviour {
public SmartPipeBehaviour(SmartBlockEntity be) {
super(be);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.createmod.catnip.nbt.NBTHelper;
import net.createmod.catnip.platform.CatnipServices;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -49,9 +50,10 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.fml.loading.FMLEnvironment;

public class KineticBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation, IHaveHoveringInformation {

Expand Down Expand Up @@ -468,6 +470,54 @@ public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneak

}

protected void addToGoggleRotationDirectionTooltip(List<Component> tooltip) {
float speed = getSpeed();
// If the block isn't generating its own speed and is currently at 0, returns
if (speed == 0) speed = getGeneratedSpeed();
if (speed == 0) return;

// Used for GameTests to safely verify tooltip content on the server side
// Bypasses client-only formatting logic to prevent crashes in headless environments
// Note: Used Component.translatable directly to avoid issues with CreateLang in GameTests
if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) {
tooltip.add(Component.translatable("create.gui.goggles.rotation_direction"));
if (speed > 0) {
tooltip.add(Component.translatable("create.gui.goggles.rotation_direction.clockwise"));
} else {
tooltip.add(Component.translatable("create.gui.goggles.rotation_direction.counter_clockwise"));
}
return;
}

float apparentSpeed = speed;
BlockState state = getBlockState();
if (state.getBlock() instanceof IRotate rotatingBlock) {
Axis rotationAxis = rotatingBlock.getRotationAxis(state);
Vec3 axisVector = switch (rotationAxis) {
case X -> new Vec3(1, 0, 0);
case Y -> new Vec3(0, 1, 0);
case Z -> new Vec3(0, 0, 1);
};

Vec3 lookVector = Minecraft.getInstance().player.getLookAngle();
double dot = axisVector.dot(lookVector);

// Invert apparent direction if player is looking against the rotation axis
if (Math.abs(dot) > 0.001)
apparentSpeed = (float) (speed * Math.signum(dot));
}

CreateLang.translate("gui.goggles.rotation_direction")
.style(GRAY)
.forGoggles(tooltip);

CreateLang.translate(apparentSpeed > 0
? "gui.goggles.rotation_direction.clockwise"
: "gui.goggles.rotation_direction.counter_clockwise")
.style(apparentSpeed > 0 ? ChatFormatting.GREEN : ChatFormatting.BLUE)
.forGoggles(tooltip, 1);
}

protected void addStressImpactStats(List<Component> tooltip, float stressAtBase) {
CreateLang.translate("tooltip.stressImpact")
.style(GRAY)
Expand Down
Loading