Fix various tool tip and lang issues.

This commit is contained in:
Waterpicker 2021-06-14 22:17:13 -05:00
parent 85cc5a6b24
commit e2d0d97328
9 changed files with 119 additions and 28 deletions

View file

@ -36,6 +36,7 @@ public final class DoorData implements AutoCloseable {
private final Optional<String> itemGroup;
private final UnbakedBlockSettings blockSettings;
private final RiftDataList riftDataList;
private final boolean hasToolTip;
private boolean closed = false;
public static DoorData fromJson(JsonObject json) {
@ -45,22 +46,28 @@ public final class DoorData implements AutoCloseable {
Optional<String> itemGroup = Optional.ofNullable(json.getAsJsonPrimitive("itemGroup")).map(JsonPrimitive::getAsString);
UnbakedBlockSettings blockSettings = UnbakedBlockSettings.fromJson(json.getAsJsonObject("blockSettings"));
RiftDataList riftDataList = RiftDataList.fromJson(json.getAsJsonArray("riftData"));
return new DoorData(id, itemSettings, itemGroup, blockSettings, riftDataList);
boolean hasToolTip = json.has("hasToolTip") && json.getAsJsonPrimitive("hasToolTip").getAsBoolean();
return new DoorData(id, itemSettings, itemGroup, blockSettings, riftDataList, hasToolTip);
} catch (RuntimeException e) {
throw new RuntimeException("Caught exception while deserializing " + json.toString(), e);
}
}
public DoorData(String id, UnbakedItemSettings itemSettings, UnbakedBlockSettings blockSettings, RiftDataList riftDataList) {
this(id, itemSettings, Optional.empty(), blockSettings, riftDataList);
this(id, itemSettings, Optional.empty(), blockSettings, riftDataList, false);
}
public DoorData(String id, UnbakedItemSettings itemSettings, Optional<String> itemGroup, UnbakedBlockSettings blockSettings, RiftDataList riftDataList) {
public DoorData(String id, UnbakedItemSettings itemSettings, UnbakedBlockSettings blockSettings, RiftDataList riftDataList, boolean hasToolTip) {
this(id, itemSettings, Optional.empty(), blockSettings, riftDataList, hasToolTip);
}
public DoorData(String id, UnbakedItemSettings itemSettings, Optional<String> itemGroup, UnbakedBlockSettings blockSettings, RiftDataList riftDataList, boolean hasToolTip) {
this.id = id;
this.itemSettings = itemSettings;
this.itemGroup = itemGroup;
this.blockSettings = blockSettings;
this.riftDataList = riftDataList;
this.hasToolTip = hasToolTip;
}
public JsonObject toJson(JsonObject json) {
@ -69,6 +76,7 @@ public final class DoorData implements AutoCloseable {
itemGroup.ifPresent(s -> json.add("itemGroup", new JsonPrimitive(s)));
json.add("blockSettings", this.blockSettings.toJson(new JsonObject()));
json.add("riftData", this.riftDataList.toJson());
json.addProperty("hasToolTip", this.hasToolTip);
return json;
}
@ -98,6 +106,10 @@ public final class DoorData implements AutoCloseable {
return riftDataList;
}
public boolean hasToolTip() {
return hasToolTip;
}
@Override
public void close() {
if (closed) {
@ -138,7 +150,7 @@ public final class DoorData implements AutoCloseable {
this.blockSettings.luminance.ifPresent(blockSettings::luminance);
Identifier id = new Identifier(this.id);
Block doorBlock = new DimensionalDoorBlock(blockSettings);
Item doorItem = new DimensionalDoorItem(doorBlock, itemSettings, createSetupFunction());
Item doorItem = new DimensionalDoorItem(doorBlock, itemSettings, createSetupFunction(), hasToolTip);
Registry.register(Registry.BLOCK, id, doorBlock);
Registry.register(Registry.ITEM, id, doorItem);
DOORS.add(doorBlock);

View file

@ -50,7 +50,8 @@ public class DoorDataReader {
"minecraft:iron_door",
OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PublicPocketTarget()), Optional.empty()).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
));
), true);
public static final DoorData DEFAULT_GOLD_DIMENSIONAL_DOOR = new DoorData(
"dimdoors:gold_dimensional_door",
new DoorData.UnbakedItemSettings(
@ -64,7 +65,7 @@ public class DoorDataReader {
"dimdoors:gold_door",
OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(DefaultDungeonDestinations.getDeeperDungeonDestination()), Optional.of(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES)).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
));
), true);
public static final DoorData DEFAULT_OAK_DIMENSIONAL_DOOR = new DoorData(
"dimdoors:oak_dimensional_door",
new DoorData.UnbakedItemSettings(
@ -78,7 +79,7 @@ public class DoorDataReader {
"minecraft:oak_door",
OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(DefaultDungeonDestinations.getShallowerDungeonDestination()), Optional.of(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES)).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
));
), true);
public static final DoorData DEFAULT_QUARTZ_DIMENSIONAL_DOOR = new DoorData(
"dimdoors:quartz_dimensional_door",
new DoorData.UnbakedItemSettings(
@ -95,8 +96,8 @@ public class DoorDataReader {
WorldMatchCondition condition = new WorldMatchCondition(ModDimensions.PERSONAL);
list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PrivatePocketExitTarget()), Optional.empty()).toJson(new JsonObject()), condition));
list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PrivatePocketTarget()), Optional.empty()).toJson(new JsonObject()), new InverseCondition(condition)));
})
));
})
), true);
public static final DoorData DEFAULT_UNSTABLE_DIMENSIONAL_DOOR = new DoorData(
"dimdoors:unstable_dimensional_door",
new DoorData.UnbakedItemSettings(
@ -110,7 +111,7 @@ public class DoorDataReader {
"minecraft:iron_door",
OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new UnstableTarget()), Optional.of(LinkProperties.builder().linksRemaining(1).groups(IntStream.of(0, 1).boxed().collect(Collectors.toSet())).build())).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
));
), true);
public static void read() {
Path doorDir = DimensionalDoorsInitializer.getConfigRoot().resolve("doors");

View file

@ -0,0 +1,19 @@
package org.dimdev.dimdoors.client;
import java.util.List;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
public class ToolTipHelper {
public static void processTranslation(List<Text> list, String key, Object... args) {
if(I18n.hasTranslation(key)) {
list.add(new TranslatableText(key, args));
} else {
for (int i = 0; I18n.hasTranslation(key + i); i++) {
list.add(new TranslatableText(key + i, args));
}
}
}
}

View file

@ -1,19 +1,29 @@
package org.dimdev.dimdoors.item;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.IntStream;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.BlockItem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.RiftProvider;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.client.ToolTipHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
@ -21,10 +31,24 @@ import net.minecraft.world.World;
public class DimensionalDoorItem extends BlockItem {
private final Consumer<? super EntranceRiftBlockEntity> setupFunction;
private boolean hasToolTip = false;
public DimensionalDoorItem(Block block, Item.Settings settings, Consumer<? super EntranceRiftBlockEntity> setupFunction) {
public DimensionalDoorItem(Block block, Settings settings, Consumer<? super EntranceRiftBlockEntity> setupFunction) {
this(block, settings, setupFunction, false);
}
public DimensionalDoorItem(Block block, Settings settings, Consumer<? super EntranceRiftBlockEntity> setupFunction, boolean hasToolTip) {
super(block, settings);
this.setupFunction = setupFunction;
this.hasToolTip = hasToolTip;
}
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
if(hasToolTip) {
ToolTipHelper.processTranslation(list, this.getTranslationKey() + ".info");
}
}
@Override

View file

@ -1,18 +1,24 @@
package org.dimdev.dimdoors.item;
import java.util.List;
import java.util.Objects;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.DimensionalPortalBlock;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.client.ToolTipHelper;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterials;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
@ -28,7 +34,12 @@ public class RiftBladeItem extends SwordItem {
public RiftBladeItem(Settings settings) {
super(ToolMaterials.IRON, 3, -2.4F, settings);
}
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
ToolTipHelper.processTranslation(list, this.getTranslationKey() + ".info");
}
@Override

View file

@ -7,6 +7,7 @@ import net.minecraft.util.hit.BlockHitResult;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.client.ToolTipHelper;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import net.minecraft.client.item.TooltipContext;
@ -36,7 +37,7 @@ public class RiftRemoverItem extends Item {
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
list.add(new TranslatableText(this.getTranslationKey() + ".info"));
ToolTipHelper.processTranslation(list, this.getTranslationKey() + ".info");
}
@Override

View file

@ -7,6 +7,7 @@ import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.client.ToolTipHelper;
import org.dimdev.dimdoors.rift.targets.RiftReference;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import org.dimdev.dimdoors.api.util.Location;
@ -138,9 +139,10 @@ public class RiftSignatureItem extends Item {
public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
RotatedLocation transform = getSource(itemStack);
if (transform != null) {
list.add(new TranslatableText(this.getTranslationKey() + ".bound.info", transform.getX(), transform.getY(), transform.getZ(), transform.getWorldId()));
list.add(new TranslatableText(this.getTranslationKey() + ".bound.info0", transform.getX(), transform.getY(), transform.getZ(), transform.getWorldId().getValue()));
list.add(new TranslatableText(this.getTranslationKey() + ".bound.info1", transform.getWorldId().getValue()));
} else {
list.add(new TranslatableText(this.getTranslationKey() + ".unbound.info"));
ToolTipHelper.processTranslation(list, this.getTranslationKey() + ".unbound.info");
}
}
}

View file

@ -2,9 +2,12 @@ package org.dimdev.dimdoors.item;
import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.client.ToolTipHelper;
import org.dimdev.dimdoors.rift.targets.RiftReference;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import org.dimdev.dimdoors.api.util.Location;
@ -117,13 +120,15 @@ public class StabilizedRiftSignatureItem extends Item { // TODO: common supercla
}
@Override
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
RotatedLocation transform = getTarget(itemStack);
if (transform != null) {
list.add(new TranslatableText(this.getTranslationKey() + ".bound.info", transform.getX(), transform.getY(), transform.getZ(), transform.getWorldId()));
list.add(new TranslatableText(this.getTranslationKey() + ".bound.info0", transform.getX(), transform.getY(), transform.getZ(), transform.getWorldId().getValue()));
list.add(new TranslatableText(this.getTranslationKey() + ".bound.info1", transform.getWorldId().getValue()));
} else {
list.add(new TranslatableText(this.getTranslationKey() + ".unbound.info"));
ToolTipHelper.processTranslation(list, this.getTranslationKey() + ".unbound.info");
}
}
}

View file

@ -88,17 +88,34 @@
"item.dimdoors.world_thread_chestplate": "Woven World Thread Chestplate",
"item.dimdoors.rift_key.bound.info": "Bound",
"item.dimdoors.rift_key.unbound.info": "Unbound",
"item.dimdoors.iron_dimensional_door.info": "Place on the block under a rift \\nto activate that rift or place \\nanywhere else to create a \\npocket dimension.",
"item.dimdoors.gold_dimensional_door.info": "Similar to a Dimensional Door \\nbut keeps a pocket dimension \\nloaded if placed on the inside.",
"item.dimdoors.quartz_dimensional_door.info": "Creates a pathway to your personal pocket.",
"item.dimdoors.rift_blade.info": "Opens temporary doors on rifts \\nand has a teleport attack.",
"item.dimdoors.rift_remover.info": "Use near exposed rift \\nto remove it and \\nany nearby rifts.",
"item.dimdoors.rift_signature.bound.info": "Leads to (%d, %d, %d) at dimension #%d",
"item.dimdoors.rift_signature.unbound.info": "First click stores a location; \\nsecond click creates a pair of \\nrifts linking the two locations.",
"item.dimdoors.stabilized_rift_signature.bound.info": "Leads to (%d, %d, %d) at dimension #%d",
"item.dimdoors.stabilized_rift_signature.unbound.info": "First click stores a location, \\nother clicks create rifts linking \\nthe first and last locations together.",
"item.dimdoors.rift_key.no_links": "There are no saved links.",
"block.dimdoors.iron_dimensional_door.info0": "Place on the block under a rift",
"block.dimdoors.iron_dimensional_door.info1": "to activate that rift or place",
"block.dimdoors.iron_dimensional_door.info2": "anywhere else to create a",
"block.dimdoors.iron_dimensional_door.info3": "pocket dimension.",
"block.dimdoors.gold_dimensional_door.info0": "Similar to a Dimensional Door",
"block.dimdoors.gold_dimensional_door.info1": "but keeps a pocket dimension",
"block.dimdoors.gold_dimensional_door.info2": "loaded if placed on the inside.",
"block.dimdoors.quartz_dimensional_door.info": "Creates a pathway to your personal pocket.",
"item.dimdoors.rift_blade.info0": "Opens temporary doors on rifts",
"item.dimdoors.rift_blade.info1": "and has a teleport attack.",
"item.dimdoors.rift_remover.info0": "Use near exposed rift",
"item.dimdoors.rift_remover.info1": "to remove it and",
"item.dimdoors.rift_remover.info2": "any nearby rifts.",
"item.dimdoors.rift_signature.bound.info1": "Leads to (%d, %d, %d)",
"item.dimdoors.rift_signature.bound.info0": "at dimension %d",
"item.dimdoors.rift_signature.unbound.info0": "First click stores a location;.",
"item.dimdoors.rift_signature.unbound.info1": "second click creates a pair of",
"item.dimdoors.rift_signature.unbound.info2": "rifts linking the two locations.",
"item.dimdoors.stabilized_rift_signature.bound.info0": "Leads to (%d, %d, %d)",
"item.dimdoors.stabilized_rift_signature.bound.info1": "at dimension %d",
"item.dimdoors.stabilized_rift_signature.unbound.info0": "First click stores a location,.",
"item.dimdoors.stabilized_rift_signature.unbound.info1": "other clicks create rifts linking",
"item.dimdoors.stabilized_rift_signature.unbound.info2": "the first and last locations together.",
"item.dimdoors.unstable_dimensional_door.info": "Caution: Leads to random destination",
"item.dimdoors.oak_dimensional_door.info": "Place on the block under a rift \\nto create a portal, or place anywhere \\nin a pocket dimension to exit.",
"block.dimdoors.oak_dimensional_door.info0": "Place on the block under a rift.",
"block.dimdoors.oak_dimensional_door.info1": "to create a portal, or place anywhere.",
"block.dimdoors.oak_dimensional_door.info2": "in a pocket dimension to exit.",
"item.dimdoors.creepy_record": "Music Disc",
"item.dimdoors.creepy_record.desc": "Creepy - The sound of Limbo",
"item.dimdoors.eternal_fluid_bucket": "Eternal Fluid Bucket",
@ -110,7 +127,6 @@
"item.dimdoors.mask_wand": "Mask Wand",
"item.dimdoors.mask_shard": "Mask Shard",
"dimdoors.virtualTarget.dimdoors.available_link": "Random",
"dimdoors.virtualTarget.dimdoors.escape": "Escape",
"dimdoors.virtualTarget.dimdoors.global": "Global",