From 736d0a1edd3bf454b611812cc1d6a5d0db5809ab Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Mon, 5 Aug 2024 05:42:28 +0200 Subject: [PATCH 1/6] started porting --- README.md | 4 +- build.gradle | 34 ++--- build.properties | 11 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 10 ++ .../java/vazkii/akashictome/AkashicTome.java | 29 ++-- .../vazkii/akashictome/AttachementRecipe.java | 20 +-- .../vazkii/akashictome/ConfigHandler.java | 1 + .../java/vazkii/akashictome/ModItems.java | 28 ---- .../vazkii/akashictome/MorphingHandler.java | 22 +-- .../java/vazkii/akashictome/NBTUtils.java | 30 ++++ .../java/vazkii/akashictome/Registries.java | 18 +++ .../java/vazkii/akashictome/TomeItem.java | 22 ++- .../vazkii/akashictome/client/HUDHandler.java | 20 +-- .../vazkii/akashictome/client/TomeScreen.java | 134 ++++++++++-------- .../akashictome/network/MessageMorphTome.java | 32 +++-- .../network/MessageUnmorphTome.java | 24 ++-- .../akashictome/network/NetworkHandler.java | 27 ++++ src/main/resources/META-INF/mods.toml | 16 +-- .../assets/akashictome/models/item/tome.json | 4 +- .../textures/{items => item}/tome.png | Bin 21 files changed, 271 insertions(+), 217 deletions(-) create mode 100644 settings.gradle delete mode 100644 src/main/java/vazkii/akashictome/ModItems.java create mode 100644 src/main/java/vazkii/akashictome/NBTUtils.java create mode 100644 src/main/java/vazkii/akashictome/Registries.java create mode 100644 src/main/java/vazkii/akashictome/network/NetworkHandler.java rename src/main/resources/assets/akashictome/textures/{items => item}/tome.png (100%) diff --git a/README.md b/README.md index be6a1bb..b4c30e6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,2 @@ # AkashicTome -The book of books. - -This mod requires [AutoRegLib](https://github.com/Vazkii/AutoRegLib). \ No newline at end of file +The book of books. \ No newline at end of file diff --git a/build.gradle b/build.gradle index ac1db7a..b46662f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,12 @@ -buildscript { - repositories { - maven { url = 'https://maven.minecraftforge.net' } - maven { url = 'https://repo.spongepowered.org/maven' } - jcenter() - mavenCentral() - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true - } -} plugins { + id 'eclipse' + id 'maven-publish' + id 'pmd' id 'com.diffplug.spotless' version '5.12.5' + id 'net.minecraftforge.gradle' version '5.1.+' + id 'org.parchmentmc.librarian.forgegradle' version '1.+' + id 'org.spongepowered.mixin' version '0.7.+' } -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'eclipse' -apply plugin: 'maven-publish' -apply plugin: 'pmd' ext.configFile = file('build.properties') ext.config = parseConfig(configFile) @@ -55,7 +46,7 @@ minecraft { property 'forge.logging.console.level', 'debug' mods { - examplemod { + akashictome { source sourceSets.main } } @@ -71,7 +62,7 @@ minecraft { property 'forge.logging.console.level', 'debug' mods { - examplemod { + akashictome { source sourceSets.main } } @@ -81,16 +72,15 @@ minecraft { repositories { maven { - // for AutoRegLib - name "blamejared" - url "https://maven.blamejared.com/" + url "https://cursemaven.com" } } dependencies { minecraft "net.minecraftforge:forge:${config.mc_version}-${config.forge_version}" - - implementation fg.deobf("vazkii.autoreglib:AutoRegLib:${config.arl_version}") + implementation fg.deobf("curse.maven:curios-309927:5367944") + implementation fg.deobf("curse.maven:patchouli-306770:4966125") + implementation fg.deobf("curse.maven:botania-225643:5594997") } spotless { diff --git a/build.properties b/build.properties index a1461c5..5f1e89a 100644 --- a/build.properties +++ b/build.properties @@ -1,12 +1,11 @@ #Fri Feb 02 19:58:59 UTC 2024 -mapping_channel=official -forge_version=43.1.52 +mapping_channel=parchment +forge_version=47.2.0 mod_id=akashictome dir_repo=./ build_number=25 -arl_version=1.8.2-56.125 dir_output=../Build Output/AkashicTome/ -mapping_version=1.19.2 -version=1.6 +mapping_version=2023.09.03-1.20.1 +version=1.7 mod_name=AkashicTome -mc_version=1.19.2 +mc_version=1.20.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cc125a5..3c472b9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..bba4331 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + gradlePluginPortal() + jcenter() + mavenCentral() + maven { url = 'https://maven.minecraftforge.net/' } + maven { url = 'https://maven.parchmentmc.org' } + maven { url = "https://repo.spongepowered.org/repository/maven-public/" } + } +} \ No newline at end of file diff --git a/src/main/java/vazkii/akashictome/AkashicTome.java b/src/main/java/vazkii/akashictome/AkashicTome.java index 55fe628..382cd7d 100644 --- a/src/main/java/vazkii/akashictome/AkashicTome.java +++ b/src/main/java/vazkii/akashictome/AkashicTome.java @@ -1,5 +1,7 @@ package vazkii.akashictome; +import net.minecraft.world.item.CreativeModeTabs; +import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.ModLoadingContext; @@ -7,42 +9,37 @@ import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.network.NetworkDirection; - -import vazkii.akashictome.network.MessageMorphTome; -import vazkii.akashictome.network.MessageUnmorphTome; +import vazkii.akashictome.network.NetworkHandler; import vazkii.akashictome.proxy.ClientProxy; import vazkii.akashictome.proxy.CommonProxy; -import vazkii.arl.network.IMessage; -import vazkii.arl.network.NetworkHandler; @Mod(AkashicTome.MOD_ID) public class AkashicTome { public static final String MOD_ID = "akashictome"; - public static NetworkHandler NETWORKHANDLER; public static CommonProxy proxy; public AkashicTome() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::commonSetup); - bus.register(ModItems.class); + Registries.ITEMS.register(bus); + Registries.SERIALIZERS.register(bus); + + bus.addListener(this::addToCreativeTab); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigHandler.CONFIG_SPEC); - proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new); + proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new); proxy.preInit(); - - NETWORKHANDLER = new NetworkHandler(MOD_ID, 1); } public void commonSetup(FMLCommonSetupEvent event) { - NETWORKHANDLER.register(MessageMorphTome.class, NetworkDirection.PLAY_TO_SERVER); - NETWORKHANDLER.register(MessageUnmorphTome.class, NetworkDirection.PLAY_TO_SERVER); + NetworkHandler.register(); } - public static void sendToServer(IMessage msg) { - NETWORKHANDLER.sendToServer(msg); + private void addToCreativeTab(BuildCreativeModeTabContentsEvent event) { + if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) { + event.accept(Registries.TOME); + } } - } diff --git a/src/main/java/vazkii/akashictome/AttachementRecipe.java b/src/main/java/vazkii/akashictome/AttachementRecipe.java index cb6e5fa..341ce35 100644 --- a/src/main/java/vazkii/akashictome/AttachementRecipe.java +++ b/src/main/java/vazkii/akashictome/AttachementRecipe.java @@ -1,21 +1,21 @@ package vazkii.akashictome; import net.minecraft.core.NonNullList; +import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingBookCategory; import net.minecraft.world.item.crafting.CustomRecipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.Level; import net.minecraftforge.registries.ForgeRegistries; -import vazkii.arl.util.ItemNBTHelper; - public class AttachementRecipe extends CustomRecipe { - public AttachementRecipe(ResourceLocation idIn) { - super(idIn); + public AttachementRecipe(ResourceLocation idIn, CraftingBookCategory pCategory) { + super(idIn, pCategory); } @Override @@ -30,7 +30,7 @@ public boolean matches(CraftingContainer var1, Level var2) { if (foundTarget) return false; foundTarget = true; - } else if (stack.getItem() == ModItems.tome) { + } else if (stack.is(Registries.TOME.get())) { if (foundTool) return false; foundTool = true; @@ -43,14 +43,14 @@ public boolean matches(CraftingContainer var1, Level var2) { } @Override - public ItemStack assemble(CraftingContainer var1) { + public ItemStack assemble(CraftingContainer var1, RegistryAccess pRegistryAccess) { ItemStack tool = ItemStack.EMPTY; ItemStack target = ItemStack.EMPTY; for (int i = 0; i < var1.getContainerSize(); i++) { ItemStack stack = var1.getItem(i); if (!stack.isEmpty()) { - if (stack.getItem() == ModItems.tome) + if (stack.is(Registries.TOME.get())) tool = stack; else target = stack; @@ -80,7 +80,7 @@ public ItemStack assemble(CraftingContainer var1) { CompoundTag modCmp = new CompoundTag(); if (tries > 0) - ItemNBTHelper.setString(target, MorphingHandler.TAG_ITEM_DEFINED_MOD, mod); + NBTUtils.setString(target, MorphingHandler.TAG_ITEM_DEFINED_MOD, mod); target.save(modCmp); morphData.put(mod, modCmp); @@ -125,7 +125,7 @@ public boolean isTarget(ItemStack stack) { } @Override - public ItemStack getResultItem() { + public ItemStack getResultItem(RegistryAccess pRegistryAccess) { return ItemStack.EMPTY; } @@ -136,7 +136,7 @@ public NonNullList getRemainingItems(CraftingContainer inv) { @Override public RecipeSerializer getSerializer() { - return ModItems.ATTACHMENT; + return Registries.ATTACHMENT.get(); } } diff --git a/src/main/java/vazkii/akashictome/ConfigHandler.java b/src/main/java/vazkii/akashictome/ConfigHandler.java index 2239aea..3191312 100644 --- a/src/main/java/vazkii/akashictome/ConfigHandler.java +++ b/src/main/java/vazkii/akashictome/ConfigHandler.java @@ -30,6 +30,7 @@ public ConfigHandler(ForgeConfigSpec.Builder builder) { Predicate validator = o -> o instanceof String; + //TODO update this list whitelistedItems = builder.defineList("Whitelisted Items", Lists.newArrayList("roots:runedtablet", "opencomputers:tool:4", diff --git a/src/main/java/vazkii/akashictome/ModItems.java b/src/main/java/vazkii/akashictome/ModItems.java deleted file mode 100644 index c715ea9..0000000 --- a/src/main/java/vazkii/akashictome/ModItems.java +++ /dev/null @@ -1,28 +0,0 @@ -package vazkii.akashictome; - -import net.minecraft.core.Registry; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.crafting.RecipeSerializer; -import net.minecraft.world.item.crafting.SimpleRecipeSerializer; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.registries.RegisterEvent; - -import vazkii.arl.util.RegistryHelper; - -public final class ModItems { - - public static final RecipeSerializer ATTACHMENT = new SimpleRecipeSerializer<>(AttachementRecipe::new); - - public static Item tome; - - @SubscribeEvent(priority = EventPriority.HIGHEST) - public static void onRegistryInit(RegisterEvent event) { - if (tome == null) { - tome = new TomeItem(); - - RegistryHelper.register(ATTACHMENT, AkashicTome.MOD_ID + ":attachment", Registry.RECIPE_SERIALIZER_REGISTRY); - } - } - -} diff --git a/src/main/java/vazkii/akashictome/MorphingHandler.java b/src/main/java/vazkii/akashictome/MorphingHandler.java index 143d3c8..d457c55 100644 --- a/src/main/java/vazkii/akashictome/MorphingHandler.java +++ b/src/main/java/vazkii/akashictome/MorphingHandler.java @@ -16,7 +16,7 @@ import net.minecraftforge.registries.ForgeRegistries; import vazkii.akashictome.network.MessageUnmorphTome; -import vazkii.arl.util.ItemNBTHelper; +import vazkii.akashictome.network.NetworkHandler; import java.util.HashMap; import java.util.Locale; @@ -36,8 +36,8 @@ public final class MorphingHandler { @SubscribeEvent public void onPlayerLeftClick(PlayerInteractEvent.LeftClickEmpty event) { ItemStack stack = event.getItemStack(); - if (!stack.isEmpty() && isAkashicTome(stack) && stack.getItem() != ModItems.tome) { - AkashicTome.sendToServer(new MessageUnmorphTome()); + if (!stack.isEmpty() && isAkashicTome(stack) && !stack.is(Registries.TOME.get())) { + NetworkHandler.sendToServer(new MessageUnmorphTome()); } } @@ -48,9 +48,9 @@ public void onItemDropped(ItemTossEvent event) { ItemEntity e = event.getEntity(); ItemStack stack = e.getItem(); - if (!stack.isEmpty() && isAkashicTome(stack) && stack.getItem() != ModItems.tome) { + if (!stack.isEmpty() && isAkashicTome(stack) && !stack.is(Registries.TOME.get())) { CompoundTag morphData = stack.getTag().getCompound(TAG_TOME_DATA).copy(); - String currentMod = ItemNBTHelper.getString(stack, TAG_ITEM_DEFINED_MOD, getModFromStack(stack)); + String currentMod = NBTUtils.getString(stack, TAG_ITEM_DEFINED_MOD, getModFromStack(stack)); ItemStack morph = makeMorphedStack(stack, MINECRAFT, morphData); CompoundTag newMorphData = morph.getTag().getCompound(TAG_TOME_DATA); @@ -117,7 +117,7 @@ public static ItemStack getShiftStackForMod(ItemStack stack, String mod) { return stack; String currentMod = getModFromStack(stack); - String defined = ItemNBTHelper.getString(stack, TAG_ITEM_DEFINED_MOD, ""); + String defined = NBTUtils.getString(stack, TAG_ITEM_DEFINED_MOD, ""); if (!defined.isEmpty()) currentMod = defined; @@ -130,7 +130,7 @@ public static ItemStack getShiftStackForMod(ItemStack stack, String mod) { public static ItemStack makeMorphedStack(ItemStack currentStack, String targetMod, CompoundTag morphData) { String currentMod = getModFromStack(currentStack); - String defined = ItemNBTHelper.getString(currentStack, TAG_ITEM_DEFINED_MOD, ""); + String defined = NBTUtils.getString(currentStack, TAG_ITEM_DEFINED_MOD, ""); if (!defined.isEmpty()) currentMod = defined; @@ -145,14 +145,14 @@ public static ItemStack makeMorphedStack(ItemStack currentStack, String targetMo ItemStack stack; if (targetMod.equals(MINECRAFT)) - stack = new ItemStack(ModItems.tome); + stack = new ItemStack(Registries.TOME.get()); else { CompoundTag targetCmp = morphData.getCompound(targetMod); morphData.remove(targetMod); stack = ItemStack.of(targetCmp); if (stack.isEmpty()) - stack = new ItemStack(ModItems.tome); + stack = new ItemStack(Registries.TOME.get()); } if (!stack.hasTag()) @@ -162,7 +162,7 @@ public static ItemStack makeMorphedStack(ItemStack currentStack, String targetMo stackCmp.put(TAG_TOME_DATA, morphData); stackCmp.putBoolean(TAG_MORPHING, true); - if (stack.getItem() != ModItems.tome) { + if (!stack.is(Registries.TOME.get())) { CompoundTag displayName = new CompoundTag(); CompoundTag ogDisplayName = displayName; displayName.putString("text", Component.Serializer.toJson(stack.getHoverName())); @@ -203,7 +203,7 @@ public static boolean isAkashicTome(ItemStack stack) { if (stack.isEmpty()) return false; - if (stack.getItem() == ModItems.tome) + if (stack.is(Registries.TOME.get())) return true; return stack.hasTag() && stack.getTag().getBoolean(TAG_MORPHING); diff --git a/src/main/java/vazkii/akashictome/NBTUtils.java b/src/main/java/vazkii/akashictome/NBTUtils.java new file mode 100644 index 0000000..ef91789 --- /dev/null +++ b/src/main/java/vazkii/akashictome/NBTUtils.java @@ -0,0 +1,30 @@ +package vazkii.akashictome; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.ItemStack; + +//Some Nbt Utils ported from ARL which doesn't exist anymore +public class NBTUtils { + public static CompoundTag getNBT(ItemStack stack) { + if(!stack.hasTag()) { + stack.setTag(new CompoundTag()); + } + return stack.getTag(); + } + + public static boolean verifyExistence(ItemStack stack, String tag) { + return !stack.isEmpty() && stack.hasTag() && getNBT(stack).contains(tag); + } + + public static String getString(ItemStack stack, String tag, String defaultExpected) { + return verifyExistence(stack, tag) ? getNBT(stack).getString(tag) : defaultExpected; + } + + public static void setString(ItemStack stack, String tag, String s) { + getNBT(stack).putString(tag, s); + } + + public static CompoundTag getCompound(ItemStack stack, String tag, boolean nullifyOnFail) { + return verifyExistence(stack, tag) ? getNBT(stack).getCompound(tag) : nullifyOnFail ? null : new CompoundTag(); + } +} diff --git a/src/main/java/vazkii/akashictome/Registries.java b/src/main/java/vazkii/akashictome/Registries.java new file mode 100644 index 0000000..08dc8ce --- /dev/null +++ b/src/main/java/vazkii/akashictome/Registries.java @@ -0,0 +1,18 @@ +package vazkii.akashictome; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +public final class Registries { + public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AkashicTome.MOD_ID); + public static final DeferredRegister> SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, AkashicTome.MOD_ID); + + public static final RegistryObject TOME = ITEMS.register("tome", TomeItem::new); + + public static final RegistryObject> ATTACHMENT = SERIALIZERS.register("attachment", () -> new SimpleCraftingRecipeSerializer<>(AttachementRecipe::new)); + +} diff --git a/src/main/java/vazkii/akashictome/TomeItem.java b/src/main/java/vazkii/akashictome/TomeItem.java index f67e3e5..863111f 100644 --- a/src/main/java/vazkii/akashictome/TomeItem.java +++ b/src/main/java/vazkii/akashictome/TomeItem.java @@ -3,6 +3,7 @@ import com.google.common.collect.Lists; import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -12,25 +13,23 @@ import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; import net.minecraft.world.item.Item.Properties; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; -import vazkii.arl.item.BasicItem; -import vazkii.arl.util.TooltipHandler; - import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class TomeItem extends BasicItem { +public class TomeItem extends Item { public TomeItem() { - super("tome", new Properties().stacksTo(1).tab(CreativeModeTab.TAB_TOOLS)); + super(new Properties().stacksTo(1)/*TODO .tab(CreativeModeTab.TAB_TOOLS)*/); } @Override @@ -44,7 +43,7 @@ public InteractionResult useOn(UseOnContext context) { if (playerIn.isShiftKeyDown()) { String mod = MorphingHandler.getModFromState(worldIn.getBlockState(pos)); ItemStack newStack = MorphingHandler.getShiftStackForMod(stack, mod); - if (!ItemStack.isSame(newStack, stack)) { + if (!ItemStack.isSameItemSameTags(newStack, stack)) { //TODO test if sameTags as well playerIn.setItemInHand(hand, newStack); return InteractionResult.SUCCESS; } @@ -66,12 +65,10 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltipList = new ArrayList<>(); - - TooltipHandler.tooltipIfShift(tooltipList, () -> { + if (Screen.hasShiftDown()) { List keys = Lists.newArrayList(data.getAllKeys()); Collections.sort(keys); String currMod = ""; @@ -98,10 +95,9 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip.add(Component.literal(tip))); } } diff --git a/src/main/java/vazkii/akashictome/client/HUDHandler.java b/src/main/java/vazkii/akashictome/client/HUDHandler.java index ca98089..641ae34 100644 --- a/src/main/java/vazkii/akashictome/client/HUDHandler.java +++ b/src/main/java/vazkii/akashictome/client/HUDHandler.java @@ -5,6 +5,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.resources.language.I18n; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; @@ -15,9 +16,9 @@ import org.lwjgl.opengl.GL11; -import vazkii.akashictome.ModItems; import vazkii.akashictome.MorphingHandler; -import vazkii.arl.util.ItemNBTHelper; +import vazkii.akashictome.NBTUtils; +import vazkii.akashictome.Registries; public class HUDHandler { @@ -29,15 +30,16 @@ public void onDrawScreen(RenderGuiOverlayEvent.Post event) { Minecraft mc = Minecraft.getInstance(); HitResult pos = mc.hitResult; Window res = event.getWindow(); + GuiGraphics guiGraphics = event.getGuiGraphics(); if (pos != null && pos instanceof BlockHitResult) { BlockHitResult bpos = (BlockHitResult) pos; ItemStack tomeStack = mc.player.getMainHandItem(); - boolean hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome; + boolean hasTome = !tomeStack.isEmpty() && tomeStack.is(Registries.TOME.get()); if (!hasTome) { tomeStack = mc.player.getOffhandItem(); - hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome; + hasTome = !tomeStack.isEmpty() && tomeStack.is(Registries.TOME.get()); } if (!hasTome) @@ -54,9 +56,9 @@ public void onDrawScreen(RenderGuiOverlayEvent.Post event) { String mod = MorphingHandler.getModFromState(state); ItemStack morphStack = MorphingHandler.getShiftStackForMod(tomeStack, mod); - if (!morphStack.isEmpty() && !ItemStack.isSame(morphStack, tomeStack)) { + if (!morphStack.isEmpty() && !ItemStack.isSameItemSameTags(morphStack, tomeStack)) { //TODO test if same tags as well drawStack = morphStack; - line1 = ItemNBTHelper.getCompound(morphStack, MorphingHandler.TAG_TOME_DISPLAY_NAME, false).getString("text"); + line1 = NBTUtils.getCompound(morphStack, MorphingHandler.TAG_TOME_DISPLAY_NAME, false).getString("text"); line2 = ChatFormatting.GRAY + I18n.get("akashictome.click_morph"); } @@ -66,9 +68,9 @@ public void onDrawScreen(RenderGuiOverlayEvent.Post event) { int sx = res.getGuiScaledWidth() / 2 - 17; int sy = res.getGuiScaledHeight() / 2 + 2; - mc.getItemRenderer().renderGuiItem(drawStack, sx, sy); - mc.font.drawShadow(event.getPoseStack(), line1, sx + 20, sy + 4, 0xFFFFFFFF); - mc.font.drawShadow(event.getPoseStack(), line2, sx + 25, sy + 14, 0xFFFFFFFF); + guiGraphics.renderItem(drawStack, sx, sy); + guiGraphics.drawString(mc.font, line1, sx + 20, sy + 4, 0xFFFFFFFF); + guiGraphics.drawString(mc.font, line2, sx + 25, sy + 14, 0xFFFFFFFF); } } } diff --git a/src/main/java/vazkii/akashictome/client/TomeScreen.java b/src/main/java/vazkii/akashictome/client/TomeScreen.java index 43ef575..e772d70 100644 --- a/src/main/java/vazkii/akashictome/client/TomeScreen.java +++ b/src/main/java/vazkii/akashictome/client/TomeScreen.java @@ -7,11 +7,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexConsumer; -import com.mojang.math.Matrix4f; -import com.mojang.math.Vector3f; - import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.model.BookModel; import net.minecraft.client.model.geom.ModelLayers; @@ -23,11 +21,13 @@ import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; +import org.joml.Matrix4f; import vazkii.akashictome.AkashicTome; import vazkii.akashictome.ConfigHandler; import vazkii.akashictome.MorphingHandler; +import vazkii.akashictome.NBTUtils; import vazkii.akashictome.network.MessageMorphTome; -import vazkii.arl.util.ItemNBTHelper; +import vazkii.akashictome.network.NetworkHandler; import java.util.ArrayList; import java.util.Arrays; @@ -51,7 +51,7 @@ public TomeScreen(ItemStack tome) { @Override public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) { if (p_mouseClicked_5_ == 0 && this.definedMod != null) { - AkashicTome.sendToServer(new MessageMorphTome(this.definedMod)); + NetworkHandler.sendToServer(new MessageMorphTome(this.definedMod)); this.minecraft.setScreen(null); return true; } @@ -65,9 +65,10 @@ public boolean isPauseScreen() { } @Override - public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public void render(GuiGraphics pGuiGraphics, int mouseX, int mouseY, float partialTicks) { + PoseStack matrixStack = pGuiGraphics.pose(); this.definedMod = null; - super.render(matrixStack, mouseX, mouseY, partialTicks); + super.render(pGuiGraphics, mouseX, mouseY, partialTicks); List stacks = new ArrayList<>(); @@ -98,8 +99,8 @@ public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialT int padding = 4; int extra = 2; - fill(matrixStack, startX - padding, startY - padding, startX + iconSize * amountPerRow + padding, startY + iconSize * rows + padding, 0x22000000); - fill(matrixStack, startX - padding - extra, startY - padding - extra, startX + iconSize * amountPerRow + padding + extra, startY + iconSize * rows + padding + extra, 0x22000000); + pGuiGraphics.fill(startX - padding, startY - padding, startX + iconSize * amountPerRow + padding, startY + iconSize * rows + padding, 0x22000000); + pGuiGraphics.fill(startX - padding - extra, startY - padding - extra, startX + iconSize * amountPerRow + padding + extra, startY + iconSize * rows + padding + extra, 0x22000000); ItemStack tooltipStack = ItemStack.EMPTY; @@ -114,15 +115,16 @@ public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialT y -= 2; } - this.minecraft.getItemRenderer().renderAndDecorateItem(stack, x, y); + pGuiGraphics.renderItem(stack, x, y); //TODO render glint + //this.minecraft.getItemRenderer().renderAndDecorateItem(stack, x, y); } } if (!tooltipStack.isEmpty()) { - CompoundTag name = ItemNBTHelper.getCompound(tooltipStack, MorphingHandler.TAG_TOME_DISPLAY_NAME, false); + CompoundTag name = NBTUtils.getCompound(tooltipStack, MorphingHandler.TAG_TOME_DISPLAY_NAME, false); String tempDefinedMod = MorphingHandler.getModFromStack(tooltipStack); String mod = ChatFormatting.GRAY + MorphingHandler.getModNameForId(tempDefinedMod); - tempDefinedMod = ItemNBTHelper.getString(tooltipStack, MorphingHandler.TAG_ITEM_DEFINED_MOD, tempDefinedMod); + tempDefinedMod = NBTUtils.getString(tooltipStack, MorphingHandler.TAG_ITEM_DEFINED_MOD, tempDefinedMod); Component comp = Component.Serializer.fromJson(name.getString("text")); if (comp == null) @@ -130,67 +132,73 @@ public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialT List tooltipList = Arrays.asList(comp, Component.literal(mod)); - renderComponentTooltip(matrixStack, tooltipList, mouseX, mouseY, this.font); + pGuiGraphics.renderComponentTooltip(this.font, tooltipList, mouseX, mouseY); this.definedMod = tempDefinedMod; } if(!ConfigHandler.hideBookRender.get()) { - // [VanillaCopy] EnchantmentScreen, but locked in open position, at different location, and bigger - Lighting.setupForFlatItems(); - int guiScale = (int) this.minecraft.getWindow().getGuiScale(); - int viewportWidth = 320; - int viewportHeight = 240; - RenderSystem.viewport((this.width - viewportWidth) / 2 * guiScale, (this.height - viewportHeight) / 2 * guiScale, viewportWidth * guiScale, viewportHeight * guiScale); - Matrix4f projMat = Matrix4f.createTranslateMatrix(-0.34F, 0.23F, 0.0F); - projMat.multiply(Matrix4f.perspective(90.0D, 1.3333334F, 9.0F, 80.0F)); - RenderSystem.backupProjectionMatrix(); - RenderSystem.setProjectionMatrix(projMat); - matrixStack.pushPose(); - PoseStack.Pose pose = matrixStack.last(); - pose.pose().setIdentity(); - pose.normal().setIdentity(); - matrixStack.translate(6.3D, 3.3F, 1984.0D); // Akashic: Position at bottom of screen - float scale = 15.0F; // Akashic: bigger - matrixStack.scale(scale, scale, scale); - matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0F)); - matrixStack.mulPose(Vector3f.XP.rotationDegrees(20.0F)); - float f1 = 1.0F; // Akashic: lock in open position Mth.lerp(p_98763_, this.oOpen, this.open); - matrixStack.translate((1.0F - f1) * 0.2F, (1.0F - f1) * 0.1F, (1.0F - f1) * 0.25F); - float f2 = -(1.0F - f1) * 90.0F - 90.0F; - matrixStack.mulPose(Vector3f.YP.rotationDegrees(f2)); - matrixStack.mulPose(Vector3f.XP.rotationDegrees(180.0F)); - float f3 = 0.0F /* Akashic: no flip Mth.lerp(p_98763_, this.oFlip, this.flip) */ + 0.25F; - float f4 = 0.0F /* Akashic: no flip Mth.lerp(p_98763_, this.oFlip, this.flip) */ + 0.75F; - f3 = (f3 - (float) Mth.fastFloor(f3)) * 1.6F - 0.3F; - f4 = (f4 - (float) Mth.fastFloor(f4)) * 1.6F - 0.3F; - if (f3 < 0.0F) { - f3 = 0.0F; - } - - if (f4 < 0.0F) { - f4 = 0.0F; - } - if (f3 > 1.0F) { - f3 = 1.0F; - } - if (f4 > 1.0F) { - f4 = 1.0F; - } - BOOK_MODEL.setupAnim(0.0F, f3, f4, f1); - MultiBufferSource.BufferSource buffers = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()); - VertexConsumer buffer = buffers.getBuffer(BOOK_MODEL.renderType(BOOK_TEXTURE)); - BOOK_MODEL.renderToBuffer(matrixStack, buffer, 0xF000F0, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F); - buffers.endBatch(); - matrixStack.popPose(); - RenderSystem.viewport(0, 0, this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight()); - RenderSystem.restoreProjectionMatrix(); - Lighting.setupFor3DItems(); } RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } + public void renderBook(PoseStack matrixStack) { //TODO rewrite this for 1.20 + // [VanillaCopy] EnchantmentScreen, but locked in open position, at different location, and bigger + Lighting.setupForFlatItems(); + int guiScale = (int) this.minecraft.getWindow().getGuiScale(); + int viewportWidth = 320; + int viewportHeight = 240; + RenderSystem.viewport((this.width - viewportWidth) / 2 * guiScale, (this.height - viewportHeight) / 2 * guiScale, viewportWidth * guiScale, viewportHeight * guiScale); + //Matrix4f projMat = Matrix4f.createTranslateMatrix(-0.34F, 0.23F, 0.0F); + //projMat.multiply(Matrix4f.perspective(90.0D, 1.3333334F, 9.0F, 80.0F)); + RenderSystem.backupProjectionMatrix(); + //RenderSystem.setProjectionMatrix(projMat); + matrixStack.pushPose(); + PoseStack.Pose pose = matrixStack.last(); + //pose.pose().setIdentity(); + //pose.normal().setIdentity(); + matrixStack.translate(6.3D, 3.3F, 1984.0D); // Akashic: Position at bottom of screen + float scale = 15.0F; // Akashic: bigger + matrixStack.scale(scale, scale, scale); + //matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0F)); + //matrixStack.mulPose(Vector3f.XP.rotationDegrees(20.0F)); + float f1 = 1.0F; // Akashic: lock in open position Mth.lerp(p_98763_, this.oOpen, this.open); + matrixStack.translate((1.0F - f1) * 0.2F, (1.0F - f1) * 0.1F, (1.0F - f1) * 0.25F); + float f2 = -(1.0F - f1) * 90.0F - 90.0F; + //matrixStack.mulPose(Vector3f.YP.rotationDegrees(f2)); + //matrixStack.mulPose(Vector3f.XP.rotationDegrees(180.0F)); + float f3 = 0.0F /* Akashic: no flip Mth.lerp(p_98763_, this.oFlip, this.flip) */ + 0.25F; + float f4 = 0.0F /* Akashic: no flip Mth.lerp(p_98763_, this.oFlip, this.flip) */ + 0.75F; + //f3 = (f3 - (float) Mth.fastFloor(f3)) * 1.6F - 0.3F; + //f4 = (f4 - (float) Mth.fastFloor(f4)) * 1.6F - 0.3F; + if (f3 < 0.0F) { + f3 = 0.0F; + } + + if (f4 < 0.0F) { + f4 = 0.0F; + } + + if (f3 > 1.0F) { + f3 = 1.0F; + } + + if (f4 > 1.0F) { + f4 = 1.0F; + } + + BOOK_MODEL.setupAnim(0.0F, f3, f4, f1); + MultiBufferSource.BufferSource buffers = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()); + VertexConsumer buffer = buffers.getBuffer(BOOK_MODEL.renderType(BOOK_TEXTURE)); + //BOOK_MODEL.renderToBuffer(matrixStack, buffer, 0xF000F0, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F); + buffers.endBatch(); + //matrixStack.popPose(); + RenderSystem.viewport(0, 0, this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight()); + RenderSystem.restoreProjectionMatrix(); + Lighting.setupFor3DItems(); + } + } diff --git a/src/main/java/vazkii/akashictome/network/MessageMorphTome.java b/src/main/java/vazkii/akashictome/network/MessageMorphTome.java index 9391d11..2600ec5 100644 --- a/src/main/java/vazkii/akashictome/network/MessageMorphTome.java +++ b/src/main/java/vazkii/akashictome/network/MessageMorphTome.java @@ -1,17 +1,17 @@ package vazkii.akashictome.network; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.network.NetworkEvent; -import vazkii.akashictome.ModItems; import vazkii.akashictome.MorphingHandler; -import vazkii.arl.network.IMessage; +import vazkii.akashictome.Registries; -@SuppressWarnings("serial") -public class MessageMorphTome implements IMessage { +import java.util.function.Supplier; +public class MessageMorphTome { public String modid; public MessageMorphTome() {} @@ -20,29 +20,37 @@ public MessageMorphTome(String modid) { this.modid = modid; } - @Override - public boolean receive(NetworkEvent.Context context) { + public static void serialize(final MessageMorphTome msg, final FriendlyByteBuf buf) { + buf.writeUtf(msg.modid); + } + + public static MessageMorphTome deserialize(final FriendlyByteBuf buf) { + final MessageMorphTome msg = new MessageMorphTome(); + msg.modid = buf.readUtf(); + return msg; + } + + public static void handle(MessageMorphTome msg, Supplier ctx) { + NetworkEvent.Context context = ctx.get(); Player player = context.getSender(); if (player != null) { context.enqueueWork(() -> { ItemStack tomeStack = player.getMainHandItem(); InteractionHand hand = InteractionHand.MAIN_HAND; - boolean hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome; + boolean hasTome = !tomeStack.isEmpty() && tomeStack.is(Registries.TOME.get()); if (!hasTome) { tomeStack = player.getOffhandItem(); - hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome; + hasTome = !tomeStack.isEmpty() && tomeStack.is(Registries.TOME.get()); hand = InteractionHand.OFF_HAND; } if (hasTome) { - ItemStack newStack = MorphingHandler.getShiftStackForMod(tomeStack, modid); + ItemStack newStack = MorphingHandler.getShiftStackForMod(tomeStack, msg.modid); player.setItemInHand(hand, newStack); } }); } - - return true; + context.setPacketHandled(true); } - } diff --git a/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java b/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java index 42826c9..3262fa1 100644 --- a/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java +++ b/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java @@ -1,25 +1,32 @@ package vazkii.akashictome.network; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.network.NetworkEvent; import vazkii.akashictome.AkashicTome; -import vazkii.akashictome.ModItems; import vazkii.akashictome.MorphingHandler; -import vazkii.arl.network.IMessage; +import vazkii.akashictome.Registries; -@SuppressWarnings("serial") -public class MessageUnmorphTome implements IMessage { +import java.util.function.Supplier; + +public class MessageUnmorphTome { public MessageUnmorphTome() {} - @Override - public boolean receive(NetworkEvent.Context context) { + public static void serialize(final MessageUnmorphTome msg, final FriendlyByteBuf buf) {} + + public static MessageUnmorphTome deserialize(final FriendlyByteBuf buf) { + return new MessageUnmorphTome(); + } + + public static void handle(MessageUnmorphTome msg, Supplier ctx) { + NetworkEvent.Context context = ctx.get(); Player player = context.getSender(); if (player != null) { context.enqueueWork(() -> { ItemStack stack = player.getMainHandItem(); - if (!stack.isEmpty() && MorphingHandler.isAkashicTome(stack) && stack.getItem() != ModItems.tome) { + if (!stack.isEmpty() && MorphingHandler.isAkashicTome(stack) && stack.is(Registries.TOME.get())) { ItemStack newStack = MorphingHandler.getShiftStackForMod(stack, MorphingHandler.MINECRAFT); var inventory = player.getInventory(); inventory.setItem(inventory.selected, newStack); @@ -27,8 +34,7 @@ public boolean receive(NetworkEvent.Context context) { } }); } - - return true; + context.setPacketHandled(true); } } diff --git a/src/main/java/vazkii/akashictome/network/NetworkHandler.java b/src/main/java/vazkii/akashictome/network/NetworkHandler.java new file mode 100644 index 0000000..df6d101 --- /dev/null +++ b/src/main/java/vazkii/akashictome/network/NetworkHandler.java @@ -0,0 +1,27 @@ +package vazkii.akashictome.network; + +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.simple.SimpleChannel; +import vazkii.akashictome.AkashicTome; + +public class NetworkHandler { + private static SimpleChannel channel; + private static int id = 0; + + public static void register() { + final String protocolVersion = "1"; + channel = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(AkashicTome.MOD_ID, "main")) + .networkProtocolVersion(() -> protocolVersion) + .clientAcceptedVersions(protocolVersion::equals) + .serverAcceptedVersions(protocolVersion::equals) + .simpleChannel(); + channel.registerMessage(id++, MessageMorphTome.class, MessageMorphTome::serialize, MessageMorphTome::deserialize, MessageMorphTome::handle); + channel.registerMessage(id++, MessageUnmorphTome.class, MessageUnmorphTome::serialize, MessageUnmorphTome::deserialize, MessageUnmorphTome::handle); + } + + public static void sendToServer(MSG msg) { + channel.sendToServer(msg); + } + +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 022f5e2..35c7938 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[40,)" +loaderVersion="[47,)" issueTrackerURL="https://github.com/Vazkii/AkashicTome" license="Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License" @@ -7,20 +7,12 @@ license="Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported Lice modId="akashictome" displayName="Akashic Tome" version="${file.jarVersion}" -authors="Vazkii, MoreThanHidden" -description=''' -The book to end all books. -''' -[[dependencies.akashictome]] - modId="autoreglib" - mandatory=true - versionRange="[1.7-52,)" - ordering="AFTER" - side="BOTH" +authors="Vazkii, MoreThanHidden, Uraneptus" +description='''The book to end all books.''' [[dependencies.akashictome]] modId="forge" mandatory=true - versionRange="[38.0.17,)" + versionRange="[47.1.0,)" ordering="AFTER" side="BOTH" diff --git a/src/main/resources/assets/akashictome/models/item/tome.json b/src/main/resources/assets/akashictome/models/item/tome.json index 0c33174..2b0e89a 100644 --- a/src/main/resources/assets/akashictome/models/item/tome.json +++ b/src/main/resources/assets/akashictome/models/item/tome.json @@ -1,6 +1,6 @@ { - "parent": "item/handheld", + "parent": "minecraft:item/handheld", "textures": { - "layer0": "akashictome:items/tome" + "layer0": "akashictome:item/tome" } } diff --git a/src/main/resources/assets/akashictome/textures/items/tome.png b/src/main/resources/assets/akashictome/textures/item/tome.png similarity index 100% rename from src/main/resources/assets/akashictome/textures/items/tome.png rename to src/main/resources/assets/akashictome/textures/item/tome.png From 6e1a27e53b642f7ca59a86b1258a32fee3fef85b Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Mon, 5 Aug 2024 17:37:32 +0200 Subject: [PATCH 2/6] lang fixes --- build.properties | 4 ++-- src/main/java/vazkii/akashictome/MorphingHandler.java | 8 ++++++-- src/main/java/vazkii/akashictome/TomeItem.java | 6 +++--- src/main/resources/assets/akashictome/lang/en_us.json | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/build.properties b/build.properties index 5f1e89a..ce6c341 100644 --- a/build.properties +++ b/build.properties @@ -1,9 +1,9 @@ -#Fri Feb 02 19:58:59 UTC 2024 +#Mon Aug 05 15:03:26 UTC 2024 mapping_channel=parchment forge_version=47.2.0 mod_id=akashictome dir_repo=./ -build_number=25 +build_number=26 dir_output=../Build Output/AkashicTome/ mapping_version=2023.09.03-1.20.1 version=1.7 diff --git a/src/main/java/vazkii/akashictome/MorphingHandler.java b/src/main/java/vazkii/akashictome/MorphingHandler.java index d457c55..9966dca 100644 --- a/src/main/java/vazkii/akashictome/MorphingHandler.java +++ b/src/main/java/vazkii/akashictome/MorphingHandler.java @@ -37,7 +37,7 @@ public final class MorphingHandler { public void onPlayerLeftClick(PlayerInteractEvent.LeftClickEmpty event) { ItemStack stack = event.getItemStack(); if (!stack.isEmpty() && isAkashicTome(stack) && !stack.is(Registries.TOME.get())) { - NetworkHandler.sendToServer(new MessageUnmorphTome()); + NetworkHandler.sendToServer(new MessageUnmorphTome()); //TODO fix } } @@ -69,6 +69,7 @@ public void onItemDropped(ItemTossEvent event) { } copyCmp.remove("display"); + /* Component displayName = null; CompoundTag nameCmp = (CompoundTag) copyCmp.get(TAG_TOME_DISPLAY_NAME); if (nameCmp != null) @@ -76,6 +77,8 @@ public void onItemDropped(ItemTossEvent event) { if (displayName != null && !displayName.getString().isEmpty() && displayName != copy.getHoverName()) copy.setHoverName(displayName); + */ + copyCmp.remove(TAG_MORPHING); copyCmp.remove(TAG_TOME_DISPLAY_NAME); copyCmp.remove(TAG_TOME_DATA); @@ -104,7 +107,7 @@ public static String getModOrAlias(String mod) { return aliases.getOrDefault(mod, mod); } - public static boolean doesStackHaveModAttached(ItemStack stack, String mod) { + public static boolean doesStackHaveModAttached(ItemStack stack, String mod) { //TODO what was this used for? if (!stack.hasTag()) return false; @@ -172,6 +175,7 @@ public static ItemStack makeMorphedStack(ItemStack currentStack, String targetMo else stackCmp.put(TAG_TOME_DISPLAY_NAME, displayName); + MutableComponent rawComp = Component.Serializer.fromJson(displayName.getString("text")); if (rawComp == null) { stackCmp.put(TAG_TOME_DISPLAY_NAME, displayName); diff --git a/src/main/java/vazkii/akashictome/TomeItem.java b/src/main/java/vazkii/akashictome/TomeItem.java index 863111f..1554fc6 100644 --- a/src/main/java/vazkii/akashictome/TomeItem.java +++ b/src/main/java/vazkii/akashictome/TomeItem.java @@ -29,7 +29,7 @@ public class TomeItem extends Item { public TomeItem() { - super(new Properties().stacksTo(1)/*TODO .tab(CreativeModeTab.TAB_TOOLS)*/); + super(new Properties().stacksTo(1)); } @Override @@ -43,7 +43,7 @@ public InteractionResult useOn(UseOnContext context) { if (playerIn.isShiftKeyDown()) { String mod = MorphingHandler.getModFromState(worldIn.getBlockState(pos)); ItemStack newStack = MorphingHandler.getShiftStackForMod(stack, mod); - if (!ItemStack.isSameItemSameTags(newStack, stack)) { //TODO test if sameTags as well + if (!ItemStack.isSameItem(newStack, stack)) { //TODO test if sameTags as well playerIn.setItemInHand(hand, newStack); return InteractionResult.SUCCESS; } @@ -89,7 +89,7 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List Date: Tue, 6 Aug 2024 03:41:11 +0200 Subject: [PATCH 3/6] fixed log spam --- src/main/java/vazkii/akashictome/client/HUDHandler.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/vazkii/akashictome/client/HUDHandler.java b/src/main/java/vazkii/akashictome/client/HUDHandler.java index 641ae34..5cd25bc 100644 --- a/src/main/java/vazkii/akashictome/client/HUDHandler.java +++ b/src/main/java/vazkii/akashictome/client/HUDHandler.java @@ -7,6 +7,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; @@ -56,20 +58,21 @@ public void onDrawScreen(RenderGuiOverlayEvent.Post event) { String mod = MorphingHandler.getModFromState(state); ItemStack morphStack = MorphingHandler.getShiftStackForMod(tomeStack, mod); - if (!morphStack.isEmpty() && !ItemStack.isSameItemSameTags(morphStack, tomeStack)) { //TODO test if same tags as well + if (!morphStack.isEmpty() && !ItemStack.isSameItemSameTags(morphStack, tomeStack)) { drawStack = morphStack; line1 = NBTUtils.getCompound(morphStack, MorphingHandler.TAG_TOME_DISPLAY_NAME, false).getString("text"); line2 = ChatFormatting.GRAY + I18n.get("akashictome.click_morph"); } + MutableComponent line1Component = Component.Serializer.fromJson(line1); - if (!drawStack.isEmpty()) { + if (!drawStack.isEmpty() && line1Component != null) { RenderSystem.enableBlend(); RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); int sx = res.getGuiScaledWidth() / 2 - 17; int sy = res.getGuiScaledHeight() / 2 + 2; guiGraphics.renderItem(drawStack, sx, sy); - guiGraphics.drawString(mc.font, line1, sx + 20, sy + 4, 0xFFFFFFFF); + guiGraphics.drawString(mc.font, line1Component.withStyle(ChatFormatting.GREEN), sx + 20, sy + 4, 0xFFFFFFFF); guiGraphics.drawString(mc.font, line2, sx + 25, sy + 14, 0xFFFFFFFF); } } From afda4d8ecb1b3151d54ae8a1620e1b46aae14e5c Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Tue, 6 Aug 2024 03:41:38 +0200 Subject: [PATCH 4/6] fixed unmorphing --- .../java/vazkii/akashictome/network/MessageUnmorphTome.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java b/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java index 3262fa1..bd81edd 100644 --- a/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java +++ b/src/main/java/vazkii/akashictome/network/MessageUnmorphTome.java @@ -26,7 +26,7 @@ public static void handle(MessageUnmorphTome msg, Supplier if (player != null) { context.enqueueWork(() -> { ItemStack stack = player.getMainHandItem(); - if (!stack.isEmpty() && MorphingHandler.isAkashicTome(stack) && stack.is(Registries.TOME.get())) { + if (!stack.isEmpty() && MorphingHandler.isAkashicTome(stack) && !stack.is(Registries.TOME.get())) { ItemStack newStack = MorphingHandler.getShiftStackForMod(stack, MorphingHandler.MINECRAFT); var inventory = player.getInventory(); inventory.setItem(inventory.selected, newStack); From 626be7842cc8b8829506443d6c1a092c4b005797 Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Tue, 6 Aug 2024 03:42:13 +0200 Subject: [PATCH 5/6] Rewrote book screen renderer --- build.properties | 2 +- .../vazkii/akashictome/client/TomeScreen.java | 90 ++++++------------- 2 files changed, 28 insertions(+), 64 deletions(-) diff --git a/build.properties b/build.properties index ce6c341..00e64f2 100644 --- a/build.properties +++ b/build.properties @@ -3,7 +3,7 @@ mapping_channel=parchment forge_version=47.2.0 mod_id=akashictome dir_repo=./ -build_number=26 +build_number=27 dir_output=../Build Output/AkashicTome/ mapping_version=2023.09.03-1.20.1 version=1.7 diff --git a/src/main/java/vazkii/akashictome/client/TomeScreen.java b/src/main/java/vazkii/akashictome/client/TomeScreen.java index e772d70..d274636 100644 --- a/src/main/java/vazkii/akashictome/client/TomeScreen.java +++ b/src/main/java/vazkii/akashictome/client/TomeScreen.java @@ -7,6 +7,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Axis; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; @@ -99,8 +100,11 @@ public void render(GuiGraphics pGuiGraphics, int mouseX, int mouseY, float parti int padding = 4; int extra = 2; - pGuiGraphics.fill(startX - padding, startY - padding, startX + iconSize * amountPerRow + padding, startY + iconSize * rows + padding, 0x22000000); - pGuiGraphics.fill(startX - padding - extra, startY - padding - extra, startX + iconSize * amountPerRow + padding + extra, startY + iconSize * rows + padding + extra, 0x22000000); + + int endX = startX + iconSize * amountPerRow; + int endY = startY + iconSize * rows; + pGuiGraphics.fill(startX - padding, startY - padding, endX + padding, endY + padding, 0x22000000); + pGuiGraphics.fill(startX - padding - extra, startY - padding - extra, endX + padding + extra, endY + padding + extra, 0x22000000); ItemStack tooltipStack = ItemStack.EMPTY; @@ -115,8 +119,7 @@ public void render(GuiGraphics pGuiGraphics, int mouseX, int mouseY, float parti y -= 2; } - pGuiGraphics.renderItem(stack, x, y); //TODO render glint - //this.minecraft.getItemRenderer().renderAndDecorateItem(stack, x, y); + pGuiGraphics.renderItem(stack, x, y); } } @@ -137,68 +140,29 @@ public void render(GuiGraphics pGuiGraphics, int mouseX, int mouseY, float parti } if(!ConfigHandler.hideBookRender.get()) { - - + float f = 1.0F; + float f1 = 0.0F; + Lighting.setupForEntityInInventory(); + matrixStack.pushPose(); + matrixStack.translate((startX + endX) / 2.0, startY - 45, 100.0F); + float f2 = 100.0F; + matrixStack.scale(-f2, f2, f2); + matrixStack.mulPose(Axis.XP.rotationDegrees(30.0F)); + matrixStack.translate((1.0F - f) * 0.2F, (1.0F - f) * 0.1F, (1.0F - f) * 0.25F); + float f3 = -(1.0F - f) * 90.0F - 91.0F; + matrixStack.mulPose(Axis.YP.rotationDegrees(f3)); + matrixStack.mulPose(Axis.XP.rotationDegrees(180.0F)); + float f4 = Mth.clamp(Mth.frac(f1 + 0.25F) * 1.6F - 0.3F, 0.0F, 1.0F); + float f5 = Mth.clamp(Mth.frac(f1 + 0.75F) * 1.6F - 0.3F, 0.0F, 1.0F); + this.BOOK_MODEL.setupAnim(0.0F, f4, f5, f); + VertexConsumer vertexconsumer = pGuiGraphics.bufferSource().getBuffer(this.BOOK_MODEL.renderType(BOOK_TEXTURE)); + this.BOOK_MODEL.renderToBuffer(matrixStack, vertexconsumer, 15728880, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F); + pGuiGraphics.flush(); + matrixStack.popPose(); + Lighting.setupFor3DItems(); } RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } - - public void renderBook(PoseStack matrixStack) { //TODO rewrite this for 1.20 - // [VanillaCopy] EnchantmentScreen, but locked in open position, at different location, and bigger - Lighting.setupForFlatItems(); - int guiScale = (int) this.minecraft.getWindow().getGuiScale(); - int viewportWidth = 320; - int viewportHeight = 240; - RenderSystem.viewport((this.width - viewportWidth) / 2 * guiScale, (this.height - viewportHeight) / 2 * guiScale, viewportWidth * guiScale, viewportHeight * guiScale); - //Matrix4f projMat = Matrix4f.createTranslateMatrix(-0.34F, 0.23F, 0.0F); - //projMat.multiply(Matrix4f.perspective(90.0D, 1.3333334F, 9.0F, 80.0F)); - RenderSystem.backupProjectionMatrix(); - //RenderSystem.setProjectionMatrix(projMat); - matrixStack.pushPose(); - PoseStack.Pose pose = matrixStack.last(); - //pose.pose().setIdentity(); - //pose.normal().setIdentity(); - matrixStack.translate(6.3D, 3.3F, 1984.0D); // Akashic: Position at bottom of screen - float scale = 15.0F; // Akashic: bigger - matrixStack.scale(scale, scale, scale); - //matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0F)); - //matrixStack.mulPose(Vector3f.XP.rotationDegrees(20.0F)); - float f1 = 1.0F; // Akashic: lock in open position Mth.lerp(p_98763_, this.oOpen, this.open); - matrixStack.translate((1.0F - f1) * 0.2F, (1.0F - f1) * 0.1F, (1.0F - f1) * 0.25F); - float f2 = -(1.0F - f1) * 90.0F - 90.0F; - //matrixStack.mulPose(Vector3f.YP.rotationDegrees(f2)); - //matrixStack.mulPose(Vector3f.XP.rotationDegrees(180.0F)); - float f3 = 0.0F /* Akashic: no flip Mth.lerp(p_98763_, this.oFlip, this.flip) */ + 0.25F; - float f4 = 0.0F /* Akashic: no flip Mth.lerp(p_98763_, this.oFlip, this.flip) */ + 0.75F; - //f3 = (f3 - (float) Mth.fastFloor(f3)) * 1.6F - 0.3F; - //f4 = (f4 - (float) Mth.fastFloor(f4)) * 1.6F - 0.3F; - if (f3 < 0.0F) { - f3 = 0.0F; - } - - if (f4 < 0.0F) { - f4 = 0.0F; - } - - if (f3 > 1.0F) { - f3 = 1.0F; - } - - if (f4 > 1.0F) { - f4 = 1.0F; - } - - BOOK_MODEL.setupAnim(0.0F, f3, f4, f1); - MultiBufferSource.BufferSource buffers = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()); - VertexConsumer buffer = buffers.getBuffer(BOOK_MODEL.renderType(BOOK_TEXTURE)); - //BOOK_MODEL.renderToBuffer(matrixStack, buffer, 0xF000F0, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F); - buffers.endBatch(); - //matrixStack.popPose(); - RenderSystem.viewport(0, 0, this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight()); - RenderSystem.restoreProjectionMatrix(); - Lighting.setupFor3DItems(); - } - } From afb3ac0f0767e1b1504f31eaa999c661d78d1b84 Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Wed, 7 Aug 2024 19:45:45 +0200 Subject: [PATCH 6/6] fixing stuff (I hate u github) --- build.properties | 2 +- src/main/java/vazkii/akashictome/ConfigHandler.java | 1 - src/main/java/vazkii/akashictome/TomeItem.java | 2 +- src/main/java/vazkii/akashictome/client/HUDHandler.java | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/build.properties b/build.properties index 00e64f2..8b66ee9 100644 --- a/build.properties +++ b/build.properties @@ -1,4 +1,4 @@ -#Mon Aug 05 15:03:26 UTC 2024 +#Mon Aug 05 18:32:28 UTC 2024 mapping_channel=parchment forge_version=47.2.0 mod_id=akashictome diff --git a/src/main/java/vazkii/akashictome/ConfigHandler.java b/src/main/java/vazkii/akashictome/ConfigHandler.java index 3191312..2239aea 100644 --- a/src/main/java/vazkii/akashictome/ConfigHandler.java +++ b/src/main/java/vazkii/akashictome/ConfigHandler.java @@ -30,7 +30,6 @@ public ConfigHandler(ForgeConfigSpec.Builder builder) { Predicate validator = o -> o instanceof String; - //TODO update this list whitelistedItems = builder.defineList("Whitelisted Items", Lists.newArrayList("roots:runedtablet", "opencomputers:tool:4", diff --git a/src/main/java/vazkii/akashictome/TomeItem.java b/src/main/java/vazkii/akashictome/TomeItem.java index 1554fc6..e0d69ad 100644 --- a/src/main/java/vazkii/akashictome/TomeItem.java +++ b/src/main/java/vazkii/akashictome/TomeItem.java @@ -43,7 +43,7 @@ public InteractionResult useOn(UseOnContext context) { if (playerIn.isShiftKeyDown()) { String mod = MorphingHandler.getModFromState(worldIn.getBlockState(pos)); ItemStack newStack = MorphingHandler.getShiftStackForMod(stack, mod); - if (!ItemStack.isSameItem(newStack, stack)) { //TODO test if sameTags as well + if (!ItemStack.isSameItem(newStack, stack)) { playerIn.setItemInHand(hand, newStack); return InteractionResult.SUCCESS; } diff --git a/src/main/java/vazkii/akashictome/client/HUDHandler.java b/src/main/java/vazkii/akashictome/client/HUDHandler.java index 7fdd28e..2f0a3f5 100644 --- a/src/main/java/vazkii/akashictome/client/HUDHandler.java +++ b/src/main/java/vazkii/akashictome/client/HUDHandler.java @@ -53,7 +53,7 @@ public void onDrawScreen(RenderGuiOverlayEvent.Post event) { if (!state.isAir()) { ItemStack drawStack = ItemStack.EMPTY; - MutableComponent line1 = null; + String line1 = ""; String line2 = ""; String mod = MorphingHandler.getModFromState(state);