Skip to content

Commit

Permalink
Improve GTFormattingCode (#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwer523 authored Jul 1, 2024
1 parent 8e18ffe commit a5346d5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Version: 1.3.1
- Rubber trees spawn chance config now works
- Singleblock machines can no longer run a recipe beyond its tier
- Fluid Hatch locking properly saves between world loads
- Color-changing tooltip now changes colors properly
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.client.EnvironmentalHazardClientHandler;
import com.gregtechceu.gtceu.client.TooltipHelper;
import com.gregtechceu.gtceu.client.TooltipsHandler;
import com.gregtechceu.gtceu.client.renderer.BlockHighLightRenderer;
import com.gregtechceu.gtceu.client.renderer.MultiblockInWorldPreviewRenderer;
import com.gregtechceu.gtceu.client.util.TooltipHelper;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gregtechceu.gtceu.client;
package com.gregtechceu.gtceu.client.util;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTValues;
Expand All @@ -15,7 +15,7 @@ public class TooltipHelper {

private static final List<GTFormattingCode> CODES = new ArrayList<>();

/* Array of TextFormatting codes that are used to create a rainbow effect */
/** Array of TextFormatting codes that are used to create a rainbow effect */
private static final ChatFormatting[] ALL_COLORS = new ChatFormatting[] {
RED, GOLD, YELLOW, GREEN, AQUA, DARK_AQUA, DARK_BLUE, BLUE, DARK_PURPLE, LIGHT_PURPLE
};
Expand Down
53 changes: 31 additions & 22 deletions src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.api.registry.registrate.MachineBuilder;
import com.gregtechceu.gtceu.api.registry.registrate.MultiblockMachineBuilder;
import com.gregtechceu.gtceu.client.TooltipHelper;
import com.gregtechceu.gtceu.client.renderer.machine.*;
import com.gregtechceu.gtceu.client.util.TooltipHelper;
import com.gregtechceu.gtceu.common.block.BoilerFireboxType;
import com.gregtechceu.gtceu.common.data.machines.GCyMMachines;
import com.gregtechceu.gtceu.common.data.machines.GTAEMachines;
Expand Down Expand Up @@ -554,32 +554,37 @@ public class GTMachines {
//////////////////////////////////////
// ********* Storage *********//
//////////////////////////////////////

public static final BiConsumer<ItemStack, List<Component>> CREATIVE_TOOLTIPS = (stack, components) -> components
.add(Component.translatable("gtceu.creative_tooltip.1")
.append(Component.translatable("gtceu.creative_tooltip.2")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent())))
.append(Component.translatable("gtceu.creative_tooltip.3")));

public static BiConsumer<ItemStack, List<Component>> createCreativeTooltips(boolean share) {
return (stack, list) -> {
CREATIVE_TOOLTIPS.accept(stack, list);
list.add(Component.translatable("gtceu.universal.%s".formatted(share ? "enabled" : "disabled")));
};
}

public static final MachineDefinition CREATIVE_ENERGY = REGISTRATE
.machine("creative_energy", CreativeEnergyContainerMachine::new)
.rotationState(RotationState.NONE)
.tooltips(Component.translatable("gtceu.creative_tooltip.1"),
Component.translatable("gtceu.creative_tooltip.2")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent())),
Component.translatable("gtceu.creative_tooltip.3"))
.tooltipBuilder(CREATIVE_TOOLTIPS)
.compassNodeSelf()
.register();
public static final MachineDefinition CREATIVE_FLUID = REGISTRATE.machine("creative_tank", CreativeTankMachine::new)
.rotationState(RotationState.ALL)
.tooltips(Component.translatable("gtceu.creative_tooltip.1"),
Component.translatable("gtceu.creative_tooltip.2")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent())),
Component.translatable("gtceu.creative_tooltip.3"))
.tooltipBuilder(CREATIVE_TOOLTIPS)
.renderer(() -> new QuantumTankRenderer(MAX, GTCEu.id("block/machine/creative_tank")))
.hasTESR(true)
.compassNodeSelf()
.register();
public static final MachineDefinition CREATIVE_ITEM = REGISTRATE
.machine("creative_chest", CreativeChestMachine::new)
.rotationState(RotationState.ALL)
.tooltips(Component.translatable("gtceu.creative_tooltip.1"),
Component.translatable("gtceu.creative_tooltip.2")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent())),
Component.translatable("gtceu.creative_tooltip.3"))
.tooltipBuilder(CREATIVE_TOOLTIPS)
.renderer(() -> new QuantumChestRenderer(MAX, GTCEu.id("block/machine/creative_chest")))
.hasTESR(true)
.compassNodeSelf()
Expand Down Expand Up @@ -1988,10 +1993,12 @@ public static BiConsumer<ItemStack, List<Component>> createTankTooltips(String n
.recipeType(GTRecipeTypes.DUMMY_RECIPES)
.appearanceBlock(HIGH_POWER_CASING)
.tooltips(Component.translatable("gtceu.machine.active_transformer.tooltip.0"),
Component.translatable("gtceu.machine.active_transformer.tooltip.1"),
Component.translatable("gtceu.machine.active_transformer.tooltip.2")
.append(Component.translatable("gtceu.machine.active_transformer.tooltip.3")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent()))))
Component.translatable("gtceu.machine.active_transformer.tooltip.1"))
.tooltipBuilder(
(stack,
components) -> components.add(Component.translatable("gtceu.machine.active_transformer.tooltip.2")
.append(Component.translatable("gtceu.machine.active_transformer.tooltip.3")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent())))))
.pattern((definition) -> FactoryBlockPattern.start()
.aisle("XXX", "XXX", "XXX")
.aisle("XXX", "XCX", "XXX")
Expand All @@ -2015,10 +2022,12 @@ public static BiConsumer<ItemStack, List<Component>> createTankTooltips(String n
PowerSubstationMachine.MAX_BATTERY_LAYERS),
Component.translatable("gtceu.machine.power_substation.tooltip.3"),
Component.translatable("gtceu.machine.power_substation.tooltip.4",
PowerSubstationMachine.PASSIVE_DRAIN_MAX_PER_STORAGE / 1000),
Component.translatable("gtceu.machine.power_substation.tooltip.5")
.append(Component.translatable("gtceu.machine.power_substation.tooltip.6")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent()))))
PowerSubstationMachine.PASSIVE_DRAIN_MAX_PER_STORAGE / 1000))
.tooltipBuilder(
(stack,
components) -> components.add(Component.translatable("gtceu.machine.power_substation.tooltip.5")
.append(Component.translatable("gtceu.machine.power_substation.tooltip.6")
.withStyle(style -> style.withColor(TooltipHelper.RAINBOW_SLOW.getCurrent())))))
.appearanceBlock(CASING_PALLADIUM_SUBSTATION)
.pattern(definition -> FactoryBlockPattern.start(RIGHT, BACK, UP)
.aisle("XXSXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX")
Expand Down Expand Up @@ -2314,7 +2323,7 @@ public static MultiblockMachineDefinition[] registerTieredMultis(String name,

private static MachineDefinition registerTankValve(
String name, String displayName, boolean isMetal,
BiConsumer<MachineBuilder, ResourceLocation> rendererSetup) {
BiConsumer<MachineBuilder<?>, ResourceLocation> rendererSetup) {
MachineBuilder<MachineDefinition> builder = REGISTRATE
.machine(name, holder -> new TankValvePartMachine(holder, isMetal))
.langValue(displayName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.gregtechceu.gtceu.api.pattern.FactoryBlockPattern;
import com.gregtechceu.gtceu.api.pattern.MultiblockShapeInfo;
import com.gregtechceu.gtceu.api.registry.registrate.MachineBuilder;
import com.gregtechceu.gtceu.client.TooltipHelper;
import com.gregtechceu.gtceu.client.renderer.machine.HPCAPartRenderer;
import com.gregtechceu.gtceu.client.renderer.machine.OverlayTieredActiveMachineRenderer;
import com.gregtechceu.gtceu.client.util.TooltipHelper;
import com.gregtechceu.gtceu.common.data.GTMachines;
import com.gregtechceu.gtceu.common.data.GTMaterials;
import com.gregtechceu.gtceu.common.data.GTRecipeTypes;
Expand All @@ -35,18 +35,21 @@

import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;

import static com.gregtechceu.gtceu.api.GTValues.*;
import static com.gregtechceu.gtceu.api.pattern.Predicates.*;
import static com.gregtechceu.gtceu.common.data.GTBlocks.*;
import static com.gregtechceu.gtceu.common.data.GTMachines.createCreativeTooltips;
import static com.gregtechceu.gtceu.common.registry.GTRegistration.REGISTRATE;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -345,19 +348,19 @@ public class GTResearchMachines {
.tier(MAX)
.rotationState(RotationState.ALL)
.abilities(PartAbility.DATA_ACCESS)
.tooltips(Component.translatable("gtceu.machine.data_access_hatch.tooltip.0"),
Component.translatable("gtceu.creative_tooltip.1")
.append(TooltipHelper.RAINBOW.toString())
.append(Component.translatable("gtceu.creative_tooltip.2"))
.append(Component.translatable("gtceu.creative_tooltip.3")),
Component.translatable("gtceu.universal.enabled"))
.tooltips(Component.translatable("gtceu.machine.data_access_hatch.tooltip.0"))
.tooltipBuilder(createCreativeTooltips(true))
.overlayTieredHullRenderer("data_access_hatch_creative")
.register();

//////////////////////////////////////
// *********** HPCA ***********//
//////////////////////////////////////

public static final BiConsumer<ItemStack, List<Component>> OVERHEAT_TOOLTIPS = (stack, components) -> components
.add(Component.translatable("gtceu.machine.hpca.component_type.damaged")
.withStyle(style -> style.withColor(TooltipHelper.BLINKING_ORANGE.getCurrent())));

public static final MachineDefinition HPCA_EMPTY_COMPONENT = registerHPCAPart(
"hpca_empty_component", "Empty HPCA Component",
HPCAEmptyPartMachine::new, "empty", null, null, false).register();
Expand All @@ -368,9 +371,8 @@ public class GTResearchMachines {
Component.translatable("gtceu.machine.hpca.component_general.upkeep_eut", GTValues.VA[GTValues.EV]),
Component.translatable("gtceu.machine.hpca.component_general.max_eut", GTValues.VA[GTValues.LuV]),
Component.translatable("gtceu.machine.hpca.component_type.computation_cwut", 4),
Component.translatable("gtceu.machine.hpca.component_type.computation_cooling", 2),
Component.literal(TooltipHelper.BLINKING_ORANGE.toString())
.append(Component.translatable("gtceu.machine.hpca.component_type.damaged")))
Component.translatable("gtceu.machine.hpca.component_type.computation_cooling", 2))
.tooltipBuilder(OVERHEAT_TOOLTIPS)
.register();
public static final MachineDefinition HPCA_ADVANCED_COMPUTATION_COMPONENT = registerHPCAPart(
"hpca_advanced_computation_component", "HPCA Advanced Computation Component",
Expand All @@ -379,9 +381,8 @@ public class GTResearchMachines {
Component.translatable("gtceu.machine.hpca.component_general.upkeep_eut", GTValues.VA[GTValues.IV]),
Component.translatable("gtceu.machine.hpca.component_general.max_eut", GTValues.VA[GTValues.ZPM]),
Component.translatable("gtceu.machine.hpca.component_type.computation_cwut", 16),
Component.translatable("gtceu.machine.hpca.component_type.computation_cooling", 4),
Component.literal(TooltipHelper.BLINKING_ORANGE.toString())
.append(Component.translatable("gtceu.machine.hpca.component_type.damaged")))
Component.translatable("gtceu.machine.hpca.component_type.computation_cooling", 4))
.tooltipBuilder(OVERHEAT_TOOLTIPS)
.register();
public static final MachineDefinition HPCA_HEAT_SINK_COMPONENT = registerHPCAPart(
"hpca_heat_sink_component", "HPCA Heat Sink Component",
Expand Down

0 comments on commit a5346d5

Please sign in to comment.