Skip to content

Commit

Permalink
added method to utils to get translatable and literal text component
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Sep 16, 2023
1 parent a57b558 commit 15ed5b8
Show file tree
Hide file tree
Showing 45 changed files with 175 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import muramasa.antimatter.Ref;
import muramasa.antimatter.registration.IItemBlockProvider;
import muramasa.antimatter.util.Utils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
Expand All @@ -18,6 +18,6 @@ public AntimatterItemBlock(Block block) {
@NotNull
@Override
public Component getName(@NotNull ItemStack stack) {
return getBlock() instanceof IItemBlockProvider ? ((IItemBlockProvider) getBlock()).getDisplayName(stack) : new TranslatableComponent(stack.getDescriptionId());
return getBlock() instanceof IItemBlockProvider ? ((IItemBlockProvider) getBlock()).getDisplayName(stack) : Utils.translatable(stack.getDescriptionId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -360,7 +359,7 @@ public AbstractGuiEventPacket createGuiPacket(IGuiEvent event) {

@Override
public Component getDisplayName() {
return new TextComponent(this.type.getTypeName());
return Utils.literal(this.type.getTypeName());
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.machine.types.Machine;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -83,7 +83,7 @@ public InteractionResult onInteractServer(BlockState state, Level world, BlockPo
h.setOutputVoltage(h.getInputVoltage());
h.setInputVoltage(temp);
this.invalidateCap(IEnergyHandler.class);
player.sendMessage(new TextComponent((isDefaultMachineState() ? "Step Down, In: " : "Step Up, In") + h.getInputVoltage() + "V@" + h.getInputAmperage() + "Amp, Out: " + h.getOutputVoltage() + "V@" + h.getOutputAmperage() + "Amp"), player.getUUID());
player.sendMessage(Utils.literal((isDefaultMachineState() ? "Step Down, In: " : "Step Up, In") + h.getInputVoltage() + "V@" + h.getInputAmperage() + "Amp, Out: " + h.getOutputVoltage() + "V@" + h.getOutputAmperage() + "Amp"), player.getUUID());
});
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -160,9 +159,9 @@ public static void onItemTooltip(TooltipFlag flags, List<Component> tooltip) {
if (flags.isAdvanced() && Ref.SHOW_ITEM_TAGS) {
Collection<ResourceLocation> tags = Collections.emptyList(); //ItemTags.getAllTags().getMatchingTags(e.getItemStack().getItem());
if (!tags.isEmpty()) {
tooltip.add(new TextComponent("Tags:").withStyle(ChatFormatting.DARK_GRAY));
tooltip.add(Utils.literal("Tags:").withStyle(ChatFormatting.DARK_GRAY));
for (ResourceLocation loc : tags) {
tooltip.add(new TextComponent(loc.toString()).withStyle(ChatFormatting.DARK_GRAY));
tooltip.add(Utils.literal(loc.toString()).withStyle(ChatFormatting.DARK_GRAY));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package muramasa.antimatter.cover;

import earth.terrarium.botarium.common.fluid.utils.FluidHooks;
import muramasa.antimatter.blockentity.BlockEntityFakeBlock;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.data.AntimatterDefaultTools;
Expand All @@ -9,12 +10,10 @@
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.machine.event.IMachineEvent;
import muramasa.antimatter.machine.event.MachineEvent;
import muramasa.antimatter.blockentity.BlockEntityFakeBlock;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down Expand Up @@ -99,7 +98,7 @@ public boolean onInteract(Player player, InteractionHand hand, Direction side, @
if (type != null && type.getTag() == AntimatterDefaultTools.SCREWDRIVER.getTag()){
allowInput = !allowInput;
String suffix = allowInput ? "allow" : "no";
player.sendMessage(new TranslatableComponent("antimatter.tooltip.cover.output." + suffix + "_input"), player.getUUID());
player.sendMessage(Utils.translatable("antimatter.tooltip.cover.output." + suffix + "_input"), player.getUUID());
return true;
}
return super.onInteract(player, hand, side, type);
Expand Down
5 changes: 2 additions & 3 deletions common/src/main/java/muramasa/antimatter/cover/ICover.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package muramasa.antimatter.cover;

import muramasa.antimatter.Ref;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.capability.IGuiHandler;
import muramasa.antimatter.client.dynamic.IDynamicModelProvider;
Expand All @@ -12,15 +13,13 @@
import muramasa.antimatter.network.packets.AbstractGuiEventPacket;
import muramasa.antimatter.registration.ITextureProvider;
import muramasa.antimatter.texture.Texture;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -54,7 +53,7 @@ default boolean canPlace(){

@NotNull
default Component getDisplayName() {
return new TextComponent(Utils.underscoreToUpperCamel(this.getId()));
return Utils.literal(Utils.underscoreToUpperCamel(this.getId()));
}

default void onGuiEvent(IGuiEvent event, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import muramasa.antimatter.capability.IGuiHandler;
import muramasa.antimatter.util.Utils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.MenuProvider;

public interface ICoverGui extends ICover, MenuProvider, IGuiHandler {

default Component getDisplayName() {
return new TextComponent(Utils.underscoreToUpperCamel(this.getId()));
return Utils.literal(Utils.underscoreToUpperCamel(this.getId()));
}

default String getDomain() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import muramasa.antimatter.datagen.AntimatterDynamics;
import muramasa.antimatter.datagen.IAntimatterProvider;
import muramasa.antimatter.util.Utils;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementRewards;
import net.minecraft.advancements.FrameType;
import net.minecraft.data.DataProvider;
import net.minecraft.data.HashCache;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ItemLike;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -82,11 +82,11 @@ public String getName() {
}

public static Advancement.Builder buildRootAdvancement(ItemLike provider, ResourceLocation backgroundPath, String title, String desc, FrameType type, boolean toast, boolean announce, boolean hide) {
return Advancement.Builder.advancement().display(provider, new TranslatableComponent(title), new TranslatableComponent(desc), backgroundPath, type, toast, announce, hide).rewards(AdvancementRewards.Builder.experience(10));
return Advancement.Builder.advancement().display(provider, Utils.translatable(title), Utils.translatable(desc), backgroundPath, type, toast, announce, hide).rewards(AdvancementRewards.Builder.experience(10));
}

public static Advancement.Builder buildAdvancement(Advancement parent, ItemLike provider, String title, String desc, FrameType type, boolean toast, boolean announce, boolean hide) {
return Advancement.Builder.advancement().parent(parent).display(provider, new TranslatableComponent(title), new TranslatableComponent(desc), null, type, toast, announce, hide).rewards(AdvancementRewards.Builder.experience(10));
return Advancement.Builder.advancement().parent(parent).display(provider, Utils.translatable(title), Utils.translatable(desc), null, type, toast, announce, hide).rewards(AdvancementRewards.Builder.experience(10));
}

public static String getLoc(String domain, String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import muramasa.antimatter.gui.Widget;
import muramasa.antimatter.gui.event.GuiEvents;
import muramasa.antimatter.gui.event.IGuiEvent;
import muramasa.antimatter.util.Utils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
Expand All @@ -16,7 +17,6 @@
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundEvents;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -83,7 +83,7 @@ protected void clientClick() {
public void mouseOver(PoseStack stack, double mouseX, double mouseY, float partialTicks) {
super.mouseOver(stack, mouseX, mouseY, partialTicks);
if (getTooltipKey() != null){
renderTooltip(stack,new TranslatableComponent(getTooltipKey()), mouseX, mouseY);
renderTooltip(stack, Utils.translatable(getTooltipKey()), mouseX, mouseY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.blaze3d.vertex.PoseStack;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.common.fluid.utils.FluidHooks;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.client.RenderHelper;
import muramasa.antimatter.gui.GuiInstance;
import muramasa.antimatter.gui.IGuiElement;
Expand All @@ -13,15 +14,13 @@
import muramasa.antimatter.gui.event.SlotClickEvent;
import muramasa.antimatter.integration.jeirei.AntimatterJEIREIPlugin;
import muramasa.antimatter.network.packets.AbstractGuiEventPacket;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import tesseract.FluidPlatformUtils;
import tesseract.TesseractGraphWrappers;

Expand Down Expand Up @@ -90,13 +89,13 @@ public void mouseOver(PoseStack stack, double mouseX, double mouseY, float parti
str.add(FluidPlatformUtils.getFluidDisplayName(this.stack));
long mb = (this.stack.getFluidAmount() / TesseractGraphWrappers.dropletMultiplier);
if (AntimatterPlatformUtils.isFabric()){
str.add(new TranslatableComponent("antimatter.tooltip.fluid.amount", new TextComponent(mb + " " + intToSuperScript(this.stack.getFluidAmount() % 81L) + "/₈₁ L")).withStyle(ChatFormatting.BLUE));
str.add(Utils.translatable("antimatter.tooltip.fluid.amount", Utils.literal(mb + " " + intToSuperScript(this.stack.getFluidAmount() % 81L) + "/₈₁ L")).withStyle(ChatFormatting.BLUE));
} else {
str.add(new TranslatableComponent("antimatter.tooltip.fluid.amount", mb + " L").withStyle(ChatFormatting.BLUE));
str.add(Utils.translatable("antimatter.tooltip.fluid.amount", mb + " L").withStyle(ChatFormatting.BLUE));
}
str.add(new TranslatableComponent("antimatter.tooltip.fluid.temp", FluidPlatformUtils.getFluidTemperature(this.stack.getFluid())).withStyle(ChatFormatting.RED));
str.add(Utils.translatable("antimatter.tooltip.fluid.temp", FluidPlatformUtils.getFluidTemperature(this.stack.getFluid())).withStyle(ChatFormatting.RED));
String liquid = !FluidPlatformUtils.isFluidGaseous(this.stack.getFluid()) ? "liquid" : "gas";
str.add(new TranslatableComponent("antimatter.tooltip.fluid." + liquid).withStyle(ChatFormatting.GREEN));
str.add(Utils.translatable("antimatter.tooltip.fluid." + liquid).withStyle(ChatFormatting.GREEN));
AntimatterJEIREIPlugin.addModDescriptor(str, this.stack);
drawHoverText(str, (int) mouseX, (int) mouseY, Minecraft.getInstance().font, stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import muramasa.antimatter.machine.MachineFlag;
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.Utils;
import muramasa.antimatter.util.int2;
import muramasa.antimatter.util.int4;
import net.minecraft.network.chat.TextComponent;

public class MachineStateWidget extends Widget {
/* Location in most machine textures. */
Expand Down Expand Up @@ -57,7 +57,7 @@ public void mouseOver(PoseStack stack, double mouseX, double mouseY, float parti
super.mouseOver(stack, mouseX, mouseY, partialTicks);
MachineState machineState = ((BlockEntityMachine<?>) gui.handler).getMachineState();
if (isRecipe) {
renderTooltip(stack, new TextComponent(machineState.getDisplayName()), mouseX, mouseY);
renderTooltip(stack, Utils.literal(machineState.getDisplayName()), mouseX, mouseY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import muramasa.antimatter.gui.*;
import muramasa.antimatter.gui.container.ContainerMachine;
import muramasa.antimatter.integration.jeirei.AntimatterJEIREIPlugin;
import muramasa.antimatter.util.Utils;
import muramasa.antimatter.util.int4;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;

import static muramasa.antimatter.gui.ICanSyncData.SyncDirection.SERVER_TO_CLIENT;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void render(PoseStack matrixStack, double mouseX, double mouseY, float pa
public void mouseOver(PoseStack stack, double mouseX, double mouseY, float partialTicks) {
super.mouseOver(stack, mouseX, mouseY, partialTicks);
if (isInside(mouseX, mouseY)) {
renderTooltip(stack, new TranslatableComponent("antimatter.gui.show_recipes"), mouseX, mouseY);
renderTooltip(stack, Utils.translatable("antimatter.gui.show_recipes"), mouseX, mouseY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import muramasa.antimatter.gui.GuiInstance;
import muramasa.antimatter.gui.IGuiElement;
import muramasa.antimatter.gui.Widget;
import net.minecraft.network.chat.TextComponent;
import muramasa.antimatter.util.Utils;

import java.util.function.Function;

Expand All @@ -25,6 +25,6 @@ public static WidgetSupplier build(String text, int color) {

@Override
public void render(PoseStack matrixStack, double mouseX, double mouseY, float partialTicks) {
this.drawText(matrixStack, new TextComponent(getter.apply(this)), realX(), realY(), color);
this.drawText(matrixStack, Utils.literal(getter.apply(this)), realX(), realY(), color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import muramasa.antimatter.recipe.map.RecipeMap;
import muramasa.antimatter.recipe.material.MaterialRecipe;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -197,7 +197,7 @@ public static <T> void addModDescriptor(List<Component> tooltip, T t) {
Object o = t;
if (t instanceof FluidHolder holder) o = getFluidObject(holder);
String text = helpers.getModIdHelper().getFormattedModNameForModId(getRuntime().getIngredientManager().getIngredientHelper(o).getDisplayModId(o));
tooltip.add(new TextComponent(text));
tooltip.add(Utils.literal(text));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import mezz.jei.api.registration.IRecipeRegistration;
import muramasa.antimatter.Data;
import muramasa.antimatter.Ref;
import muramasa.antimatter.util.Utils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -69,7 +69,7 @@ public Class<? extends MultiMachineInfoPage> getRecipeClass() {
@NotNull
@Override
public Component getTitle() {
return new TextComponent( "Multi Machines Title");
return Utils.literal( "Multi Machines Title");
}

@NotNull
Expand Down
Loading

0 comments on commit 15ed5b8

Please sign in to comment.