From aa69cbbeee61f08bfc591f3388c1fde40256c5fa Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Mon, 16 Jan 2023 20:08:26 -0800 Subject: [PATCH] AllSections are one - Remove AllSections - Refactor ItemDescription and parts of TooltipHelper - Remove deprecated methods - Rename CreateRegistry to AttachedRegistry - Rename creative tab classes to match vanilla names --- .../java/com/simibubi/create/AllBlocks.java | 30 +- .../create/AllInteractionBehaviours.java | 10 +- .../java/com/simibubi/create/AllItems.java | 31 +- .../create/AllMovementBehaviours.java | 10 +- .../java/com/simibubi/create/AllTags.java | 26 -- src/main/java/com/simibubi/create/Create.java | 12 +- .../simibubi/create/content/AllSections.java | 63 --- .../create/content/CreateItemGroup.java | 26 -- .../content/contraptions/base/IRotate.java | 6 +- .../contraptions/base/KineticBlock.java | 3 - .../AbstractContraptionEntity.java | 3 +- .../mounted/MinecartContraptionItem.java | 6 +- .../fluids/tank/BoilerHeaters.java | 10 +- .../itemAssembly/SequencedAssemblyRecipe.java | 25 +- .../relays/gauge/StressGaugeTileEntity.java | 4 +- .../weapons/PotatoProjectileRenderMode.java | 2 + .../curiosities/zapper/ZapperItem.java | 8 +- .../block/display/AllDisplayBehaviours.java | 21 +- .../item/filter/AbstractFilterScreen.java | 2 +- .../logistics/item/filter/FilterItem.java | 5 +- .../content/palettes/AllPaletteBlocks.java | 5 +- .../palettes/PalettesCreativeModeTab.java | 21 + .../content/palettes/PalettesItemGroup.java | 30 -- .../block/SchematicannonScreen.java | 2 +- .../simibubi/create/events/ClientEvents.java | 46 +- .../foundation/block/BlockStressValues.java | 10 + .../config/ContraptionMovementSetting.java | 4 +- .../foundation/data/CreateRegistrate.java | 68 --- .../data/recipe/StandardRecipeGen.java | 19 +- .../foundation/item/BaseCreativeModeTab.java | 16 + .../item/CreateCreativeModeTab.java | 48 +++ .../foundation/item/CreateItemGroupBase.java | 84 ---- .../foundation/item/ItemDescription.java | 392 +++++++----------- .../foundation/item/ItemTooltipHandler.java | 206 +++++++++ .../create/foundation/item/TooltipHelper.java | 133 +----- .../mixin/accessor/NbtAccounterAccessor.java | 4 +- .../ponder/PonderTooltipHandler.java | 12 +- ...ateRegistry.java => AttachedRegistry.java} | 18 +- .../foundation/utility/ContraptionData.java | 1 - 39 files changed, 549 insertions(+), 873 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/content/AllSections.java delete mode 100644 src/main/java/com/simibubi/create/content/CreateItemGroup.java create mode 100644 src/main/java/com/simibubi/create/content/palettes/PalettesCreativeModeTab.java delete mode 100644 src/main/java/com/simibubi/create/content/palettes/PalettesItemGroup.java create mode 100644 src/main/java/com/simibubi/create/foundation/item/BaseCreativeModeTab.java create mode 100644 src/main/java/com/simibubi/create/foundation/item/CreateCreativeModeTab.java delete mode 100644 src/main/java/com/simibubi/create/foundation/item/CreateItemGroupBase.java create mode 100644 src/main/java/com/simibubi/create/foundation/item/ItemTooltipHandler.java rename src/main/java/com/simibubi/create/foundation/utility/{CreateRegistry.java => AttachedRegistry.java} (82%) diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index e6603a698..62b12ef9c 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -3,7 +3,6 @@ package com.simibubi.create; import static com.simibubi.create.AllInteractionBehaviours.interactionBehaviour; import static com.simibubi.create.AllMovementBehaviours.movementBehaviour; import static com.simibubi.create.Create.REGISTRATE; -import static com.simibubi.create.content.AllSections.SCHEMATICS; import static com.simibubi.create.content.logistics.block.display.AllDisplayBehaviours.assignDataBehaviour; import static com.simibubi.create.foundation.data.BlockStateGen.axisBlock; import static com.simibubi.create.foundation.data.BlockStateGen.simpleCubeAll; @@ -16,7 +15,6 @@ import static com.simibubi.create.foundation.data.TagGen.tagBlockAndItem; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.AllTags.AllItemTags; -import com.simibubi.create.content.AllSections; import com.simibubi.create.content.contraptions.base.CasingBlock; import com.simibubi.create.content.contraptions.components.AssemblyOperatorBlockItem; import com.simibubi.create.content.contraptions.components.actors.BellMovementBehaviour; @@ -229,7 +227,7 @@ import com.simibubi.create.foundation.data.BuilderTransformers; import com.simibubi.create.foundation.data.CreateRegistrate; import com.simibubi.create.foundation.data.ModelGen; import com.simibubi.create.foundation.data.SharedProperties; -import com.simibubi.create.foundation.item.TooltipHelper; +import com.simibubi.create.foundation.item.ItemTooltipHandler; import com.simibubi.create.foundation.item.UncontainableBlockItem; import com.simibubi.create.foundation.utility.ColorHandlers; import com.simibubi.create.foundation.utility.Couple; @@ -282,10 +280,6 @@ public class AllBlocks { // Schematics - static { - REGISTRATE.startSection(SCHEMATICS); - } - public static final BlockEntry SCHEMATICANNON = REGISTRATE.block("schematicannon", SchematicannonBlock::new) .initialProperties(() -> Blocks.DISPENSER) @@ -319,10 +313,6 @@ public class AllBlocks { // Kinetics - static { - REGISTRATE.startSection(AllSections.KINETICS); - } - public static final BlockEntry SHAFT = REGISTRATE.block("shaft", ShaftBlock::new) .initialProperties(SharedProperties::stone) .properties(p -> p.color(MaterialColor.METAL)) @@ -572,7 +562,7 @@ public class AllBlocks { .transform(axeOrPickaxe()) .transform(BuilderTransformers.cuckooClock()) .lang("Cuckoo Clock") - .onRegisterAfter(Registry.ITEM_REGISTRY, c -> TooltipHelper.referTo(c, CUCKOO_CLOCK)) + .onRegisterAfter(Registry.ITEM_REGISTRY, c -> ItemTooltipHandler.referTo(c, CUCKOO_CLOCK)) .register(); public static final BlockEntry MILLSTONE = REGISTRATE.block("millstone", MillstoneBlock::new) @@ -1339,7 +1329,7 @@ public class AllBlocks { .unlockedBy("has_seat", RegistrateRecipeProvider.has(AllItemTags.SEATS.tag)) .save(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_seat")); }) - .onRegisterAfter(Registry.ITEM_REGISTRY, v -> TooltipHelper.referTo(v, "block.create.brown_seat")) + .onRegisterAfter(Registry.ITEM_REGISTRY, v -> ItemTooltipHandler.referTo(v, "block.create.brown_seat")) .tag(AllBlockTags.SEATS.tag) .item() .tag(AllItemTags.SEATS.tag) @@ -1474,10 +1464,6 @@ public class AllBlocks { // Logistics - static { - REGISTRATE.startSection(AllSections.LOGISTICS); - } - public static final BlockEntry MECHANICAL_ARM = REGISTRATE.block("mechanical_arm", ArmBlock::new) .initialProperties(SharedProperties::softMetal) .properties(p -> p.color(MaterialColor.TERRACOTTA_YELLOW)) @@ -1890,10 +1876,6 @@ public class AllBlocks { // Curiosities - static { - REGISTRATE.startSection(AllSections.CURIOSITIES); - } - public static final BlockEntry COPPER_BACKTANK = REGISTRATE.block("copper_backtank", CopperBacktankBlock::new) .initialProperties(SharedProperties::copperMetal) @@ -1955,7 +1937,7 @@ public class AllBlocks { .withExistingParent(colourName + "_toolbox", p.modLoc("block/toolbox/block")) .texture("0", p.modLoc("block/toolbox/" + colourName))); }) - .onRegisterAfter(Registry.ITEM_REGISTRY, v -> TooltipHelper.referTo(v, "block.create.toolbox")) + .onRegisterAfter(Registry.ITEM_REGISTRY, v -> ItemTooltipHandler.referTo(v, "block.create.toolbox")) .tag(AllBlockTags.TOOLBOXES.tag) .item(UncontainableBlockItem::new) .model((c, p) -> p.withExistingParent(colourName + "_toolbox", p.modLoc("block/toolbox/item")) @@ -1967,10 +1949,6 @@ public class AllBlocks { // Materials - static { - REGISTRATE.startSection(AllSections.PALETTES); - } - public static final BlockEntry ZINC_ORE = REGISTRATE.block("zinc_ore", Block::new) .initialProperties(() -> Blocks.GOLD_ORE) .properties(p -> p.color(MaterialColor.METAL)) diff --git a/src/main/java/com/simibubi/create/AllInteractionBehaviours.java b/src/main/java/com/simibubi/create/AllInteractionBehaviours.java index 0ce0c7465..20c9d58e6 100644 --- a/src/main/java/com/simibubi/create/AllInteractionBehaviours.java +++ b/src/main/java/com/simibubi/create/AllInteractionBehaviours.java @@ -9,7 +9,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.content.contraptions.components.structureMovement.interaction.DoorMovingInteraction; import com.simibubi.create.content.contraptions.components.structureMovement.interaction.LeverMovingInteraction; import com.simibubi.create.content.contraptions.components.structureMovement.interaction.TrapdoorMovingInteraction; -import com.simibubi.create.foundation.utility.CreateRegistry; +import com.simibubi.create.foundation.utility.AttachedRegistry; import com.tterrag.registrate.util.nullness.NonNullConsumer; import net.minecraft.resources.ResourceLocation; @@ -18,10 +18,9 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.IRegistryDelegate; public class AllInteractionBehaviours { - private static final CreateRegistry BLOCK_BEHAVIOURS = new CreateRegistry<>(ForgeRegistries.BLOCKS); + private static final AttachedRegistry BLOCK_BEHAVIOURS = new AttachedRegistry<>(ForgeRegistries.BLOCKS); private static final List GLOBAL_BEHAVIOURS = new ArrayList<>(); public static void registerBehaviour(ResourceLocation block, MovingInteractionBehaviour provider) { @@ -32,11 +31,6 @@ public class AllInteractionBehaviours { BLOCK_BEHAVIOURS.register(block, provider); } - @Deprecated(forRemoval = true) - public static void registerBehaviour(IRegistryDelegate block, MovingInteractionBehaviour provider) { - registerBehaviour(block.name(), provider); - } - public static void registerBehaviourProvider(BehaviourProvider provider) { GLOBAL_BEHAVIOURS.add(provider); } diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 63b6e3b3a..1e54fb606 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -5,11 +5,6 @@ import static com.simibubi.create.AllTags.AllItemTags.CREATE_INGOTS; import static com.simibubi.create.AllTags.AllItemTags.CRUSHED_ORES; import static com.simibubi.create.AllTags.AllItemTags.PLATES; import static com.simibubi.create.Create.REGISTRATE; -import static com.simibubi.create.content.AllSections.CURIOSITIES; -import static com.simibubi.create.content.AllSections.KINETICS; -import static com.simibubi.create.content.AllSections.LOGISTICS; -import static com.simibubi.create.content.AllSections.MATERIALS; -import static com.simibubi.create.content.AllSections.SCHEMATICS; import static com.simibubi.create.foundation.data.recipe.CompatMetals.ALUMINUM; import static com.simibubi.create.foundation.data.recipe.CompatMetals.LEAD; import static com.simibubi.create.foundation.data.recipe.CompatMetals.NICKEL; @@ -59,8 +54,8 @@ import com.simibubi.create.foundation.data.AssetLookup; import com.simibubi.create.foundation.data.CreateRegistrate; import com.simibubi.create.foundation.data.recipe.CompatMetals; import com.simibubi.create.foundation.item.HiddenIngredientItem; +import com.simibubi.create.foundation.item.ItemTooltipHandler; import com.simibubi.create.foundation.item.TagDependentIngredientItem; -import com.simibubi.create.foundation.item.TooltipHelper; import com.tterrag.registrate.util.entry.ItemEntry; import net.minecraft.tags.ItemTags; @@ -76,11 +71,7 @@ public class AllItems { REGISTRATE.creativeModeTab(() -> Create.BASE_CREATIVE_TAB); } - // Schematics - - static { - REGISTRATE.startSection(MATERIALS); - } + // Materials public static final ItemEntry WHEAT_FLOUR = taggedIngredient("wheat_flour", forgeItemTag("flour/wheat"), forgeItemTag("flour")), @@ -201,10 +192,6 @@ public class AllItems { // Kinetics - static { - REGISTRATE.startSection(KINETICS); - } - public static final ItemEntry BELT_CONNECTOR = REGISTRATE.item("belt_connector", BeltConnectorItem::new) .lang("Mechanical Belt") @@ -265,7 +252,7 @@ public class AllItems { public static final ItemEntry RED_SAND_PAPER = REGISTRATE.item("red_sand_paper", SandPaperItem::new) .tag(AllTags.AllItemTags.SANDPAPER.tag) - .onRegister(s -> TooltipHelper.referTo(s, SAND_PAPER)) + .onRegister(s -> ItemTooltipHandler.referTo(s, SAND_PAPER)) .register(); public static final ItemEntry WRENCH = REGISTRATE.item("wrench", WrenchItem::new) @@ -288,10 +275,6 @@ public class AllItems { // Curiosities - static { - REGISTRATE.startSection(CURIOSITIES); - } - public static final ItemEntry LINKED_CONTROLLER = REGISTRATE.item("linked_controller", LinkedControllerItem::new) .properties(p -> p.stacksTo(1)) @@ -328,10 +311,6 @@ public class AllItems { // Logistics - static { - REGISTRATE.startSection(LOGISTICS); - } - public static final ItemEntry FILTER = REGISTRATE.item("filter", FilterItem::regular) .model(AssetLookup.existingItemModel()) .register(); @@ -347,10 +326,6 @@ public class AllItems { // Schematics - static { - REGISTRATE.startSection(SCHEMATICS); - } - public static final ItemEntry EMPTY_SCHEMATIC = REGISTRATE.item("empty_schematic", Item::new) .properties(p -> p.stacksTo(1)) .register(); diff --git a/src/main/java/com/simibubi/create/AllMovementBehaviours.java b/src/main/java/com/simibubi/create/AllMovementBehaviours.java index 843ece1f7..f589a705b 100644 --- a/src/main/java/com/simibubi/create/AllMovementBehaviours.java +++ b/src/main/java/com/simibubi/create/AllMovementBehaviours.java @@ -10,7 +10,7 @@ import com.simibubi.create.content.contraptions.components.actors.CampfireMoveme import com.simibubi.create.content.contraptions.components.actors.dispenser.DispenserMovementBehaviour; import com.simibubi.create.content.contraptions.components.actors.dispenser.DropperMovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; -import com.simibubi.create.foundation.utility.CreateRegistry; +import com.simibubi.create.foundation.utility.AttachedRegistry; import com.tterrag.registrate.util.nullness.NonNullConsumer; import net.minecraft.resources.ResourceLocation; @@ -18,10 +18,9 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.IRegistryDelegate; public class AllMovementBehaviours { - private static final CreateRegistry BLOCK_BEHAVIOURS = new CreateRegistry<>(ForgeRegistries.BLOCKS); + private static final AttachedRegistry BLOCK_BEHAVIOURS = new AttachedRegistry<>(ForgeRegistries.BLOCKS); private static final List GLOBAL_BEHAVIOURS = new ArrayList<>(); public static void registerBehaviour(ResourceLocation block, MovementBehaviour behaviour) { @@ -32,11 +31,6 @@ public class AllMovementBehaviours { BLOCK_BEHAVIOURS.register(block, behaviour); } - @Deprecated(forRemoval = true) - public static void registerBehaviour(IRegistryDelegate block, MovementBehaviour behaviour) { - registerBehaviour(block.name(), behaviour); - } - public static void registerBehaviourProvider(BehaviourProvider provider) { GLOBAL_BEHAVIOURS.add(provider); } diff --git a/src/main/java/com/simibubi/create/AllTags.java b/src/main/java/com/simibubi/create/AllTags.java index 725836177..81202ee51 100644 --- a/src/main/java/com/simibubi/create/AllTags.java +++ b/src/main/java/com/simibubi/create/AllTags.java @@ -7,18 +7,13 @@ import static com.simibubi.create.AllTags.NameSpace.TIC; import java.util.Collections; -import com.simibubi.create.foundation.data.TagGen; import com.simibubi.create.foundation.utility.Lang; -import com.tterrag.registrate.builders.BlockBuilder; -import com.tterrag.registrate.builders.ItemBuilder; -import com.tterrag.registrate.util.nullness.NonNullFunction; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.FluidTags; import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; @@ -52,27 +47,6 @@ public class AllTags { return forgeTag(ForgeRegistries.FLUIDS, path); } - @Deprecated(forRemoval = true) - public static NonNullFunction, BlockBuilder> axeOrPickaxe() { - return TagGen.axeOrPickaxe(); - } - - @Deprecated(forRemoval = true) - public static NonNullFunction, BlockBuilder> axeOnly() { - return TagGen.axeOnly(); - } - - @Deprecated(forRemoval = true) - public static NonNullFunction, BlockBuilder> pickaxeOnly() { - return TagGen.pickaxeOnly(); - } - - @Deprecated(forRemoval = true) - public static NonNullFunction, ItemBuilder>> tagBlockAndItem( - String... path) { - return TagGen.tagBlockAndItem(path); - } - public enum NameSpace { MOD(Create.ID, false, true), FORGE("forge"), diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index a5ee44809..10d12e4df 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -10,7 +10,6 @@ import com.mojang.logging.LogUtils; import com.simibubi.create.api.behaviour.BlockSpoutingBehaviour; import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.curios.Curios; -import com.simibubi.create.content.CreateItemGroup; import com.simibubi.create.content.contraptions.TorquePropagator; import com.simibubi.create.content.contraptions.fluids.tank.BoilerHeaters; import com.simibubi.create.content.curiosities.deco.SlidingDoorBlock; @@ -20,7 +19,7 @@ import com.simibubi.create.content.logistics.block.display.AllDisplayBehaviours; import com.simibubi.create.content.logistics.block.mechanicalArm.AllArmInteractionPointTypes; import com.simibubi.create.content.logistics.trains.GlobalRailwayManager; import com.simibubi.create.content.palettes.AllPaletteBlocks; -import com.simibubi.create.content.palettes.PalettesItemGroup; +import com.simibubi.create.content.palettes.PalettesCreativeModeTab; import com.simibubi.create.content.schematics.ServerSchematicLoader; import com.simibubi.create.content.schematics.filtering.SchematicInstances; import com.simibubi.create.foundation.advancement.AllAdvancements; @@ -37,8 +36,9 @@ import com.simibubi.create.foundation.data.recipe.MechanicalCraftingRecipeGen; import com.simibubi.create.foundation.data.recipe.ProcessingRecipeGen; import com.simibubi.create.foundation.data.recipe.SequencedAssemblyRecipeGen; import com.simibubi.create.foundation.data.recipe.StandardRecipeGen; +import com.simibubi.create.foundation.item.BaseCreativeModeTab; import com.simibubi.create.foundation.networking.AllPackets; -import com.simibubi.create.foundation.utility.CreateRegistry; +import com.simibubi.create.foundation.utility.AttachedRegistry; import com.simibubi.create.foundation.worldgen.AllFeatures; import com.simibubi.create.foundation.worldgen.AllOreFeatureConfigEntries; import com.simibubi.create.foundation.worldgen.AllPlacementModifiers; @@ -81,8 +81,8 @@ public class Create { public static final CreateRegistrate REGISTRATE = CreateRegistrate.create(ID); - public static final CreativeModeTab BASE_CREATIVE_TAB = new CreateItemGroup(); - public static final CreativeModeTab PALETTES_CREATIVE_TAB = new PalettesItemGroup(); + public static final CreativeModeTab BASE_CREATIVE_TAB = new BaseCreativeModeTab(); + public static final CreativeModeTab PALETTES_CREATIVE_TAB = new PalettesCreativeModeTab(); public static final ServerSchematicLoader SCHEMATIC_RECEIVER = new ServerSchematicLoader(); public static final RedstoneLinkNetworkHandler REDSTONE_LINK_NETWORK_HANDLER = new RedstoneLinkNetworkHandler(); @@ -146,7 +146,7 @@ public class Create { } public static void init(final FMLCommonSetupEvent event) { - CreateRegistry.unwrapAll(); + AttachedRegistry.unwrapAll(); AllPackets.registerPackets(); SchematicInstances.register(); BuiltinPotatoProjectileTypes.register(); diff --git a/src/main/java/com/simibubi/create/content/AllSections.java b/src/main/java/com/simibubi/create/content/AllSections.java deleted file mode 100644 index 628b98b3e..000000000 --- a/src/main/java/com/simibubi/create/content/AllSections.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.simibubi.create.content; - -import com.simibubi.create.Create; -import com.simibubi.create.foundation.item.ItemDescription.Palette; - -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; - -public enum AllSections { - - /** Create's kinetic mechanisms */ - KINETICS(Palette.Red), - - /** Item transport and other Utility */ - LOGISTICS(Palette.Yellow), - - /** Tools for structure movement and replication */ - SCHEMATICS(Palette.Blue), - - /** Decorative blocks */ - PALETTES(Palette.Green), - - /** Helpful gadgets and other shenanigans */ - CURIOSITIES(Palette.Purple), - - /** Base materials, ingredients and tools */ - MATERIALS(Palette.Green), - - /** Fallback section */ - UNASSIGNED(Palette.Gray) - - ; - - private final Palette tooltipPalette; - - private AllSections(Palette tooltipPalette) { - this.tooltipPalette = tooltipPalette; - } - - public Palette getTooltipPalette() { - return tooltipPalette; - } - - public static AllSections of(ItemStack stack) { - Item item = stack.getItem(); - if (item instanceof BlockItem) - return ofBlock(((BlockItem) item).getBlock()); - return ofItem(item); - } - - static AllSections ofItem(Item item) { - return Create.REGISTRATE - .getSection(item); - } - - static AllSections ofBlock(Block block) { - return Create.REGISTRATE - .getSection(block); - } - -} diff --git a/src/main/java/com/simibubi/create/content/CreateItemGroup.java b/src/main/java/com/simibubi/create/content/CreateItemGroup.java deleted file mode 100644 index ed03bc689..000000000 --- a/src/main/java/com/simibubi/create/content/CreateItemGroup.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.simibubi.create.content; - -import java.util.EnumSet; - -import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.item.CreateItemGroupBase; - -import net.minecraft.world.item.ItemStack; - -public class CreateItemGroup extends CreateItemGroupBase { - - public CreateItemGroup() { - super("base"); - } - - @Override - protected EnumSet getSections() { - return EnumSet.complementOf(EnumSet.of(AllSections.PALETTES)); - } - - @Override - public ItemStack makeIcon() { - return AllBlocks.COGWHEEL.asStack(); - } - -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/IRotate.java b/src/main/java/com/simibubi/create/content/contraptions/base/IRotate.java index 089d86101..42830264a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/IRotate.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/IRotate.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.content.contraptions.wrench.IWrenchable; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.item.ItemDescription; +import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.LangBuilder; @@ -73,7 +73,7 @@ public interface IRotate extends IWrenchable { public static LangBuilder getFormattedSpeedText(float speed, boolean overstressed) { SpeedLevel speedLevel = of(speed); - LangBuilder builder = Lang.text(ItemDescription.makeProgressBar(3, speedLevel.ordinal())); + LangBuilder builder = Lang.text(TooltipHelper.makeProgressBar(3, speedLevel.ordinal())); builder.translate("tooltip.speedRequirement." + Lang.asId(speedLevel.name())) .space() @@ -133,7 +133,7 @@ public interface IRotate extends IWrenchable { public static LangBuilder getFormattedStressText(double stressPercent) { StressImpact stressLevel = of(stressPercent); - return Lang.text(ItemDescription.makeProgressBar(3, Math.min(stressLevel.ordinal() + 1, 3))) + return Lang.text(TooltipHelper.makeProgressBar(3, Math.min(stressLevel.ordinal() + 1, 3))) .translate("tooltip.stressImpact." + Lang.asId(stressLevel.name())) .text(String.format(" (%s%%) ", (int) (stressPercent * 100))) .style(stressLevel.getRelativeColor()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java index fcecf28d0..80ee71e4d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.foundation.advancement.AdvancementBehaviour; import com.simibubi.create.foundation.block.ITE; -import com.simibubi.create.foundation.item.ItemDescription.Palette; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -17,8 +16,6 @@ import net.minecraft.world.level.block.state.BlockState; public abstract class KineticBlock extends Block implements IRotate { - protected static final Palette color = Palette.Red; - public KineticBlock(Properties properties) { super(properties); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java index 764f9b643..23149f719 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java @@ -10,8 +10,6 @@ import java.util.UUID; import javax.annotation.Nullable; -import com.simibubi.create.foundation.utility.ContraptionData; - import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.tuple.MutablePair; @@ -37,6 +35,7 @@ import com.simibubi.create.foundation.collision.Matrix3d; import com.simibubi.create.foundation.mixin.accessor.ServerLevelAccessor; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.ContraptionData; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java index 5b0d02320..3dd2ff7c1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java @@ -4,10 +4,6 @@ import java.util.List; import javax.annotation.Nullable; -import com.simibubi.create.foundation.utility.ContraptionData; - -import net.minecraft.network.chat.MutableComponent; - import org.apache.commons.lang3.tuple.MutablePair; import com.simibubi.create.AllItems; @@ -21,6 +17,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Ori import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.ContraptionMovementSetting; +import com.simibubi.create.foundation.utility.ContraptionData; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.NBTHelper; @@ -32,6 +29,7 @@ import net.minecraft.core.NonNullList; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; import net.minecraft.core.dispenser.DispenseItemBehavior; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.tags.BlockTags; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/BoilerHeaters.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/BoilerHeaters.java index 12bde6e81..e042d0e65 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/BoilerHeaters.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/BoilerHeaters.java @@ -9,7 +9,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; -import com.simibubi.create.foundation.utility.CreateRegistry; +import com.simibubi.create.foundation.utility.AttachedRegistry; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; @@ -17,10 +17,9 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.IRegistryDelegate; public class BoilerHeaters { - private static final CreateRegistry BLOCK_HEATERS = new CreateRegistry<>(ForgeRegistries.BLOCKS); + private static final AttachedRegistry BLOCK_HEATERS = new AttachedRegistry<>(ForgeRegistries.BLOCKS); private static final List GLOBAL_HEATERS = new ArrayList<>(); public static void registerHeater(ResourceLocation block, Heater heater) { @@ -31,11 +30,6 @@ public class BoilerHeaters { BLOCK_HEATERS.register(block, heater); } - @Deprecated(forRemoval = true) - public static void registerHeater(IRegistryDelegate block, Heater heater) { - registerHeater(block.name(), heater); - } - public static void registerHeaterProvider(HeaterProvider provider) { GLOBAL_HEATERS.add(provider); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java index 980d506eb..d3cb6f53e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/itemAssembly/SequencedAssemblyRecipe.java @@ -31,6 +31,7 @@ import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.wrapper.RecipeWrapper; @@ -220,29 +221,31 @@ public class SequencedAssemblyRecipe implements Recipe { } @OnlyIn(Dist.CLIENT) - public static void addToTooltip(List toolTip, ItemStack stack) { + public static void addToTooltip(ItemTooltipEvent event) { + ItemStack stack = event.getItemStack(); if (!stack.hasTag() || !stack.getTag() .contains("SequencedAssembly")) return; CompoundTag compound = stack.getTag() .getCompound("SequencedAssembly"); ResourceLocation resourceLocation = new ResourceLocation(compound.getString("id")); - Optional> recipe = Minecraft.getInstance().level.getRecipeManager() + Optional> optionalRecipe = Minecraft.getInstance().level.getRecipeManager() .byKey(resourceLocation); - if (!recipe.isPresent()) + if (!optionalRecipe.isPresent()) return; - Recipe iRecipe = recipe.get(); - if (!(iRecipe instanceof SequencedAssemblyRecipe)) + Recipe recipe = optionalRecipe.get(); + if (!(recipe instanceof SequencedAssemblyRecipe)) return; - SequencedAssemblyRecipe sequencedAssemblyRecipe = (SequencedAssemblyRecipe) iRecipe; + SequencedAssemblyRecipe sequencedAssemblyRecipe = (SequencedAssemblyRecipe) recipe; int length = sequencedAssemblyRecipe.sequence.size(); int step = sequencedAssemblyRecipe.getStep(stack); int total = length * sequencedAssemblyRecipe.loops; - toolTip.add(Components.immutableEmpty()); - toolTip.add(Lang.translateDirect("recipe.sequenced_assembly") + List tooltip = event.getToolTip(); + tooltip.add(Components.immutableEmpty()); + tooltip.add(Lang.translateDirect("recipe.sequenced_assembly") .withStyle(ChatFormatting.GRAY)); - toolTip.add(Lang.translateDirect("recipe.assembly.progress", step, total) + tooltip.add(Lang.translateDirect("recipe.assembly.progress", step, total) .withStyle(ChatFormatting.DARK_GRAY)); int remaining = total - step; @@ -253,10 +256,10 @@ public class SequencedAssemblyRecipe implements Recipe { Component textComponent = sequencedRecipe.getAsAssemblyRecipe() .getDescriptionForAssembly(); if (i == 0) - toolTip.add(Lang.translateDirect("recipe.assembly.next", textComponent) + tooltip.add(Lang.translateDirect("recipe.assembly.next", textComponent) .withStyle(ChatFormatting.AQUA)); else - toolTip.add(Components.literal("-> ").append(textComponent) + tooltip.add(Components.literal("-> ").append(textComponent) .withStyle(ChatFormatting.DARK_AQUA)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java index 665226cb1..bf68e22f5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java @@ -4,7 +4,7 @@ import java.util.List; import com.simibubi.create.content.contraptions.base.IRotate.StressImpact; import com.simibubi.create.foundation.advancement.AllAdvancements; -import com.simibubi.create.foundation.item.ItemDescription; +import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Color; @@ -86,7 +86,7 @@ public class StressGaugeTileEntity extends GaugeTileEntity { .forGoggles(tooltip); if (getTheoreticalSpeed() == 0) - Lang.text(ItemDescription.makeProgressBar(3, 0)) + Lang.text(TooltipHelper.makeProgressBar(3, 0)) .translate("gui.stressometer.no_rotation") .style(ChatFormatting.DARK_GRAY) .forGoggles(tooltip); diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java index 449c7d8f8..46c96baab 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.curiosities.weapons; +import static com.simibubi.create.content.curiosities.weapons.PotatoProjectileRenderMode.entityRandom; + import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.utility.AngleHelper; diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java index f0b7b85ff..90fe9ea87 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java @@ -10,7 +10,6 @@ import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.item.CustomArmPoseItem; -import com.simibubi.create.foundation.item.ItemDescription; import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.NBTHelper; @@ -63,10 +62,9 @@ public abstract class ZapperItem extends Item implements CustomArmPoseItem { .getCompound("BlockUsed")) .getBlock() .getName(); - ItemDescription.add(tooltip, - Lang.translateDirect("terrainzapper.usingBlock", - usedBlock.withStyle(ChatFormatting.GRAY)) - .withStyle(ChatFormatting.DARK_GRAY)); + tooltip.add(Lang.translateDirect("terrainzapper.usingBlock", + usedBlock.withStyle(ChatFormatting.GRAY)) + .withStyle(ChatFormatting.DARK_GRAY)); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/display/AllDisplayBehaviours.java b/src/main/java/com/simibubi/create/content/logistics/block/display/AllDisplayBehaviours.java index 55637bae2..c3e44e619 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/display/AllDisplayBehaviours.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/display/AllDisplayBehaviours.java @@ -17,7 +17,7 @@ import com.simibubi.create.content.logistics.block.display.source.ScoreboardDisp import com.simibubi.create.content.logistics.block.display.target.DisplayTarget; import com.simibubi.create.content.logistics.block.display.target.LecternDisplayTarget; import com.simibubi.create.content.logistics.block.display.target.SignDisplayTarget; -import com.simibubi.create.foundation.utility.CreateRegistry; +import com.simibubi.create.foundation.utility.AttachedRegistry; import com.simibubi.create.foundation.utility.RegisteredObjects; import com.tterrag.registrate.util.nullness.NonNullConsumer; @@ -30,16 +30,15 @@ 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.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.IRegistryDelegate; public class AllDisplayBehaviours { public static final Map GATHERER_BEHAVIOURS = new HashMap<>(); - private static final CreateRegistry> SOURCES_BY_BLOCK = new CreateRegistry<>(ForgeRegistries.BLOCKS); - private static final CreateRegistry, List> SOURCES_BY_TILE = new CreateRegistry<>(ForgeRegistries.BLOCK_ENTITIES); + private static final AttachedRegistry> SOURCES_BY_BLOCK = new AttachedRegistry<>(ForgeRegistries.BLOCKS); + private static final AttachedRegistry, List> SOURCES_BY_TILE = new AttachedRegistry<>(ForgeRegistries.BLOCK_ENTITIES); - private static final CreateRegistry TARGETS_BY_BLOCK = new CreateRegistry<>(ForgeRegistries.BLOCKS); - private static final CreateRegistry, DisplayTarget> TARGETS_BY_TILE = new CreateRegistry<>(ForgeRegistries.BLOCK_ENTITIES); + private static final AttachedRegistry TARGETS_BY_BLOCK = new AttachedRegistry<>(ForgeRegistries.BLOCKS); + private static final AttachedRegistry, DisplayTarget> TARGETS_BY_TILE = new AttachedRegistry<>(ForgeRegistries.BLOCK_ENTITIES); public static DisplayBehaviour register(ResourceLocation id, DisplayBehaviour behaviour) { behaviour.id = id; @@ -103,16 +102,6 @@ public class AllDisplayBehaviours { } } - @Deprecated(forRemoval = true) - public static void assignBlock(DisplayBehaviour behaviour, IRegistryDelegate block) { - assignBlock(behaviour, block.name()); - } - - @Deprecated(forRemoval = true) - public static void assignTile(DisplayBehaviour behaviour, IRegistryDelegate> teType) { - assignTile(behaviour, teType.name()); - } - public static NonNullConsumer assignDataBehaviour(DisplayBehaviour behaviour, String... suffix) { return b -> { diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java index f06e71732..bd38b38b9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java @@ -104,7 +104,7 @@ public abstract class AbstractFilterScreen ex button.setToolTip(button.getToolTip() .get(0)); button.getToolTip() - .add(TooltipHelper.holdShift(Palette.Yellow, hasShiftDown())); + .add(TooltipHelper.holdShift(Palette.YELLOW, hasShiftDown())); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java index cda585844..b169f458c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java @@ -10,7 +10,6 @@ import com.simibubi.create.AllItems; import com.simibubi.create.AllKeys; import com.simibubi.create.content.contraptions.processing.EmptyingByBasin; import com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode; -import com.simibubi.create.foundation.item.ItemDescription; import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Lang; @@ -75,8 +74,8 @@ public class FilterItem extends Item implements MenuProvider { List makeSummary = makeSummary(stack); if (makeSummary.isEmpty()) return; - ItemDescription.add(tooltip, Components.literal(" ")); - ItemDescription.add(tooltip, makeSummary); + tooltip.add(Components.literal(" ")); + tooltip.addAll(makeSummary); } } diff --git a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java index affe9842b..0afc7c6d3 100644 --- a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java +++ b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java @@ -10,7 +10,6 @@ import static com.simibubi.create.foundation.data.WindowGen.woodenWindowPane; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.Create; -import com.simibubi.create.content.AllSections; import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour; import com.simibubi.create.foundation.block.connected.SimpleCTBehaviour; import com.simibubi.create.foundation.data.BlockStateGen; @@ -31,9 +30,7 @@ import net.minecraftforge.common.Tags; public class AllPaletteBlocks { static { - REGISTRATE - .creativeModeTab(() -> Create.PALETTES_CREATIVE_TAB) - .startSection(AllSections.PALETTES); + REGISTRATE.creativeModeTab(() -> Create.PALETTES_CREATIVE_TAB); } // Windows and Glass diff --git a/src/main/java/com/simibubi/create/content/palettes/PalettesCreativeModeTab.java b/src/main/java/com/simibubi/create/content/palettes/PalettesCreativeModeTab.java new file mode 100644 index 000000000..c8519cd87 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/palettes/PalettesCreativeModeTab.java @@ -0,0 +1,21 @@ +package com.simibubi.create.content.palettes; + +import com.simibubi.create.foundation.item.CreateCreativeModeTab; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; + +public class PalettesCreativeModeTab extends CreateCreativeModeTab { + public PalettesCreativeModeTab() { + super("palettes"); + } + + @Override + public void addItems(NonNullList items, boolean specialItems) { + } + + @Override + public ItemStack makeIcon() { + return AllPaletteBlocks.ORNATE_IRON_WINDOW.asStack(); + } +} diff --git a/src/main/java/com/simibubi/create/content/palettes/PalettesItemGroup.java b/src/main/java/com/simibubi/create/content/palettes/PalettesItemGroup.java deleted file mode 100644 index 980ca176d..000000000 --- a/src/main/java/com/simibubi/create/content/palettes/PalettesItemGroup.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.simibubi.create.content.palettes; - -import java.util.EnumSet; - -import com.simibubi.create.content.AllSections; -import com.simibubi.create.foundation.item.CreateItemGroupBase; - -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.ItemStack; - -public class PalettesItemGroup extends CreateItemGroupBase { - - public PalettesItemGroup() { - super("palettes"); - } - - @Override - protected EnumSet getSections() { - return EnumSet.of(AllSections.PALETTES); - } - - @Override - public void addItems(NonNullList items, boolean specialItems) {} - - @Override - public ItemStack makeIcon() { - return new ItemStack(AllPaletteBlocks.ORNATE_IRON_WINDOW.get()); - } - -} diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java index 08d759717..f525d405f 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java @@ -245,7 +245,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen itemTooltip = event.getToolTip(); - List toolTip = new ArrayList<>(); - toolTip.add(itemTooltip.remove(0)); - TooltipHelper.getTooltip(stack) - .addInformation(toolTip); - itemTooltip.addAll(0, toolTip); - } - - if (stack.getItem() instanceof BlockItem) { - BlockItem item = (BlockItem) stack.getItem(); - if (item.getBlock() instanceof IRotate || item.getBlock() instanceof SteamEngineBlock) { - List kineticStats = ItemDescription.getKineticStats(item.getBlock()); - if (!kineticStats.isEmpty()) { - event.getToolTip() - .add(Components.immutableEmpty()); - event.getToolTip() - .addAll(kineticStats); - } - } - } - - PonderTooltipHandler.addToTooltip(event.getToolTip(), stack); - SequencedAssemblyRecipe.addToTooltip(event.getToolTip(), stack); + ItemTooltipHandler.addToTooltip(event); + PonderTooltipHandler.addToTooltip(event); + SequencedAssemblyRecipe.addToTooltip(event); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/block/BlockStressValues.java b/src/main/java/com/simibubi/create/foundation/block/BlockStressValues.java index b1592abd6..24974a783 100644 --- a/src/main/java/com/simibubi/create/foundation/block/BlockStressValues.java +++ b/src/main/java/com/simibubi/create/foundation/block/BlockStressValues.java @@ -74,6 +74,16 @@ public class BlockStressValues { return BlockStressDefaults.DEFAULT_CAPACITIES.containsKey(blockId); } + @Nullable + public static Couple getGeneratedRPM(Block block) { + ResourceLocation blockId = RegisteredObjects.getKeyOrThrow(block); + IStressValueProvider provider = getProvider(blockId.getNamespace()); + if (provider != null) { + return provider.getGeneratedRPM(block); + } + return null; + } + public interface IStressValueProvider { /** * Gets the stress impact of a block. diff --git a/src/main/java/com/simibubi/create/foundation/config/ContraptionMovementSetting.java b/src/main/java/com/simibubi/create/foundation/config/ContraptionMovementSetting.java index 5aca81cdb..017df144f 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ContraptionMovementSetting.java +++ b/src/main/java/com/simibubi/create/foundation/config/ContraptionMovementSetting.java @@ -5,7 +5,7 @@ import java.util.function.Supplier; import javax.annotation.Nullable; -import com.simibubi.create.foundation.utility.CreateRegistry; +import com.simibubi.create.foundation.utility.AttachedRegistry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; @@ -17,7 +17,7 @@ import net.minecraftforge.registries.ForgeRegistries; public enum ContraptionMovementSetting { MOVABLE, NO_PICKUP, UNMOVABLE; - private static final CreateRegistry> SETTING_SUPPLIERS = new CreateRegistry<>(ForgeRegistries.BLOCKS); + private static final AttachedRegistry> SETTING_SUPPLIERS = new AttachedRegistry<>(ForgeRegistries.BLOCKS); public static void register(ResourceLocation block, Supplier settingSupplier) { SETTING_SUPPLIERS.register(block, settingSupplier); diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java index e0200c3b5..0647d8148 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java @@ -2,18 +2,12 @@ package com.simibubi.create.foundation.data; import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly; -import java.util.Collection; -import java.util.IdentityHashMap; -import java.util.Map; -import java.util.Map.Entry; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Supplier; -import java.util.stream.Collectors; import com.simibubi.create.Create; import com.simibubi.create.CreateClient; -import com.simibubi.create.content.AllSections; import com.simibubi.create.content.contraptions.fluids.VirtualFluid; import com.simibubi.create.content.contraptions.relays.encased.CasingConnectivity; import com.simibubi.create.foundation.block.connected.CTModel; @@ -22,17 +16,13 @@ import com.simibubi.create.foundation.utility.RegisteredObjects; import com.tterrag.registrate.AbstractRegistrate; import com.tterrag.registrate.builders.BlockBuilder; import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory; -import com.tterrag.registrate.builders.Builder; import com.tterrag.registrate.builders.FluidBuilder; -import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.NonNullBiFunction; import com.tterrag.registrate.util.nullness.NonNullConsumer; import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.world.entity.Entity; @@ -49,9 +39,6 @@ import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.ForgeFlowingFluid; import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.IForgeRegistryEntry; -import net.minecraftforge.registries.RegistryObject; public class CreateRegistrate extends AbstractRegistrate { protected CreateRegistrate(String modid) { @@ -62,66 +49,11 @@ public class CreateRegistrate extends AbstractRegistrate { return new CreateRegistrate(modid); } - @Deprecated(forRemoval = true) - public static NonNullSupplier lazy(String modid) { - return NonNullSupplier - .lazy(() -> new CreateRegistrate(modid).registerEventListeners(FMLJavaModLoadingContext.get() - .getModEventBus())); - } - @Override public CreateRegistrate registerEventListeners(IEventBus bus) { return super.registerEventListeners(bus); } - /* Section Tracking */ - - protected static final Map, AllSections> SECTION_LOOKUP = new IdentityHashMap<>(); - protected AllSections currentSection; - - public CreateRegistrate startSection(AllSections section) { - this.currentSection = section; - return this; - } - - public AllSections currentSection() { - return currentSection; - } - - @Override - protected , T extends R> RegistryEntry accept(String name, - ResourceKey> type, Builder builder, NonNullSupplier creator, - NonNullFunction, ? extends RegistryEntry> entryFactory) { - RegistryEntry ret = super.accept(name, type, builder, creator, entryFactory); - SECTION_LOOKUP.put(ret, currentSection()); - return ret; - } - - public void addToSection(RegistryEntry entry, AllSections section) { - SECTION_LOOKUP.put(entry, section); - } - - public AllSections getSection(RegistryEntry entry) { - return SECTION_LOOKUP.getOrDefault(entry, AllSections.UNASSIGNED); - } - - public AllSections getSection(IForgeRegistryEntry entry) { - for (Entry, AllSections> mapEntry : SECTION_LOOKUP.entrySet()) { - if (mapEntry.getKey().get() == entry) { - return mapEntry.getValue(); - } - } - return AllSections.UNASSIGNED; - } - - public > Collection> getAll(AllSections section, - ResourceKey> registryType) { - return this.getAll(registryType) - .stream() - .filter(e -> getSection(e) == section) - .collect(Collectors.toList()); - } - public CreateTileEntityBuilder tileEntity(String name, BlockEntityFactory factory) { return this.tileEntity(this.self(), name, factory); diff --git a/src/main/java/com/simibubi/create/foundation/data/recipe/StandardRecipeGen.java b/src/main/java/com/simibubi/create/foundation/data/recipe/StandardRecipeGen.java index 5401c429c..b1284cc51 100644 --- a/src/main/java/com/simibubi/create/foundation/data/recipe/StandardRecipeGen.java +++ b/src/main/java/com/simibubi/create/foundation/data/recipe/StandardRecipeGen.java @@ -24,10 +24,8 @@ import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.AllTags; import com.simibubi.create.AllTags.AllItemTags; import com.simibubi.create.Create; -import com.simibubi.create.content.AllSections; import com.simibubi.create.content.palettes.AllPaletteBlocks; import com.simibubi.create.content.palettes.AllPaletteStoneTypes; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.RegisteredObjects; import com.tterrag.registrate.util.entry.BlockEntry; import com.tterrag.registrate.util.entry.ItemEntry; @@ -68,7 +66,7 @@ public class StandardRecipeGen extends CreateRecipeProvider { * (Ctrl-o) in Eclipse */ - private Marker MATERIALS = enterSection(AllSections.MATERIALS); + private Marker MATERIALS = enterFolder("materials"); GeneratedRecipe @@ -136,7 +134,7 @@ public class StandardRecipeGen extends CreateRecipeProvider { ; - private Marker CURIOSITIES = enterSection(AllSections.CURIOSITIES); + private Marker CURIOSITIES = enterFolder("curiosities"); GeneratedRecipe @@ -175,7 +173,7 @@ public class StandardRecipeGen extends CreateRecipeProvider { ; - private Marker KINETICS = enterSection(AllSections.KINETICS); + private Marker KINETICS = enterFolder("kinetics"); GeneratedRecipe ANDESITE_LADDER = create(AllBlocks.ANDESITE_LADDER).returns(4) .unlockedBy(I::andesite) @@ -829,7 +827,7 @@ public class StandardRecipeGen extends CreateRecipeProvider { ; - private Marker LOGISTICS = enterSection(AllSections.LOGISTICS); + private Marker LOGISTICS = enterFolder("logistics"); GeneratedRecipe @@ -935,7 +933,7 @@ public class StandardRecipeGen extends CreateRecipeProvider { ; - private Marker SCHEMATICS = enterSection(AllSections.SCHEMATICS); + private Marker SCHEMATICS = enterFolder("schematics"); GeneratedRecipe @@ -965,7 +963,7 @@ public class StandardRecipeGen extends CreateRecipeProvider { ; - private Marker PALETTES = enterSection(AllSections.PALETTES); + private Marker PALETTES = enterFolder("palettes"); GeneratedRecipe @@ -1086,11 +1084,6 @@ public class StandardRecipeGen extends CreateRecipeProvider { String currentFolder = ""; - Marker enterSection(AllSections section) { - currentFolder = Lang.asId(section.name()); - return new Marker(); - } - Marker enterFolder(String folder) { currentFolder = folder; return new Marker(); diff --git a/src/main/java/com/simibubi/create/foundation/item/BaseCreativeModeTab.java b/src/main/java/com/simibubi/create/foundation/item/BaseCreativeModeTab.java new file mode 100644 index 000000000..9e96c3d85 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/item/BaseCreativeModeTab.java @@ -0,0 +1,16 @@ +package com.simibubi.create.foundation.item; + +import com.simibubi.create.AllBlocks; + +import net.minecraft.world.item.ItemStack; + +public class BaseCreativeModeTab extends CreateCreativeModeTab { + public BaseCreativeModeTab() { + super("base"); + } + + @Override + public ItemStack makeIcon() { + return AllBlocks.COGWHEEL.asStack(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/item/CreateCreativeModeTab.java b/src/main/java/com/simibubi/create/foundation/item/CreateCreativeModeTab.java new file mode 100644 index 000000000..2fdbbef70 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/item/CreateCreativeModeTab.java @@ -0,0 +1,48 @@ +package com.simibubi.create.foundation.item; + +import com.simibubi.create.Create; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.registries.ForgeRegistries; + +public abstract class CreateCreativeModeTab extends CreativeModeTab { + public CreateCreativeModeTab(String id) { + super(Create.ID + "." + id); + } + + @Override + public void fillItemList(NonNullList items) { + addItems(items, true); + addBlocks(items); + addItems(items, false); + } + + public void addBlocks(NonNullList items) { + for (Item item : ForgeRegistries.ITEMS) { + if (item instanceof BlockItem) { + item.fillItemCategory(this, items); + } + } + } + + public void addItems(NonNullList items, boolean specialItems) { + ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); + + for (Item item : ForgeRegistries.ITEMS) { + if (!(item instanceof BlockItem)) { + ItemStack stack = new ItemStack(item); + BakedModel model = itemRenderer.getModel(stack, null, null, 0); + if (model.isGui3d() == specialItems) { + item.fillItemCategory(this, items); + } + } + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/item/CreateItemGroupBase.java b/src/main/java/com/simibubi/create/foundation/item/CreateItemGroupBase.java deleted file mode 100644 index e4d91d0e3..000000000 --- a/src/main/java/com/simibubi/create/foundation/item/CreateItemGroupBase.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.simibubi.create.foundation.item; - -import java.util.Collection; -import java.util.EnumSet; -import java.util.stream.Collectors; - -import com.simibubi.create.Create; -import com.simibubi.create.content.AllSections; -import com.tterrag.registrate.util.entry.RegistryEntry; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.NonNullList; -import net.minecraft.core.Registry; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.Block; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -public abstract class CreateItemGroupBase extends CreativeModeTab { - - public CreateItemGroupBase(String id) { - super(Create.ID + "." + id); - } - - @Override - @OnlyIn(Dist.CLIENT) - public void fillItemList(NonNullList items) { - addItems(items, true); - addBlocks(items); - addItems(items, false); - } - - @OnlyIn(Dist.CLIENT) - public void addBlocks(NonNullList items) { - for (RegistryEntry entry : getBlocks()) { - Block def = entry.get(); - Item item = def.asItem(); - if (item != Items.AIR) - def.fillItemCategory(this, items); - } - } - - @OnlyIn(Dist.CLIENT) - public void addItems(NonNullList items, boolean specialItems) { - ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); - - for (RegistryEntry entry : getItems()) { - Item item = entry.get(); - if (item instanceof BlockItem) - continue; - ItemStack stack = new ItemStack(item); - BakedModel model = itemRenderer.getModel(stack, null, null, 0); - if (model.isGui3d() != specialItems) - continue; - item.fillItemCategory(this, items); - } - } - - protected Collection> getBlocks() { - return getSections().stream() - .flatMap(s -> Create.REGISTRATE - .getAll(s, Registry.BLOCK_REGISTRY) - .stream()) - .collect(Collectors.toList()); - } - - protected Collection> getItems() { - return getSections().stream() - .flatMap(s -> Create.REGISTRATE - .getAll(s, Registry.ITEM_REGISTRY) - .stream()) - .collect(Collectors.toList()); - } - - protected EnumSet getSections() { - return EnumSet.allOf(AllSections.class); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java b/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java index b8b85e2f6..bc98a5380 100644 --- a/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java +++ b/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java @@ -1,289 +1,197 @@ package com.simibubi.create.foundation.item; -import static com.simibubi.create.foundation.item.TooltipHelper.cutStringTextComponent; -import static com.simibubi.create.foundation.item.TooltipHelper.cutTextComponent; -import static net.minecraft.ChatFormatting.AQUA; -import static net.minecraft.ChatFormatting.BLUE; import static net.minecraft.ChatFormatting.DARK_GRAY; -import static net.minecraft.ChatFormatting.DARK_GREEN; -import static net.minecraft.ChatFormatting.DARK_PURPLE; -import static net.minecraft.ChatFormatting.DARK_RED; -import static net.minecraft.ChatFormatting.GOLD; import static net.minecraft.ChatFormatting.GRAY; -import static net.minecraft.ChatFormatting.GREEN; -import static net.minecraft.ChatFormatting.LIGHT_PURPLE; -import static net.minecraft.ChatFormatting.RED; -import static net.minecraft.ChatFormatting.STRIKETHROUGH; import static net.minecraft.ChatFormatting.WHITE; -import static net.minecraft.ChatFormatting.YELLOW; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import com.simibubi.create.content.contraptions.base.IRotate; -import com.simibubi.create.content.contraptions.base.IRotate.StressImpact; -import com.simibubi.create.content.contraptions.goggles.GogglesItem; -import com.simibubi.create.foundation.block.BlockStressValues; -import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.config.CKinetics; +import org.apache.commons.lang3.tuple.Pair; + +import com.google.common.collect.ImmutableList; import com.simibubi.create.foundation.utility.Components; -import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.Lang; -import com.simibubi.create.foundation.utility.LangBuilder; import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.level.block.Block; -public class ItemDescription { +public record ItemDescription(ImmutableList lines, ImmutableList linesOnShift, ImmutableList linesOnCtrl) { + public static final ItemDescription MISSING = new ItemDescription(ImmutableList.of(), ImmutableList.of(), ImmutableList.of()); - public static final ItemDescription MISSING = new ItemDescription(null); - public static Component trim = Components.literal(" ").withStyle(WHITE, STRIKETHROUGH); + public static Builder builder() { + return new Builder(); + } - public enum Palette { - - Blue(BLUE, AQUA), - Green(DARK_GREEN, GREEN), - Yellow(GOLD, YELLOW), - Red(DARK_RED, RED), - Purple(DARK_PURPLE, LIGHT_PURPLE), - Gray(DARK_GRAY, GRAY), - - ; - - private Palette(ChatFormatting primary, ChatFormatting highlight) { - color = primary; - hColor = highlight; + public static ItemDescription create(Palette palette, String translationKey) { + if (!I18n.exists(translationKey)) { + return MISSING; } - public ChatFormatting color; - public ChatFormatting hColor; - } + Builder builder = builder(); + builder.palette(palette); - private List lines; - private List linesOnShift; - private List linesOnCtrl; - private Palette palette; - - public ItemDescription(Palette palette) { - this.palette = palette; - lines = new ArrayList<>(); - linesOnShift = new ArrayList<>(); - linesOnCtrl = new ArrayList<>(); - } - - public ItemDescription withSummary(Component summary) { - addStrings(linesOnShift, cutTextComponent(summary, palette.color, palette.hColor)); - return this; - } - - public static List getKineticStats(Block block) { - List list = new ArrayList<>(); - - CKinetics config = AllConfigs.SERVER.kinetics; - LangBuilder rpmUnit = Lang.translate("generic.unit.rpm"); - LangBuilder suUnit = Lang.translate("generic.unit.stress"); - - boolean hasGoggles = GogglesItem.isWearingGoggles(Minecraft.getInstance().player); - - boolean showStressImpact; - if (!(block instanceof IRotate)) { - showStressImpact = true; - } else { - showStressImpact = !((IRotate) block).hideStressImpact(); + // Summary + String summaryKey = translationKey + ".summary"; + if (I18n.exists(summaryKey)) { + builder.addSummary(I18n.get(summaryKey)); } - boolean hasStressImpact = - StressImpact.isEnabled() && showStressImpact && BlockStressValues.getImpact(block) > 0; - boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.hasCapacity(block); - - if (hasStressImpact) { - Lang.translate("tooltip.stressImpact") - .style(GRAY) - .addTo(list); - - double impact = BlockStressValues.getImpact(block); - StressImpact impactId = impact >= config.highStressImpact.get() ? StressImpact.HIGH - : (impact >= config.mediumStressImpact.get() ? StressImpact.MEDIUM : StressImpact.LOW); - LangBuilder builder = Lang.builder() - .add(Lang.text(makeProgressBar(3, impactId.ordinal() + 1)) - .style(impactId.getAbsoluteColor())); - - if (hasGoggles) { - builder.add(Lang.number(impact)) - .text("x ") - .add(rpmUnit) - .addTo(list); - } else - builder.translate("tooltip.stressImpact." + Lang.asId(impactId.name())) - .addTo(list); + // Behaviours + for (int i = 1; i < 100; i++) { + String conditionKey = translationKey + ".condition" + i; + String behaviourKey = translationKey + ".behaviour" + i; + if (!I18n.exists(conditionKey)) + break; + builder.addBehaviour(I18n.get(conditionKey), I18n.get(behaviourKey)); } - if (hasStressCapacity) { - Lang.translate("tooltip.capacityProvided") - .style(GRAY) - .addTo(list); - - double capacity = BlockStressValues.getCapacity(block); - BlockStressValues.IStressValueProvider stressProvider = BlockStressValues.getProvider(block); - Couple generatedRPM = stressProvider != null ? - stressProvider.getGeneratedRPM(block) - : null; - - StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.HIGH - : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.LOW); - StressImpact opposite = StressImpact.values()[StressImpact.values().length - 2 - impactId.ordinal()]; - LangBuilder builder = Lang.builder() - .add(Lang.text(makeProgressBar(3, impactId.ordinal() + 1)) - .style(opposite.getAbsoluteColor())); - - if (hasGoggles) { - builder.add(Lang.number(capacity)) - .text("x ") - .add(rpmUnit) - .addTo(list); - - if (generatedRPM != null) { - LangBuilder amount = Lang.number(capacity * generatedRPM.getSecond()) - .add(suUnit); - Lang.text(" -> ") - .add(!generatedRPM.getFirst() - .equals(generatedRPM.getSecond()) ? Lang.translate("tooltip.up_to", amount) : amount) - .style(DARK_GRAY) - .addTo(list); - } - } else - builder.translate("tooltip.capacityProvided." + Lang.asId(impactId.name())) - .addTo(list); + // Actions + for (int i = 1; i < 100; i++) { + String controlKey = translationKey + ".control" + i; + String actionKey = translationKey + ".action" + i; + if (!I18n.exists(controlKey)) + break; + builder.addAction(I18n.get(controlKey), I18n.get(actionKey)); } - return list; + return builder.build(); } - public static String makeProgressBar(int length, int filledLength) { - String bar = " "; - int emptySpaces = length - filledLength; - for (int i = 0; i < filledLength; i++) - bar += "\u2588"; - for (int i = 0; i < emptySpaces; i++) - bar += "\u2592"; - return bar + " "; - } - - public ItemDescription withBehaviour(String condition, String behaviour) { - add(linesOnShift, Components.literal(condition).withStyle(GRAY)); - addStrings(linesOnShift, cutStringTextComponent(behaviour, palette.color, palette.hColor, 1)); - return this; - } - - public ItemDescription withControl(String condition, String action) { - add(linesOnCtrl, Components.literal(condition).withStyle(GRAY)); - addStrings(linesOnCtrl, cutStringTextComponent(action, palette.color, palette.hColor, 1)); - return this; - } - - public ItemDescription createTabs() { - boolean hasDescription = !linesOnShift.isEmpty(); - boolean hasControls = !linesOnCtrl.isEmpty(); - - if (hasDescription || hasControls) { - String[] holdDesc = Lang.translateDirect("tooltip.holdForDescription", "$") - .getString() - .split("\\$"); - String[] holdCtrl = Lang.translateDirect("tooltip.holdForControls", "$") - .getString() - .split("\\$"); - MutableComponent keyShift = Lang.translateDirect("tooltip.keyShift"); - MutableComponent keyCtrl = Lang.translateDirect("tooltip.keyCtrl"); - for (List list : Arrays.asList(lines, linesOnShift, linesOnCtrl)) { - boolean shift = list == linesOnShift; - boolean ctrl = list == linesOnCtrl; - - if (holdDesc.length != 2 || holdCtrl.length != 2) { - list.add(0, Components.literal("Invalid lang formatting!")); - continue; - } - - if (hasControls) { - MutableComponent tabBuilder = Components.empty(); - tabBuilder.append(Components.literal(holdCtrl[0]).withStyle(DARK_GRAY)); - tabBuilder.append(keyCtrl.plainCopy() - .withStyle(ctrl ? WHITE : GRAY)); - tabBuilder.append(Components.literal(holdCtrl[1]).withStyle(DARK_GRAY)); - list.add(0, tabBuilder); - } - - if (hasDescription) { - MutableComponent tabBuilder = Components.empty(); - tabBuilder.append(Components.literal(holdDesc[0]).withStyle(DARK_GRAY)); - tabBuilder.append(keyShift.plainCopy() - .withStyle(shift ? WHITE : GRAY)); - tabBuilder.append(Components.literal(holdDesc[1]).withStyle(DARK_GRAY)); - list.add(0, tabBuilder); - } - - if (shift || ctrl) - list.add(hasDescription && hasControls ? 2 : 1, Components.immutableEmpty()); - } - } - - if (!hasDescription) - linesOnShift = lines; - if (!hasControls) - linesOnCtrl = lines; - - return this; - } - - public static String hightlight(String s, Palette palette) { - return palette.hColor + s + palette.color; - } - - public static void addStrings(List infoList, List textLines) { - textLines.forEach(s -> add(infoList, s)); - } - - public static void add(List infoList, List textLines) { - infoList.addAll(textLines); - } - - public static void add(List infoList, Component line) { - infoList.add(line); - } - - public Palette getPalette() { - return palette; - } - - public List addInformation(List tooltip) { + public void addInformation(List tooltip) { if (Screen.hasShiftDown()) { tooltip.addAll(linesOnShift); - return tooltip; + return; } if (Screen.hasControlDown()) { tooltip.addAll(linesOnCtrl); - return tooltip; + return; } tooltip.addAll(lines); - return tooltip; } - public List getLines() { - return lines; + public record Palette(ChatFormatting primary, ChatFormatting highlight) { + public static final Palette BLUE = new Palette(ChatFormatting.BLUE, ChatFormatting.AQUA); + public static final Palette GREEN = new Palette(ChatFormatting.DARK_GREEN, ChatFormatting.GREEN); + public static final Palette YELLOW = new Palette(ChatFormatting.GOLD, ChatFormatting.YELLOW); + public static final Palette RED = new Palette(ChatFormatting.DARK_RED, ChatFormatting.RED); + public static final Palette PURPLE = new Palette(ChatFormatting.DARK_PURPLE, ChatFormatting.LIGHT_PURPLE); + public static final Palette GRAY = new Palette(ChatFormatting.DARK_GRAY, ChatFormatting.GRAY); } - public List getLinesOnCtrl() { - return linesOnCtrl; - } + public static class Builder { + protected final List summary = new ArrayList<>(); + protected final List> behaviours = new ArrayList<>(); + protected final List> actions = new ArrayList<>(); + protected Palette palette; - public List getLinesOnShift() { - return linesOnShift; - } + public Builder addSummary(String summaryLine) { + summary.add(summaryLine); + return this; + } + public Builder addBehaviour(String condition, String behaviour) { + behaviours.add(Pair.of(condition, behaviour)); + return this; + } + + public Builder addAction(String condition, String action) { + actions.add(Pair.of(condition, action)); + return this; + } + + public Builder palette(Palette palette) { + this.palette = palette; + return this; + } + + public ItemDescription build() { + List lines = new ArrayList<>(); + List linesOnShift = new ArrayList<>(); + List linesOnCtrl = new ArrayList<>(); + + for (String summaryLine : summary) { + linesOnShift.addAll(TooltipHelper.cutTextComponent(Components.literal(summaryLine), palette.primary(), palette.highlight())); + } + + if (!behaviours.isEmpty()) { + linesOnShift.add(Components.immutableEmpty()); + } + + for (Pair behaviourPair : behaviours) { + String condition = behaviourPair.getLeft(); + String behaviour = behaviourPair.getRight(); + linesOnShift.add(Components.literal(condition).withStyle(GRAY)); + linesOnShift.addAll(TooltipHelper.cutStringTextComponent(behaviour, palette.primary(), palette.highlight(), 1)); + } + + for (Pair actionPair : actions) { + String condition = actionPair.getLeft(); + String action = actionPair.getRight(); + linesOnCtrl.add(Components.literal(condition).withStyle(GRAY)); + linesOnCtrl.addAll(TooltipHelper.cutStringTextComponent(action, palette.primary(), palette.highlight(), 1)); + } + + boolean hasDescription = !linesOnShift.isEmpty(); + boolean hasControls = !linesOnCtrl.isEmpty(); + + if (hasDescription || hasControls) { + String[] holdDesc = Lang.translateDirect("tooltip.holdForDescription", "$") + .getString() + .split("\\$"); + String[] holdCtrl = Lang.translateDirect("tooltip.holdForControls", "$") + .getString() + .split("\\$"); + MutableComponent keyShift = Lang.translateDirect("tooltip.keyShift"); + MutableComponent keyCtrl = Lang.translateDirect("tooltip.keyCtrl"); + for (List list : Arrays.asList(lines, linesOnShift, linesOnCtrl)) { + boolean shift = list == linesOnShift; + boolean ctrl = list == linesOnCtrl; + + if (holdDesc.length != 2 || holdCtrl.length != 2) { + list.add(0, Components.literal("Invalid lang formatting!")); + continue; + } + + if (hasControls) { + MutableComponent tabBuilder = Components.empty(); + tabBuilder.append(Components.literal(holdCtrl[0]).withStyle(DARK_GRAY)); + tabBuilder.append(keyCtrl.plainCopy() + .withStyle(ctrl ? WHITE : GRAY)); + tabBuilder.append(Components.literal(holdCtrl[1]).withStyle(DARK_GRAY)); + list.add(0, tabBuilder); + } + + if (hasDescription) { + MutableComponent tabBuilder = Components.empty(); + tabBuilder.append(Components.literal(holdDesc[0]).withStyle(DARK_GRAY)); + tabBuilder.append(keyShift.plainCopy() + .withStyle(shift ? WHITE : GRAY)); + tabBuilder.append(Components.literal(holdDesc[1]).withStyle(DARK_GRAY)); + list.add(0, tabBuilder); + } + + if (shift || ctrl) + list.add(hasDescription && hasControls ? 2 : 1, Components.immutableEmpty()); + } + } + + if (!hasDescription) { + linesOnCtrl.clear(); + linesOnShift.addAll(lines); + } + if (!hasControls) { + linesOnCtrl.clear(); + linesOnCtrl.addAll(lines); + } + + return new ItemDescription(ImmutableList.copyOf(lines), ImmutableList.copyOf(linesOnShift), ImmutableList.copyOf(linesOnCtrl)); + } + } } diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemTooltipHandler.java b/src/main/java/com/simibubi/create/foundation/item/ItemTooltipHandler.java new file mode 100644 index 000000000..d54f882c6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/item/ItemTooltipHandler.java @@ -0,0 +1,206 @@ +package com.simibubi.create.foundation.item; + +import static net.minecraft.ChatFormatting.DARK_GRAY; +import static net.minecraft.ChatFormatting.GRAY; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; + +import org.jetbrains.annotations.Nullable; + +import com.mojang.bridge.game.Language; +import com.simibubi.create.Create; +import com.simibubi.create.content.contraptions.base.IRotate; +import com.simibubi.create.content.contraptions.base.IRotate.StressImpact; +import com.simibubi.create.content.contraptions.components.steam.SteamEngineBlock; +import com.simibubi.create.content.contraptions.goggles.GogglesItem; +import com.simibubi.create.foundation.block.BlockStressValues; +import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.config.CKinetics; +import com.simibubi.create.foundation.utility.Components; +import com.simibubi.create.foundation.utility.Couple; +import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.LangBuilder; + +import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.Block; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; + +public class ItemTooltipHandler { + private static final String ITEM_PREFIX = "item." + Create.ID; + private static final String BLOCK_PREFIX = "block." + Create.ID; + + private static final Map> TOOLTIP_REFERRALS = new IdentityHashMap<>(); + private static final Map TOOLTIP_CACHE = new HashMap<>(); + private static Language cachedLanguage; + + public static void referTo(ItemLike item, Function func) { + TOOLTIP_REFERRALS.put(item.asItem(), func); + } + + public static void referTo(ItemLike item, Supplier itemWithTooltip) { + referTo(item, stack -> itemWithTooltip.get() + .asItem() + .getDescriptionId()); + } + + public static void referTo(ItemLike item, String string) { + referTo(item, stack -> string); + } + + public static void addToTooltip(ItemTooltipEvent event) { + ItemStack stack = event.getItemStack(); + List tooltip = event.getToolTip(); + + String translationKey = stack.getDescriptionId(); + if (translationKey.startsWith(ITEM_PREFIX) || translationKey.startsWith(BLOCK_PREFIX)) { + ItemDescription desc = getOrCreateTooltip(stack); + if (desc != null) { + List descTooltip = new ArrayList<>(); + desc.addInformation(descTooltip); + tooltip.addAll(1, descTooltip); + } + } + + if (stack.getItem() instanceof BlockItem blockItem) { + Block block = blockItem.getBlock(); + if (block instanceof IRotate || block instanceof SteamEngineBlock) { + List kineticStats = getKineticStats(block, event.getPlayer()); + if (!kineticStats.isEmpty()) { + tooltip.add(Components.immutableEmpty()); + tooltip.addAll(kineticStats); + } + } + } + } + + private static void checkLocale() { + Language currentLanguage = Minecraft.getInstance() + .getLanguageManager() + .getSelected(); + if (cachedLanguage != currentLanguage) { + cachedLanguage = currentLanguage; + TOOLTIP_CACHE.clear(); + } + } + + public static String getTooltipTranslationKey(ItemStack stack) { + Item item = stack.getItem(); + if (TOOLTIP_REFERRALS.containsKey(item)) { + return TOOLTIP_REFERRALS.get(item) + .apply(stack) + ".tooltip"; + } + return stack.getDescriptionId() + ".tooltip"; + } + + @Nullable + public static ItemDescription getOrCreateTooltip(ItemStack stack) { + checkLocale(); + + String key = getTooltipTranslationKey(stack); + ItemDescription desc = TOOLTIP_CACHE.get(key); + + if (desc == null) { + // TODO 0.5.1: Decide on colors and defer creation to registered factory/type based on key or item + desc = ItemDescription.create(ItemDescription.Palette.GRAY, key); + TOOLTIP_CACHE.put(key, desc); + } + + if (desc == ItemDescription.MISSING) { + return null; + } + + return desc; + } + + public static List getKineticStats(Block block, Player player) { + List list = new ArrayList<>(); + + CKinetics config = AllConfigs.SERVER.kinetics; + LangBuilder rpmUnit = Lang.translate("generic.unit.rpm"); + LangBuilder suUnit = Lang.translate("generic.unit.stress"); + + boolean hasGoggles = GogglesItem.isWearingGoggles(player); + + boolean showStressImpact; + if (block instanceof IRotate) { + showStressImpact = !((IRotate) block).hideStressImpact(); + } else { + showStressImpact = true; + } + + boolean hasStressImpact = + StressImpact.isEnabled() && showStressImpact && BlockStressValues.getImpact(block) > 0; + boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.hasCapacity(block); + + if (hasStressImpact) { + Lang.translate("tooltip.stressImpact") + .style(GRAY) + .addTo(list); + + double impact = BlockStressValues.getImpact(block); + StressImpact impactId = impact >= config.highStressImpact.get() ? StressImpact.HIGH + : (impact >= config.mediumStressImpact.get() ? StressImpact.MEDIUM : StressImpact.LOW); + LangBuilder builder = Lang.builder() + .add(Lang.text(TooltipHelper.makeProgressBar(3, impactId.ordinal() + 1)) + .style(impactId.getAbsoluteColor())); + + if (hasGoggles) { + builder.add(Lang.number(impact)) + .text("x ") + .add(rpmUnit) + .addTo(list); + } else + builder.translate("tooltip.stressImpact." + Lang.asId(impactId.name())) + .addTo(list); + } + + if (hasStressCapacity) { + Lang.translate("tooltip.capacityProvided") + .style(GRAY) + .addTo(list); + + double capacity = BlockStressValues.getCapacity(block); + Couple generatedRPM = BlockStressValues.getGeneratedRPM(block); + + StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.HIGH + : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.LOW); + StressImpact opposite = StressImpact.values()[StressImpact.values().length - 2 - impactId.ordinal()]; + LangBuilder builder = Lang.builder() + .add(Lang.text(TooltipHelper.makeProgressBar(3, impactId.ordinal() + 1)) + .style(opposite.getAbsoluteColor())); + + if (hasGoggles) { + builder.add(Lang.number(capacity)) + .text("x ") + .add(rpmUnit) + .addTo(list); + + if (generatedRPM != null) { + LangBuilder amount = Lang.number(capacity * generatedRPM.getSecond()) + .add(suUnit); + Lang.text(" -> ") + .add(!generatedRPM.getFirst() + .equals(generatedRPM.getSecond()) ? Lang.translate("tooltip.up_to", amount) : amount) + .style(DARK_GRAY) + .addTo(list); + } + } else + builder.translate("tooltip.capacityProvided." + Lang.asId(impactId.name())) + .addTo(list); + } + + return list; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java index ad5fdf92a..54e8b9356 100644 --- a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java @@ -2,16 +2,10 @@ package com.simibubi.create.foundation.item; import java.text.BreakIterator; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; -import java.util.function.Supplier; import com.google.common.base.Strings; -import com.mojang.bridge.game.Language; -import com.simibubi.create.content.AllSections; -import com.simibubi.create.content.contraptions.goggles.GogglesItem; import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; import com.simibubi.create.foundation.item.ItemDescription.Palette; import com.simibubi.create.foundation.utility.Components; @@ -22,22 +16,13 @@ import com.simibubi.create.foundation.utility.Lang; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; import net.minecraftforge.client.MinecraftForgeClient; public class TooltipHelper { - public static final int maxWidthPerLine = 200; - public static final Map cachedTooltips = new HashMap<>(); - public static Language cachedLanguage; - private static boolean gogglesMode; - private static final Map> tooltipReferrals = new HashMap<>(); + public static final int MAX_WIDTH_PER_LINE = 200; public static MutableComponent holdShift(Palette color, boolean highlighted) { return Lang.translateDirect("tooltip.holdForDescription", Lang.translateDirect("tooltip.keyShift") @@ -57,14 +42,14 @@ public class TooltipHelper { .append(component)); } - public static void referTo(ItemLike item, Supplier itemWithTooltip) { - tooltipReferrals.put(item.asItem(), () -> itemWithTooltip.get() - .asItem() - .getDescriptionId()); - } - - public static void referTo(ItemLike item, String string) { - tooltipReferrals.put(item.asItem(), () -> string); + public static String makeProgressBar(int length, int filledLength) { + String bar = " "; + int emptySpaces = length - filledLength; + for (int i = 0; i < filledLength; i++) + bar += "\u2588"; + for (int i = 0; i < emptySpaces; i++) + bar += "\u2592"; + return bar + " "; } @Deprecated @@ -89,7 +74,7 @@ public class TooltipHelper { } Font font = Minecraft.getInstance().font; - List lines = FontHelper.cutString(font, markedUp, maxWidthPerLine); + List lines = FontHelper.cutString(font, markedUp, MAX_WIDTH_PER_LINE); // Format String lineStart = Strings.repeat(" ", indent); @@ -142,7 +127,7 @@ public class TooltipHelper { int width = 0; for (String word : words) { int newWidth = font.width(word.replaceAll("_", "")); - if (width + newWidth > maxWidthPerLine) { + if (width + newWidth > MAX_WIDTH_PER_LINE) { if (width > 0) { String line = currentLine.toString(); lines.add(line); @@ -221,102 +206,6 @@ public class TooltipHelper { // return lines; // } - private static void checkLocale() { - Language currentLanguage = Minecraft.getInstance() - .getLanguageManager() - .getSelected(); - if (cachedLanguage != currentLanguage) { - cachedTooltips.clear(); - cachedLanguage = currentLanguage; - } - } - - public static boolean hasTooltip(ItemStack stack, Player player) { - checkLocale(); - - boolean hasGoggles = GogglesItem.isWearingGoggles(player); - - if (hasGoggles != gogglesMode) { - gogglesMode = hasGoggles; - cachedTooltips.clear(); - } - - String key = getTooltipTranslationKey(stack); - if (cachedTooltips.containsKey(key)) - return cachedTooltips.get(key) != ItemDescription.MISSING; - return findTooltip(stack); - } - - public static ItemDescription getTooltip(ItemStack stack) { - checkLocale(); - String key = getTooltipTranslationKey(stack); - if (cachedTooltips.containsKey(key)) { - ItemDescription itemDescription = cachedTooltips.get(key); - if (itemDescription != ItemDescription.MISSING) - return itemDescription; - } - return null; - } - - private static boolean findTooltip(ItemStack stack) { - String key = getTooltipTranslationKey(stack); - if (I18n.exists(key)) { - cachedTooltips.put(key, buildToolTip(key, stack)); - return true; - } - cachedTooltips.put(key, ItemDescription.MISSING); - return false; - } - - private static ItemDescription buildToolTip(String translationKey, ItemStack stack) { - AllSections module = AllSections.of(stack); - ItemDescription tooltip = new ItemDescription(module.getTooltipPalette()); - String summaryKey = translationKey + ".summary"; - - // Summary - if (I18n.exists(summaryKey)) - tooltip = tooltip.withSummary(Components.literal(I18n.get(summaryKey))); - - // Requirements -// if (stack.getItem() instanceof BlockItem) { -// BlockItem item = (BlockItem) stack.getItem(); -// if (item.getBlock() instanceof IRotate || item.getBlock() instanceof EngineBlock) { -// tooltip = tooltip.withKineticStats(item.getBlock()); -// } -// } - - // Behaviours - for (int i = 1; i < 100; i++) { - String conditionKey = translationKey + ".condition" + i; - String behaviourKey = translationKey + ".behaviour" + i; - if (!I18n.exists(conditionKey)) - break; - if (i == 1) - tooltip.getLinesOnShift() - .add(Components.immutableEmpty()); - tooltip.withBehaviour(I18n.get(conditionKey), I18n.get(behaviourKey)); - } - - // Controls - for (int i = 1; i < 100; i++) { - String controlKey = translationKey + ".control" + i; - String actionKey = translationKey + ".action" + i; - if (!I18n.exists(controlKey)) - break; - tooltip.withControl(I18n.get(controlKey), I18n.get(actionKey)); - } - - return tooltip.createTabs(); - } - - public static String getTooltipTranslationKey(ItemStack stack) { - Item item = stack.getItem(); - if (tooltipReferrals.containsKey(item)) - return tooltipReferrals.get(item) - .get() + ".tooltip"; - return item.getDescriptionId(stack) + ".tooltip"; - } - // private static int getComponentLength(ITextComponent component) { // AtomicInteger l = new AtomicInteger(); // TextProcessing.visitFormatted(component, Style.EMPTY, (s, style, charConsumer) -> { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/accessor/NbtAccounterAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/accessor/NbtAccounterAccessor.java index c466f13fa..5174ff635 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/accessor/NbtAccounterAccessor.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/accessor/NbtAccounterAccessor.java @@ -1,10 +1,10 @@ package com.simibubi.create.foundation.mixin.accessor; -import net.minecraft.nbt.NbtAccounter; - import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import net.minecraft.nbt.NbtAccounter; + @Mixin(NbtAccounter.class) public interface NbtAccounterAccessor { @Accessor("usage") diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java index 90f5ce8fe..c2401c8c3 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java @@ -22,6 +22,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.item.ItemStack; import net.minecraftforge.client.event.RenderTooltipEvent; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class PonderTooltipHandler { @@ -73,10 +74,12 @@ public class PonderTooltipHandler { hoveredStack = ItemStack.EMPTY; } - public static void addToTooltip(List toolTip, ItemStack stack) { + public static void addToTooltip(ItemTooltipEvent event) { if (!enable) return; + ItemStack stack = event.getItemStack(); + updateHovered(stack); if (deferTick) @@ -90,10 +93,11 @@ public class PonderTooltipHandler { Component component = subject ? Lang.translateDirect(SUBJECT) .withStyle(ChatFormatting.GREEN) : makeProgressBar(Math.min(1, holdWProgress.getValue(renderPartialTicks) * 8 / 7f)); - if (toolTip.size() < 2) - toolTip.add(component); + List tooltip = event.getToolTip(); + if (tooltip.size() < 2) + tooltip.add(component); else - toolTip.add(1, component); + tooltip.add(1, component); } protected static void updateHovered(ItemStack stack) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/CreateRegistry.java b/src/main/java/com/simibubi/create/foundation/utility/AttachedRegistry.java similarity index 82% rename from src/main/java/com/simibubi/create/foundation/utility/CreateRegistry.java rename to src/main/java/com/simibubi/create/foundation/utility/AttachedRegistry.java index 6e1e92d5e..193a6155e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/CreateRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AttachedRegistry.java @@ -14,15 +14,15 @@ import net.minecraft.resources.ResourceLocation; import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistryEntry; -public class CreateRegistry, V> { - private static final List> ALL = new ArrayList<>(); +public class AttachedRegistry, V> { + private static final List> ALL = new ArrayList<>(); protected final IForgeRegistry objectRegistry; protected final Map locationMap = new HashMap<>(); protected final Map objectMap = new IdentityHashMap<>(); protected boolean unwrapped = false; - public CreateRegistry(IForgeRegistry objectRegistry) { + public AttachedRegistry(IForgeRegistry objectRegistry) { this.objectRegistry = objectRegistry; ALL.add(this); } @@ -35,7 +35,7 @@ public class CreateRegistry, V> { if (object != null) { objectMap.put(object, value); } else { - Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry after unwrapping!"); + Create.LOGGER.warn("Could not get object for location '" + location + "' in AttachedRegistry after unwrapping!"); } } } @@ -48,7 +48,7 @@ public class CreateRegistry, V> { if (location != null) { locationMap.put(location, value); } else { - Create.LOGGER.warn("Could not get location of object '" + object + "' in CreateRegistry before unwrapping!"); + Create.LOGGER.warn("Could not get location of object '" + object + "' in AttachedRegistry before unwrapping!"); } } } @@ -62,7 +62,7 @@ public class CreateRegistry, V> { if (object != null) { return objectMap.get(object); } else { - Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry after unwrapping!"); + Create.LOGGER.warn("Could not get object for location '" + location + "' in AttachedRegistry after unwrapping!"); return null; } } @@ -77,7 +77,7 @@ public class CreateRegistry, V> { if (location != null) { return locationMap.get(location); } else { - Create.LOGGER.warn("Could not get location of object '" + object + "' in CreateRegistry before unwrapping!"); + Create.LOGGER.warn("Could not get location of object '" + object + "' in AttachedRegistry before unwrapping!"); return null; } } @@ -94,14 +94,14 @@ public class CreateRegistry, V> { if (object != null) { objectMap.put(object, entry.getValue()); } else { - Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry during unwrapping!"); + Create.LOGGER.warn("Could not get object for location '" + location + "' in AttachedRegistry during unwrapping!"); } } unwrapped = true; } public static void unwrapAll() { - for (CreateRegistry registry : ALL) { + for (AttachedRegistry registry : ALL) { registry.unwrap(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/ContraptionData.java b/src/main/java/com/simibubi/create/foundation/utility/ContraptionData.java index 66426bca9..083cb4eae 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/ContraptionData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/ContraptionData.java @@ -9,7 +9,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtAccounter; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; -import net.minecraftforge.fml.ModList; public class ContraptionData { /**