From 386b7333ab2c1d0abf5e9e94ef5e90b7b2b614ea Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 5 Nov 2023 15:24:31 -0500 Subject: [PATCH] General cleanup and porting of missed modules --- .../client/screen/VariantSelectorScreen.java | 18 +- .../module/EnchantmentsBegoneModule.java | 4 +- .../experimental/module/GameNerfsModule.java | 5 +- .../module/VariantSelectorModule.java | 382 +++++++++--------- .../module/VillagerRerollingReworkModule.java | 14 +- .../zeta/client/event/ZRenderOverlay.java | 5 +- .../zeta/client/event/ZRenderTooltip.java | 16 + .../java/vazkii/zetaimplforge/ForgeZeta.java | 3 +- .../zetaimplforge/client/ForgeZetaClient.java | 9 + .../client/event/ForgeZRenderOverlay.java | 12 + .../client/event/ForgeZRenderTooltip.java | 30 ++ .../event/ForgeZAttachCapabilities.java | 1 - 12 files changed, 270 insertions(+), 229 deletions(-) create mode 100644 src/main/java/vazkii/zeta/client/event/ZRenderTooltip.java create mode 100644 src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderTooltip.java diff --git a/src/main/java/vazkii/quark/content/experimental/client/screen/VariantSelectorScreen.java b/src/main/java/vazkii/quark/content/experimental/client/screen/VariantSelectorScreen.java index d74f302052..ed595574d6 100644 --- a/src/main/java/vazkii/quark/content/experimental/client/screen/VariantSelectorScreen.java +++ b/src/main/java/vazkii/quark/content/experimental/client/screen/VariantSelectorScreen.java @@ -1,19 +1,9 @@ package vazkii.quark.content.experimental.client.screen; -import java.util.ArrayList; -import java.util.List; - -import org.lwjgl.opengl.GL11; - import com.google.common.collect.ImmutableSet; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; - +import com.mojang.blaze3d.vertex.*; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -26,8 +16,12 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import org.lwjgl.opengl.GL11; import vazkii.quark.content.experimental.module.VariantSelectorModule; +import java.util.ArrayList; +import java.util.List; + public class VariantSelectorScreen extends Screen { float timeIn = 0; @@ -176,7 +170,7 @@ public void tick() { if(slotSelected != -1) { String variant = slotSelected == 0 ? "" : variants.get(slotSelected - 1); - VariantSelectorModule.setClientVariant(variant, true); + VariantSelectorModule.Client.setClientVariant(variant, true); mc.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } } diff --git a/src/main/java/vazkii/quark/content/experimental/module/EnchantmentsBegoneModule.java b/src/main/java/vazkii/quark/content/experimental/module/EnchantmentsBegoneModule.java index 0ab6356d8e..cd83954ec4 100644 --- a/src/main/java/vazkii/quark/content/experimental/module/EnchantmentsBegoneModule.java +++ b/src/main/java/vazkii/quark/content/experimental/module/EnchantmentsBegoneModule.java @@ -9,12 +9,12 @@ import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.EnchantmentInstance; -import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.config.Config; import vazkii.zeta.event.ZAnvilUpdate; import vazkii.zeta.event.ZConfigChanged; import vazkii.zeta.event.bus.LoadEvent; import vazkii.zeta.event.bus.PlayEvent; +import vazkii.zeta.module.ZetaLoadModule; import vazkii.zeta.module.ZetaModule; import java.util.List; @@ -22,7 +22,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -@LoadModule(category = "experimental", enabledByDefault = false, hasSubscriptions = true) +@ZetaLoadModule(category = "experimental", enabledByDefault = false) public class EnchantmentsBegoneModule extends ZetaModule { @Config diff --git a/src/main/java/vazkii/quark/content/experimental/module/GameNerfsModule.java b/src/main/java/vazkii/quark/content/experimental/module/GameNerfsModule.java index 6526c26b64..f570273c1e 100644 --- a/src/main/java/vazkii/quark/content/experimental/module/GameNerfsModule.java +++ b/src/main/java/vazkii/quark/content/experimental/module/GameNerfsModule.java @@ -1,7 +1,6 @@ package vazkii.quark.content.experimental.module; import com.mojang.serialization.Dynamic; - import net.minecraft.ChatFormatting; import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; @@ -20,10 +19,8 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.Level; - import net.minecraftforge.eventbus.api.Event; import vazkii.quark.base.Quark; -import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.config.Config; import vazkii.zeta.event.*; import vazkii.zeta.event.bus.LoadEvent; @@ -37,7 +34,7 @@ import java.util.UUID; import java.util.function.Predicate; -@LoadModule(category = "experimental", enabledByDefault = false, hasSubscriptions = true) +@ZetaLoadModule(category = "experimental", enabledByDefault = false) public class GameNerfsModule extends ZetaModule { private static final String TAG_TRADES_ADJUSTED = "quark:zombie_trades_adjusted"; diff --git a/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java b/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java index 7b848a94b3..86c15a7e14 100644 --- a/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java +++ b/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java @@ -1,15 +1,8 @@ package vazkii.quark.content.experimental.module; -import java.util.Arrays; -import java.util.List; - -import org.lwjgl.glfw.GLFW; -import org.lwjgl.opengl.GL11; - import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.datafixers.util.Either; - import net.minecraft.ChatFormatting; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; @@ -37,19 +30,11 @@ import net.minecraft.world.phys.HitResult; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.InputEvent.Key; -import net.minecraftforge.client.event.RenderGuiOverlayEvent; -import net.minecraftforge.client.event.RenderTooltipEvent; -import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; -import net.minecraftforge.event.TickEvent.ClientTickEvent; -import net.minecraftforge.event.TickEvent.Phase; -import net.minecraftforge.event.entity.EntityJoinLevelEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import org.lwjgl.glfw.GLFW; +import org.lwjgl.opengl.GL11; import vazkii.quark.base.Quark; import vazkii.quark.base.QuarkClient; import vazkii.quark.base.handler.MiscUtil; -import vazkii.quark.base.module.LoadModule; -import vazkii.zeta.module.ZetaModule; import vazkii.quark.base.module.config.Config; import vazkii.quark.base.network.QuarkNetwork; import vazkii.quark.base.network.message.experimental.PlaceVariantUpdateMessage; @@ -57,13 +42,19 @@ import vazkii.quark.content.experimental.client.tooltip.VariantsComponent; import vazkii.quark.content.experimental.config.BlockSuffixConfig; import vazkii.quark.content.experimental.item.HammerItem; +import vazkii.zeta.client.event.*; import vazkii.zeta.event.ZConfigChanged; +import vazkii.zeta.event.ZEntityJoinLevel; import vazkii.zeta.event.ZRegister; import vazkii.zeta.event.bus.LoadEvent; -import vazkii.zeta.client.event.ZKeyMapping; -import vazkii.zeta.client.event.ZTooltipComponents; +import vazkii.zeta.event.bus.PlayEvent; +import vazkii.zeta.module.ZetaLoadModule; +import vazkii.zeta.module.ZetaModule; -@LoadModule(category = "experimental", hasSubscriptions = true, enabledByDefault = false, +import java.util.Arrays; +import java.util.List; + +@ZetaLoadModule(category = "experimental", enabledByDefault = false, description = "Allows placing variant blocks automatically via a selector menu triggered from a keybind") public class VariantSelectorModule extends ZetaModule { @@ -94,19 +85,11 @@ public class VariantSelectorModule extends ZetaModule { public static Item hammer; - @OnlyIn(Dist.CLIENT) - private static KeyMapping variantSelectorKey; - @LoadEvent public final void register(ZRegister event) { hammer = new HammerItem(this).setCondition(() -> enableHammer); } - @LoadEvent - public void registerKeybinds(ZKeyMapping event) { - variantSelectorKey = event.init("quark.keybind.variant_selector", "r", QuarkClient.MISC_GROUP); - } - @LoadEvent public final void configChanged(ZConfigChanged event) { staticEnabled = enabled; @@ -127,17 +110,6 @@ public static void setSavedVariant(ServerPlayer player, String variant) { player.getPersistentData().putString(TAG_CURRENT_VARIANT, variant); } - @OnlyIn(Dist.CLIENT) - public static void setClientVariant(String variant, boolean sync) { - clientVariant = variant; - - if(sync) { - if(variant == null) - variant = ""; - QuarkNetwork.sendToServer(new PlaceVariantUpdateMessage(variant)); - } - } - private static Block getMainHandVariantBlock(Player player, String variant) { ItemStack mainHand = player.getMainHandItem(); if(mainHand.getItem() instanceof BlockItem blockItem) { @@ -165,80 +137,25 @@ public static Block getVariantOrOriginal(Block block, String variant) { return getVariantForBlock(block, variant); } - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public void keystroke(Key event) { - Minecraft mc = Minecraft.getInstance(); - if(mc.level != null && event.getAction() == GLFW.GLFW_PRESS) { - if(variantSelectorKey.isDown()) { - - ItemStack stack = mc.player.getMainHandItem(); - if(stack.is(hammer)) { - HitResult result = mc.hitResult; - if(result instanceof BlockHitResult bhr) { - BlockPos pos = bhr.getBlockPos(); - Block block = mc.player.level.getBlockState(pos).getBlock(); - stack = new ItemStack(variants.getOriginalBlock(block)); - } - } - - if(!stack.isEmpty() && stack.getItem() instanceof BlockItem) - mc.setScreen(new VariantSelectorScreen(stack, variantSelectorKey, clientVariant, variants.getVisibleVariants())); + public static ItemStack modifyHeldItemStack(AbstractClientPlayer player, ItemStack stack) { + if(!staticEnabled || !overrideHeldItemRender) + return stack; - return; + Minecraft mc = Minecraft.getInstance(); + if(player == mc.player && stack.getItem() instanceof BlockItem bi) { + Block block = bi.getBlock(); + if(clientVariant != null && !clientVariant.isEmpty()) { + Block variant = variants.getBlockForVariant(block, clientVariant); + if(variant != null && variant != block) + return new ItemStack(variant); } } - } - @LoadEvent - @OnlyIn(Dist.CLIENT) - public void registerClientTooltipComponentFactories(ZTooltipComponents event) { - event.register(VariantsComponent.class); - } - - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public void gatherComponents(RenderTooltipEvent.GatherComponents event) { - if(!showTooltip) - return; - - ItemStack stack = event.getItemStack(); - - if(hasTooltip(stack)) { - List> elements = event.getTooltipElements(); - int index = 1; - - if(Screen.hasShiftDown()) { - elements.add(index, Either.left(Component.translatable("quark.misc.variant_tooltip_header").withStyle(ChatFormatting.GRAY))); - elements.add(index + 1, Either.right(new VariantsComponent(stack))); - } - else - elements.add(index, Either.left(Component.translatable("quark.misc.variant_tooltip_hold_shift").withStyle(ChatFormatting.GRAY))); - } - } - - private boolean hasTooltip(ItemStack stack) { - return !stack.isEmpty() && stack.getItem() instanceof BlockItem bi && !variants.getAllVariants(bi.getBlock()).isEmpty(); - } - - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public void clientTick(ClientTickEvent event) { - if(event.phase != Phase.END) - return; - - Minecraft mc = Minecraft.getInstance(); - Level level = mc.level; - if(level == null) - setClientVariant(null, false); - else { - if(clientVariant == null) - setClientVariant("", true); - } + return stack; } - @SubscribeEvent - public void addEntityToWorld(EntityJoinLevelEvent event) { + @PlayEvent + public void addEntityToWorld(ZEntityJoinLevel event) { Entity entity = event.getEntity(); if(convertVariantItems && entity instanceof ItemEntity ie) { ItemStack stack = ie.getItem(); @@ -271,116 +188,183 @@ public static BlockState modifyBlockPlacementState(BlockState state, BlockPlaceC return state; } - - @OnlyIn(Dist.CLIENT) - public static ItemStack modifyHeldItemStack(AbstractClientPlayer player, ItemStack stack) { - if(!staticEnabled || !overrideHeldItemRender) - return stack; - - Minecraft mc = Minecraft.getInstance(); - if(player == mc.player && stack.getItem() instanceof BlockItem bi) { - Block block = bi.getBlock(); - if(clientVariant != null && !clientVariant.isEmpty()) { - Block variant = variants.getBlockForVariant(block, clientVariant); - if(variant != null && variant != block) - return new ItemStack(variant); + + @ZetaLoadModule(clientReplacement = true) + public static class Client extends VariantSelectorModule { + @OnlyIn(Dist.CLIENT) + private static KeyMapping variantSelectorKey; + + @LoadEvent + public void registerKeybinds(ZKeyMapping event) { + variantSelectorKey = event.init("quark.keybind.variant_selector", "r", QuarkClient.MISC_GROUP); + } + + public static void setClientVariant(String variant, boolean sync) { + clientVariant = variant; + + if(sync) { + if(variant == null) + variant = ""; + QuarkNetwork.sendToServer(new PlaceVariantUpdateMessage(variant)); } } - - return stack; - } - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public void onRender(RenderGuiOverlayEvent.Pre event) { - Minecraft mc = Minecraft.getInstance(); - if(event.getOverlay() != VanillaGuiOverlay.CROSSHAIR.type() || mc.screen instanceof VariantSelectorScreen || !showHud) - return; + @PlayEvent + public void keystroke(ZInput.Key event) { + Minecraft mc = Minecraft.getInstance(); + if(mc.level != null && event.getAction() == GLFW.GLFW_PRESS) { + if(variantSelectorKey.isDown()) { + + ItemStack stack = mc.player.getMainHandItem(); + if(stack.is(hammer)) { + HitResult result = mc.hitResult; + if(result instanceof BlockHitResult bhr) { + BlockPos pos = bhr.getBlockPos(); + Block block = mc.player.level.getBlockState(pos).getBlock(); + stack = new ItemStack(variants.getOriginalBlock(block)); + } + } - Player player = mc.player; - String savedVariant = getSavedVariant(player); + if(!stack.isEmpty() && stack.getItem() instanceof BlockItem) + mc.setScreen(new VariantSelectorScreen(stack, variantSelectorKey, clientVariant, variants.getVisibleVariants())); - if(savedVariant != null) { - ItemStack mainHand = player.getMainHandItem(); - ItemStack displayLeft = mainHand.copy(); + return; + } + } + } + + @LoadEvent + public void registerClientTooltipComponentFactories(ZTooltipComponents event) { + event.register(VariantsComponent.class); + } + + @PlayEvent + public void gatherComponents(ZRenderTooltip.GatherComponents event) { + if(!showTooltip) + return; - Block variantBlock = null; + ItemStack stack = event.getItemStack(); - if(displayLeft.is(hammer)) { - HitResult result = mc.hitResult; - if(result instanceof BlockHitResult bhr) { - BlockPos pos = bhr.getBlockPos(); - Block testBlock = player.level.getBlockState(pos).getBlock(); + if(hasTooltip(stack)) { + List> elements = event.getTooltipElements(); + int index = 1; - displayLeft = new ItemStack(testBlock); - variantBlock = getVariantOrOriginal(testBlock, savedVariant); + if(Screen.hasShiftDown()) { + elements.add(index, Either.left(Component.translatable("quark.misc.variant_tooltip_header").withStyle(ChatFormatting.GRAY))); + elements.add(index + 1, Either.right(new VariantsComponent(stack))); } + else + elements.add(index, Either.left(Component.translatable("quark.misc.variant_tooltip_hold_shift").withStyle(ChatFormatting.GRAY))); } - else - variantBlock = getMainHandVariantBlock(player, savedVariant); + } - if(variantBlock != null) { - ItemStack displayRight = new ItemStack(variantBlock); + private boolean hasTooltip(ItemStack stack) { + return !stack.isEmpty() && stack.getItem() instanceof BlockItem bi && !variants.getAllVariants(bi.getBlock()).isEmpty(); + } - if(displayLeft.getItem() == displayRight.getItem()) - return; + @PlayEvent + public void clientTick(ZEndClientTick event) { + Minecraft mc = Minecraft.getInstance(); + Level level = mc.level; + if(level == null) + setClientVariant(null, false); + else { + if(clientVariant == null) + setClientVariant("", true); + } + } - Window window = event.getWindow(); - int x = window.getGuiScaledWidth() / 2; - int y = window.getGuiScaledHeight() / 2 + 12; - - - showSimpleHud = true; - alignHudToHotbar = true; - - if(alignHudToHotbar) { - HumanoidArm arm = mc.options.mainHand().get(); - if(arm == HumanoidArm.RIGHT) - x += 125; - else x -= 93; - - y = window.getGuiScaledHeight() - 19; + @PlayEvent + public void onRender(ZRenderOverlay.Crosshair.Pre event) { + Minecraft mc = Minecraft.getInstance(); + if(mc.screen instanceof VariantSelectorScreen || !showHud) + return; + + Player player = mc.player; + String savedVariant = getSavedVariant(player); + + if(savedVariant != null) { + ItemStack mainHand = player.getMainHandItem(); + ItemStack displayLeft = mainHand.copy(); + + Block variantBlock = null; + + if(displayLeft.is(hammer)) { + HitResult result = mc.hitResult; + if(result instanceof BlockHitResult bhr) { + BlockPos pos = bhr.getBlockPos(); + Block testBlock = player.level.getBlockState(pos).getBlock(); + + displayLeft = new ItemStack(testBlock); + variantBlock = getVariantOrOriginal(testBlock, savedVariant); + } } - - int offset = 8; - int width = 16; - - displayLeft.setCount(1); - - int posX = x - offset - width; - int posY = y; - - if(!showSimpleHud) { - mc.getItemRenderer().renderAndDecorateItem(displayLeft, posX, posY); - - RenderSystem.enableBlend(); - RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 0.75F); - RenderSystem.setShaderTexture(0, MiscUtil.GENERAL_ICONS); - - Screen.blit(event.getPoseStack(), posX + 8, posY, 0, 141, 22, 15, 256, 256); - - posX += width * 2; - } - else { - final ResourceLocation WIDGETS_LOCATION = new ResourceLocation("textures/gui/widget.png"); - + else + variantBlock = getMainHandVariantBlock(player, savedVariant); + + if(variantBlock != null) { + ItemStack displayRight = new ItemStack(variantBlock); + + if(displayLeft.getItem() == displayRight.getItem()) + return; + + Window window = event.getWindow(); + int x = window.getGuiScaledWidth() / 2; + int y = window.getGuiScaledHeight() / 2 + 12; + + + showSimpleHud = true; + alignHudToHotbar = true; + if(alignHudToHotbar) { + HumanoidArm arm = mc.options.mainHand().get(); + if(arm == HumanoidArm.RIGHT) + x += 125; + else x -= 93; + + y = window.getGuiScaledHeight() - 19; + } + + int offset = 8; + int width = 16; + + displayLeft.setCount(1); + + int posX = x - offset - width; + int posY = y; + + if(!showSimpleHud) { + mc.getItemRenderer().renderAndDecorateItem(displayLeft, posX, posY); + RenderSystem.enableBlend(); RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); RenderSystem.setShader(GameRenderer::getPositionTexShader); - if(enableGreenTint) - RenderSystem.setShaderColor(0.5F, 1.0F, 0.5F, 1.0F); - else - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, WIDGETS_LOCATION); - Screen.blit(event.getPoseStack(), posX -3, posY -3, 24, 23, 22, 22, 256, 256); - } else - posX += width; - } - - mc.getItemRenderer().renderAndDecorateItem(displayRight, posX , posY); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 0.75F); + RenderSystem.setShaderTexture(0, MiscUtil.GENERAL_ICONS); + + Screen.blit(event.getPoseStack(), posX + 8, posY, 0, 141, 22, 15, 256, 256); + + posX += width * 2; + } + else { + final ResourceLocation WIDGETS_LOCATION = new ResourceLocation("textures/gui/widget.png"); + + if(alignHudToHotbar) { + RenderSystem.enableBlend(); + RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + if(enableGreenTint) + RenderSystem.setShaderColor(0.5F, 1.0F, 0.5F, 1.0F); + else + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.setShaderTexture(0, WIDGETS_LOCATION); + Screen.blit(event.getPoseStack(), posX -3, posY -3, 24, 23, 22, 22, 256, 256); + } else + posX += width; + } + + mc.getItemRenderer().renderAndDecorateItem(displayRight, posX , posY); + } } } } diff --git a/src/main/java/vazkii/quark/content/experimental/module/VillagerRerollingReworkModule.java b/src/main/java/vazkii/quark/content/experimental/module/VillagerRerollingReworkModule.java index 51be93f047..60b0b7b514 100644 --- a/src/main/java/vazkii/quark/content/experimental/module/VillagerRerollingReworkModule.java +++ b/src/main/java/vazkii/quark/content/experimental/module/VillagerRerollingReworkModule.java @@ -8,20 +8,16 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.trading.MerchantOffer; import net.minecraft.world.item.trading.MerchantOffers; -import net.minecraftforge.event.entity.living.LivingConversionEvent; -import net.minecraftforge.event.entity.living.LivingEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import vazkii.quark.base.module.LoadModule; -import vazkii.zeta.event.ZLivingConversion; -import vazkii.zeta.event.ZLivingTick; -import vazkii.zeta.event.bus.PlayEvent; -import vazkii.zeta.module.ZetaLoadModule; -import vazkii.zeta.module.ZetaModule; import vazkii.quark.base.module.config.Config; import vazkii.quark.content.experimental.hax.PseudoAccessorMerchantOffer; import vazkii.quark.mixin.accessor.AccessorMerchantOffer; import vazkii.zeta.event.ZConfigChanged; +import vazkii.zeta.event.ZLivingConversion; +import vazkii.zeta.event.ZLivingTick; import vazkii.zeta.event.bus.LoadEvent; +import vazkii.zeta.event.bus.PlayEvent; +import vazkii.zeta.module.ZetaLoadModule; +import vazkii.zeta.module.ZetaModule; @ZetaLoadModule(category = "experimental", enabledByDefault = false) public class VillagerRerollingReworkModule extends ZetaModule { diff --git a/src/main/java/vazkii/zeta/client/event/ZRenderOverlay.java b/src/main/java/vazkii/zeta/client/event/ZRenderOverlay.java index 00228587ce..65f2451f72 100644 --- a/src/main/java/vazkii/zeta/client/event/ZRenderOverlay.java +++ b/src/main/java/vazkii/zeta/client/event/ZRenderOverlay.java @@ -20,7 +20,10 @@ interface Chat extends ZRenderOverlay { interface Pre extends Chat { } interface Post extends Chat { } } - interface Crosshair extends ZRenderOverlay { } + interface Crosshair extends ZRenderOverlay { + interface Pre extends Crosshair { } + interface Post extends Crosshair { } + } interface Hotbar extends ZRenderOverlay { interface Pre extends Chat { } interface Post extends Chat { } diff --git a/src/main/java/vazkii/zeta/client/event/ZRenderTooltip.java b/src/main/java/vazkii/zeta/client/event/ZRenderTooltip.java new file mode 100644 index 0000000000..984a8da86a --- /dev/null +++ b/src/main/java/vazkii/zeta/client/event/ZRenderTooltip.java @@ -0,0 +1,16 @@ +package vazkii.zeta.client.event; + +import com.mojang.datafixers.util.Either; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.ItemStack; +import vazkii.zeta.event.bus.IZetaPlayEvent; + +import java.util.List; + +public interface ZRenderTooltip extends IZetaPlayEvent { + interface GatherComponents extends IZetaPlayEvent, ZRenderTooltip { + ItemStack getItemStack(); + List> getTooltipElements(); + } +} diff --git a/src/main/java/vazkii/zetaimplforge/ForgeZeta.java b/src/main/java/vazkii/zetaimplforge/ForgeZeta.java index d67c582568..84baddeef5 100644 --- a/src/main/java/vazkii/zetaimplforge/ForgeZeta.java +++ b/src/main/java/vazkii/zetaimplforge/ForgeZeta.java @@ -180,7 +180,8 @@ public void start() { MinecraftForge.EVENT_BUS.addListener(this::babyEntitySpawn); MinecraftForge.EVENT_BUS.addListener(this::babyEntitySpawnLowest); MinecraftForge.EVENT_BUS.addListener(this::entityJoinLevel); - MinecraftForge.EVENT_BUS.addListener(this::attachCapabilities); + //fixme + //MinecraftForge.EVENT_BUS.addGenericListener(ForgeZeta.class, this::attachCapabilities); MinecraftForge.EVENT_BUS.addListener(this::levelTickStart); MinecraftForge.EVENT_BUS.addListener(this::levelTickEnd); MinecraftForge.EVENT_BUS.addListener(this::playerInteract); diff --git a/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java b/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java index a71454244a..0ac2baa011 100644 --- a/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java +++ b/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java @@ -96,6 +96,7 @@ public void start() { MinecraftForge.EVENT_BUS.addListener(this::renderPlayerPost); MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGHEST, this::renderLivingPreHighest); MinecraftForge.EVENT_BUS.addListener(EventPriority.LOWEST, this::renderLivingPostLowest); + MinecraftForge.EVENT_BUS.addListener(this::renderTooltipGatherComponents); } public void registerBlockColors(RegisterColorHandlersEvent.Block event) { @@ -247,6 +248,8 @@ else if(e.getOverlay() == VanillaGuiOverlay.CHAT_PANEL.type()) playBus.fire(new ForgeZRenderOverlay.Chat.Pre(e), ZRenderOverlay.Chat.Pre.class); else if(e.getOverlay() == VanillaGuiOverlay.HOTBAR.type()) playBus.fire(new ForgeZRenderOverlay.Hotbar.Pre(e), ZRenderOverlay.Hotbar.Pre.class); + else if (e.getOverlay() == VanillaGuiOverlay.CROSSHAIR.type()) + playBus.fire(new ForgeZRenderOverlay.Crosshair.Pre(e), ZRenderOverlay.Crosshair.Pre.class); } public void renderGameOverlayPost(RenderGuiOverlayEvent.Post e) { @@ -256,6 +259,8 @@ else if(e.getOverlay() == VanillaGuiOverlay.CHAT_PANEL.type()) playBus.fire(new ForgeZRenderOverlay.Chat.Post(e), ZRenderOverlay.Chat.Post.class); else if(e.getOverlay() == VanillaGuiOverlay.HOTBAR.type()) playBus.fire(new ForgeZRenderOverlay.Hotbar.Post(e), ZRenderOverlay.Hotbar.Post.class); + else if (e.getOverlay() == VanillaGuiOverlay.CROSSHAIR.type()) + playBus.fire(new ForgeZRenderOverlay.Crosshair.Post(e), ZRenderOverlay.Crosshair.Post.class); } public void renderPlayerPre(RenderPlayerEvent.Pre e) { @@ -273,4 +278,8 @@ public void renderLivingPreHighest(RenderLivingEvent.Pre e) { public void renderLivingPostLowest(RenderLivingEvent.Post e) { playBus.fire(new ForgeZRenderLiving.PostLowest(e), ZRenderLiving.PostLowest.class); } + + public void renderTooltipGatherComponents(RenderTooltipEvent.GatherComponents e) { + playBus.fire(new ForgeZRenderTooltip.GatherComponents(e), ZRenderTooltip.GatherComponents.class); + } } diff --git a/src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderOverlay.java b/src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderOverlay.java index e63a32a01a..1a4deab180 100644 --- a/src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderOverlay.java +++ b/src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderOverlay.java @@ -79,6 +79,18 @@ public static class Crosshair extends ForgeZRenderOverlay implements ZRenderOver public Crosshair(RenderGuiOverlayEvent e) { super(e); } + + public static class Pre extends ForgeZRenderOverlay.Crosshair implements ZRenderOverlay.Crosshair.Pre { + public Pre(RenderGuiOverlayEvent.Pre e) { + super(e); + } + } + + public static class Post extends ForgeZRenderOverlay.Crosshair implements ZRenderOverlay.Crosshair.Post { + public Post(RenderGuiOverlayEvent.Post e) { + super(e); + } + } } public static class Hotbar extends ForgeZRenderOverlay implements ZRenderOverlay.Hotbar { diff --git a/src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderTooltip.java b/src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderTooltip.java new file mode 100644 index 0000000000..d84f8c1464 --- /dev/null +++ b/src/main/java/vazkii/zetaimplforge/client/event/ForgeZRenderTooltip.java @@ -0,0 +1,30 @@ +package vazkii.zetaimplforge.client.event; + +import com.mojang.datafixers.util.Either; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.client.event.RenderTooltipEvent; +import vazkii.zeta.client.event.ZRenderTooltip; + +import java.util.List; + +public class ForgeZRenderTooltip implements ZRenderTooltip { + public static class GatherComponents extends ForgeZRenderTooltip implements ZRenderTooltip.GatherComponents { + private final RenderTooltipEvent.GatherComponents e; + + public GatherComponents(RenderTooltipEvent.GatherComponents e) { + this.e = e; + } + + @Override + public ItemStack getItemStack() { + return e.getItemStack(); + } + + @Override + public List> getTooltipElements() { + return e.getTooltipElements(); + } + } +} diff --git a/src/main/java/vazkii/zetaimplforge/event/ForgeZAttachCapabilities.java b/src/main/java/vazkii/zetaimplforge/event/ForgeZAttachCapabilities.java index ad8cfb9e25..676abfc95c 100644 --- a/src/main/java/vazkii/zetaimplforge/event/ForgeZAttachCapabilities.java +++ b/src/main/java/vazkii/zetaimplforge/event/ForgeZAttachCapabilities.java @@ -2,7 +2,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.event.AnvilUpdateEvent; import net.minecraftforge.event.AttachCapabilitiesEvent; import vazkii.zeta.event.ZAttachCapabilities;