mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
Restore lexicon first person render, mostly
This commit is contained in:
1 parent
05fe2c195c
commit
85a7c986cf
3 files changed
+81
-51
No files matched your search
@@ -10,6 +10,8 @@ package vazkii.botania.client.core.handler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
@@ -32,13 +34,16 @@ import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.item.equipment.bauble.ItemFlightTiara;
|
||||
import vazkii.botania.common.item.relic.ItemKingKey;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
import vazkii.botania.common.lib.LibObfuscation;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
public class MiscellaneousIcons {
|
||||
|
||||
private static final MethodHandle MATERIALS = LibObfuscation.getGetter(ModelBakery.class, "field_177602_b");
|
||||
public static final MiscellaneousIcons INSTANCE = new MiscellaneousIcons();
|
||||
|
||||
public TextureAtlasSprite
|
||||
@@ -83,7 +88,10 @@ public class MiscellaneousIcons {
|
||||
public final IBakedModel[] kingKeyWeaponModels = new IBakedModel[ItemKingKey.WEAPON_TYPES];
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelRegister(ModelRegistryEvent evt) {
|
||||
public void onModelRegister(ModelRegistryEvent evt) throws Throwable {
|
||||
Set<Material> materials = (Set<Material>) MATERIALS.invokeExact();
|
||||
materials.add(RenderLexicon.TEXTURE);
|
||||
materials.add(RenderLexicon.ELVEN_TEXTURE);
|
||||
ModelLoader.addSpecialModel(prefix("icon/goldfish"));
|
||||
ModelLoader.addSpecialModel(prefix("icon/phiflower"));
|
||||
ModelLoader.addSpecialModel(prefix("icon/nerfbat"));
|
||||
|
||||
@@ -2,11 +2,19 @@ package vazkii.botania.client.core.handler;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.FirstPersonRenderer;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.entity.model.BookModel;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
@@ -24,17 +32,21 @@ import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.item.ItemLexicon;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
import vazkii.botania.common.lib.LibObfuscation;
|
||||
import vazkii.patchouli.client.book.gui.GuiBook;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// Hacky way to render 3D lexicon, will be reevaluated in the future.
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = LibMisc.MOD_ID)
|
||||
public class RenderLexicon {
|
||||
private static final MethodHandle APPLY_EQUIP_OFFSET = LibObfuscation.getMethod(FirstPersonRenderer.class, "func_228406_b_", MatrixStack.class, HandSide.class, float.class);
|
||||
private static final MethodHandle APPLY_SWING_OFFSET = LibObfuscation.getMethod(FirstPersonRenderer.class, "func_228399_a_", MatrixStack.class, HandSide.class, float.class);
|
||||
private static final BookModel model = new BookModel();
|
||||
private static final ResourceLocation texture = new ResourceLocation(LibResources.MODEL_LEXICA_DEFAULT);
|
||||
private static final ResourceLocation elvenTexture = new ResourceLocation(LibResources.MODEL_LEXICA_ELVEN);
|
||||
public static final Material TEXTURE = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(LibResources.MODEL_LEXICA_DEFAULT));
|
||||
public static final Material ELVEN_TEXTURE = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(LibResources.MODEL_LEXICA_ELVEN));
|
||||
|
||||
private static final String[] QUOTES = new String[] {
|
||||
"\"Neat!\" - Direwolf20",
|
||||
@@ -57,45 +69,43 @@ public class RenderLexicon {
|
||||
return;
|
||||
evt.setCanceled(true);
|
||||
try {
|
||||
// todo 1.15 need the buffers, MinecraftForge#6444 renderItemInFirstPerson(mc.player, evt.getMatrixStack(), evt.getPartialTicks(), evt.getInterpolatedPitch(), evt.getHand(), evt.getSwingProgress(), evt.getItemStack(), evt.getEquipProgress());
|
||||
renderFirstPersonItem(mc.player, evt.getPartialTicks(), evt.getInterpolatedPitch(), evt.getHand(), evt.getSwingProgress(), evt.getItemStack(), evt.getEquipProgress(), evt.getMatrixStack(), evt.getBuffers(), evt.getLight());
|
||||
} catch (Throwable throwable) {
|
||||
Botania.LOGGER.warn("Failed to render lexicon");
|
||||
Botania.LOGGER.warn("Failed to render lexicon", throwable);
|
||||
}
|
||||
}
|
||||
|
||||
private static void renderItemInFirstPerson(AbstractClientPlayerEntity player, MatrixStack ms, float partialTicks, float interpPitch, Hand hand, float swingProgress, ItemStack stack, float equipProgress) throws Throwable {
|
||||
// Cherry picked from ItemRenderer.renderItemInFirstPerson
|
||||
// todo 1.15 modernize to match FirstPersonRenderer
|
||||
boolean mainHand = hand == Hand.MAIN_HAND;
|
||||
HandSide side = mainHand ? player.getPrimaryHand() : player.getPrimaryHand().opposite();
|
||||
// [VanillaCopy] FirstPersonRenderer, irrelevant branches stripped out
|
||||
private static void renderFirstPersonItem(AbstractClientPlayerEntity player, float partialTicks, float pitch, Hand hand, float swingProgress, ItemStack stack, float equipProgress, MatrixStack ms, IRenderTypeBuffer buffers, int light) {
|
||||
boolean flag = hand == Hand.MAIN_HAND;
|
||||
HandSide handside = flag ? player.getPrimaryHand() : player.getPrimaryHand().opposite();
|
||||
ms.push();
|
||||
boolean rightSide = side == HandSide.RIGHT;
|
||||
float f = -0.4F * MathHelper.sin(MathHelper.sqrt(swingProgress) * (float)Math.PI);
|
||||
float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt(swingProgress) * ((float)Math.PI * 2F));
|
||||
float f2 = -0.2F * MathHelper.sin(swingProgress * (float)Math.PI);
|
||||
int i = rightSide ? 1 : -1;
|
||||
ms.translate(i * f, f1, f2);
|
||||
ms.translate(i * 0.56F, -0.44F + equipProgress * -0.8F, -0.72F);
|
||||
ms.translate(rightSide ? 0.2F : 0.52F, -0.125F, side == HandSide.RIGHT ? 0.6F : 0.25F);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rightSide ? 60F : 120F));
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(-30F));
|
||||
float f3 = MathHelper.sin(swingProgress * swingProgress * (float)Math.PI);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(i * (45.0F + f3 * -20.0F)));
|
||||
float f11 = MathHelper.sin(MathHelper.sqrt(swingProgress) * (float)Math.PI);
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(i * f11 * -20.0F));
|
||||
ms.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(f11 * -80.0F));
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(i * -45.0F));
|
||||
doRender(ms, side, partialTicks, stack);
|
||||
{
|
||||
boolean flag3 = handside == HandSide.RIGHT;
|
||||
{
|
||||
float f5 = -0.4F * MathHelper.sin(MathHelper.sqrt(swingProgress) * (float)Math.PI);
|
||||
float f6 = 0.2F * MathHelper.sin(MathHelper.sqrt(swingProgress) * ((float)Math.PI * 2F));
|
||||
float f10 = -0.2F * MathHelper.sin(swingProgress * (float)Math.PI);
|
||||
int l = flag3 ? 1 : -1;
|
||||
ms.translate((double)((float)l * f5), (double)f6, (double)f10);
|
||||
try {
|
||||
APPLY_EQUIP_OFFSET.invokeExact(Minecraft.getInstance().getFirstPersonRenderer(), ms, handside, equipProgress);
|
||||
APPLY_SWING_OFFSET.invokeExact(Minecraft.getInstance().getFirstPersonRenderer(), ms, handside, swingProgress);
|
||||
} catch (Throwable ex) {
|
||||
Botania.LOGGER.catching(ex);
|
||||
}
|
||||
}
|
||||
|
||||
doRender(stack, handside, ms, buffers, light, partialTicks);
|
||||
}
|
||||
|
||||
ms.pop();
|
||||
}
|
||||
|
||||
private static void doRender(MatrixStack ms, HandSide side, float partialTicks, ItemStack stack) {
|
||||
private static void doRender(ItemStack stack, HandSide side, MatrixStack ms, IRenderTypeBuffer buffers, int light, float partialTicks) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
|
||||
ms.push();
|
||||
mc.textureManager.bindTexture(((ItemLexicon) ModItems.lexicon).isElvenItem(stack) ? elvenTexture : texture);
|
||||
float opening;
|
||||
float pageFlip;
|
||||
|
||||
float ticks = ClientTickHandler.ticksWithLexicaOpen;
|
||||
if(ticks > 0 && ticks < 10) {
|
||||
@@ -105,32 +115,43 @@ public class RenderLexicon {
|
||||
else ticks -= partialTicks;
|
||||
}
|
||||
|
||||
ms.translate(0.3F + 0.02F * ticks, 0.475F + 0.01F * ticks, -0.2F - (side == HandSide.RIGHT ? 0.035F : 0.01F) * ticks);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(87.5F + ticks * (side == HandSide.RIGHT ? 8 : 12)));
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(ticks * 2.85F));
|
||||
opening = ticks / 12F;
|
||||
if (side == HandSide.RIGHT) {
|
||||
ms.translate(0.3F + 0.02F * ticks, 0.125F + 0.01F * ticks, -0.2F - 0.035F * ticks);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180F + ticks * 6));
|
||||
} else {
|
||||
ms.translate(0.1F - 0.02F * ticks, 0.125F + 0.01F * ticks, -0.2F - 0.035F * ticks);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(200F + ticks * 10));
|
||||
}
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(-0.3F + ticks * 2.85F));
|
||||
float opening = MathHelper.clamp(ticks / 12F, 0, 1);
|
||||
|
||||
float pageFlipTicks = ClientTickHandler.pageFlipTicks;
|
||||
if(pageFlipTicks > 0)
|
||||
pageFlipTicks -= ClientTickHandler.partialTicks;
|
||||
|
||||
pageFlip = pageFlipTicks / 5F;
|
||||
float pageFlip = pageFlipTicks / 5F;
|
||||
|
||||
float leftPageAngle = MathHelper.fractionalPart(pageFlip + 0.25F) * 1.6F - 0.3F;
|
||||
float rightPageAngle = MathHelper.fractionalPart(pageFlip + 0.75F) * 1.6F - 0.3F;
|
||||
model.setPageAngles(ClientTickHandler.total, MathHelper.clamp(leftPageAngle, 0.0F, 1.0F), MathHelper.clamp(rightPageAngle, 0.0F, 1.0F), opening);
|
||||
|
||||
Material mat = ((ItemLexicon) ModItems.lexicon).isElvenItem(stack) ? ELVEN_TEXTURE : TEXTURE;
|
||||
IVertexBuilder buffer = mat.getVertexConsumer(buffers, RenderType::getEntitySolid);
|
||||
model.render(ms, buffer, light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
|
||||
|
||||
// todo 1.15 model.render(0F, 0F, pageFlip, opening, 0F, 1F / 16F);
|
||||
if(ticks < 3) {
|
||||
FontRenderer font = Minecraft.getInstance().fontRenderer;
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(180F));
|
||||
ms.translate(-0.30F, -0.24F, -0.07F);
|
||||
ms.scale(0.0030F, 0.0030F, -0.0030F);
|
||||
|
||||
|
||||
String title = ItemLexicon.getTitle(stack).getFormattedText();
|
||||
|
||||
font.drawString(font.trimStringToWidth(title, 80), 0, 0, 0xD69700);
|
||||
font.draw(font.trimStringToWidth(title, 80), 0, 0, 0xD69700, false, ms.peek().getModel(), buffers, false, 0, light);
|
||||
|
||||
ms.translate(0F, 10F, 0F);
|
||||
ms.scale(0.6F, 0.6F, 0.6F);
|
||||
font.drawString(TextFormatting.ITALIC + "" + TextFormatting.BOLD + ItemLexicon.getEdition(), 0, 0, 0xA07100);
|
||||
String edition = TextFormatting.ITALIC + "" + TextFormatting.BOLD + ItemLexicon.getEdition();
|
||||
font.draw(edition, 0, 0, 0xA07100, false, ms.peek().getModel(), buffers, false, 0, light);
|
||||
|
||||
if(quote == -1)
|
||||
quote = mc.world.rand.nextInt(QUOTES.length);
|
||||
@@ -138,25 +159,27 @@ public class RenderLexicon {
|
||||
String quoteStr = QUOTES[quote];
|
||||
|
||||
ms.translate(-5F, 15F, 0F);
|
||||
renderText(0, 0, 140, 100, 0, false, 0x79ff92, quoteStr);
|
||||
renderText(0, 0, 140, 100, 0, 0x79ff92, quoteStr, ms.peek().getModel(), buffers, light);
|
||||
|
||||
ms.translate(8F, 110F, 0F);
|
||||
font.drawString(I18n.format("botaniamisc.lexiconcover0"), 0, 0, 0x79ff92);
|
||||
String blurb = I18n.format("botaniamisc.lexiconcover0");
|
||||
font.draw(blurb, 0, 0, 0x79ff92, false, ms.peek().getModel(), buffers, false, 0, light);
|
||||
|
||||
ms.translate(0F, 10F, 0F);
|
||||
font.drawString(TextFormatting.UNDERLINE + "" + TextFormatting.ITALIC + I18n.format("botaniamisc.lexiconcover1"), 0, 0, 0x79ff92);
|
||||
String blurb2 = TextFormatting.UNDERLINE + "" + TextFormatting.ITALIC + I18n.format("botaniamisc.lexiconcover1");
|
||||
font.draw(blurb2, 0, 0, 0x79ff92, false, ms.peek().getModel(), buffers, false, 0, light);
|
||||
|
||||
ms.translate(0F, -30F, 0F);
|
||||
|
||||
String authorTitle = I18n.format("botaniamisc.lexiconcover2");
|
||||
int len = font.getStringWidth(authorTitle);
|
||||
font.drawString(authorTitle, 58 - len / 2, -8, 0xD69700);
|
||||
font.draw(authorTitle, 58 - len / 2F, -8, 0xD69700, false, ms.peek().getModel(), buffers, false, 0, light);
|
||||
}
|
||||
|
||||
ms.pop();
|
||||
}
|
||||
|
||||
private static void renderText(int x, int y, int width, int height, int paragraphSize, boolean useUnicode, int color, String unlocalizedText) {
|
||||
private static void renderText(int x, int y, int width, int height, int paragraphSize, int color, String unlocalizedText, Matrix4f matrix, IRenderTypeBuffer buffers, int light) {
|
||||
x += 2;
|
||||
y += 10;
|
||||
width -= 4;
|
||||
@@ -194,7 +217,6 @@ public class RenderLexicon {
|
||||
|
||||
int i = 0;
|
||||
for(List<String> words : lines) {
|
||||
words.size();
|
||||
int xi = x;
|
||||
int spacing = 4;
|
||||
int wcount = words.size();
|
||||
@@ -216,7 +238,7 @@ public class RenderLexicon {
|
||||
compensationSpaces--;
|
||||
extra++;
|
||||
}
|
||||
font.drawString(s, xi, y, color);
|
||||
font.draw(s, xi, y, color, false, matrix, buffers, false, 0, light);
|
||||
xi += font.getStringWidth(s) + spacing + extra;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ public final class LibResources {
|
||||
public static final String MODEL_PYLON_MANA = PREFIX_MODEL + "pylon_mana.png";
|
||||
public static final String MODEL_PYLON_NATURA = PREFIX_MODEL + "pylon_natura.png";
|
||||
public static final String MODEL_PYLON_GAIA = PREFIX_MODEL + "pylon_gaia.png";
|
||||
public static final String MODEL_LEXICA_DEFAULT = PREFIX_MODEL + "lexicon_default.png";
|
||||
public static final String MODEL_LEXICA_ELVEN = PREFIX_MODEL + "lexicon_elven.png";
|
||||
public static final String MODEL_LEXICA_DEFAULT = PREFIX_MOD + "model/lexicon_default";
|
||||
public static final String MODEL_LEXICA_ELVEN = PREFIX_MOD + "model/lexicon_elven";
|
||||
public static final String MODEL_MANASTEEL_0 = PREFIX_MODEL + "manasteel_0.png";
|
||||
public static final String MODEL_MANASTEEL_1 = PREFIX_MODEL + "manasteel_1.png";
|
||||
public static final String MODEL_MANASTEEL_2 = PREFIX_MODEL + "manasteel_2.png";
|
||||
|
||||
Reference in new issue
Block a user