From 33b8d2bd85ee416d7edc3d1d76ee2987de726297 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Sun, 4 Oct 2020 15:39:32 +0200 Subject: [PATCH] Fix matrix stack rotations --- .../jei/category/PolishingCategory.java | 3 +- .../category/ProcessingViaFanCategory.java | 14 +++++--- .../animations/AnimatedBlazeBurner.java | 6 ++-- .../animations/AnimatedCrushingWheels.java | 5 ++- .../category/animations/AnimatedMixer.java | 6 ++-- .../category/animations/AnimatedPress.java | 6 ++-- .../jei/category/animations/AnimatedSaw.java | 6 ++-- .../tools/SandPaperItemRenderer.java | 6 ++-- .../curiosities/zapper/ZapperScreen.java | 4 +-- .../create/foundation/gui/GuiGameElement.java | 36 ++++++++----------- 10 files changed, 44 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java index 43248d03a..ea5f09a35 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java @@ -55,6 +55,7 @@ public class PolishingCategory extends CreateRecipeCategory> extends CreateRecipeCategory { @@ -30,7 +32,7 @@ public abstract class ProcessingViaFanCategory> extends Cre } @Override - public void setRecipe(IRecipeLayout recipeLayout, T recipe, IIngredients ingredients) { + public void setRecipe(IRecipeLayout recipeLayout, T recipe, @Nullable IIngredients ingredients) { IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); itemStacks.init(0, true, 20, 47); itemStacks.set(0, Arrays.asList(recipe.getIngredients() @@ -50,12 +52,14 @@ public abstract class ProcessingViaFanCategory> extends Cre } @Override - public void draw(T recipe, MatrixStack matrixStack, double mouseX, double mouseY) { + public void draw(@Nullable T recipe, @Nullable MatrixStack matrixStack, double mouseX, double mouseY) { + if (matrixStack == null) + return; renderWidgets(matrixStack, recipe, mouseX, mouseY); matrixStack.push(); matrixStack.translate(56, 33, 0); - matrixStack.multiply(new Quaternion( -12.5f, 1, 0, 0)); - matrixStack.multiply(new Quaternion( 22.5f, 0, 1, 0)); + matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-12.5f)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 24; GuiGameElement.of(AllBlockPartials.ENCASED_FAN_INNER) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java index 9de3c0081..8ec5983de 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java @@ -7,7 +7,7 @@ import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlo import com.simibubi.create.foundation.gui.GuiGameElement; import mezz.jei.api.gui.drawable.IDrawable; -import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; public class AnimatedBlazeBurner implements IDrawable { @@ -21,8 +21,8 @@ public class AnimatedBlazeBurner implements IDrawable { public void draw(MatrixStack matrixStack, int xOffset, int yOffset) { matrixStack.push(); matrixStack.translate(xOffset, yOffset, 200); - matrixStack.multiply(new Quaternion(-15.5f, 1, 0, 0)); - matrixStack.multiply(new Quaternion(22.5f, 0, 1, 0)); + matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-15.5f)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 23; GuiGameElement.of(AllBlocks.BLAZE_BURNER.getDefaultState()) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrushingWheels.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrushingWheels.java index cb07eadd9..0459efd33 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrushingWheels.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrushingWheels.java @@ -8,7 +8,7 @@ import com.simibubi.create.foundation.gui.GuiGameElement; import net.minecraft.block.BlockState; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; public class AnimatedCrushingWheels extends AnimatedKinetics { @@ -16,8 +16,7 @@ public class AnimatedCrushingWheels extends AnimatedKinetics { public void draw(MatrixStack matrixStack, int xOffset, int yOffset) { RenderSystem.enableDepthTest(); matrixStack.translate(xOffset, yOffset, 100); - matrixStack.multiply(new Quaternion(-22.5f, 0, 1, 0)); - // RenderSystem.rotatef(-22.5f, 0, 1, 0); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-22.5f)); int scale = 22; BlockState wheel = AllBlocks.CRUSHING_WHEEL.get() diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMixer.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMixer.java index 4f59ec139..011e34801 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMixer.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMixer.java @@ -7,7 +7,7 @@ import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; public class AnimatedMixer extends AnimatedKinetics { @@ -15,8 +15,8 @@ public class AnimatedMixer extends AnimatedKinetics { public void draw(MatrixStack matrixStack, int xOffset, int yOffset) { matrixStack.push(); matrixStack.translate(xOffset, yOffset, 200); - matrixStack.multiply(new Quaternion(-15.5f, 1, 0, 0)); - matrixStack.multiply(new Quaternion( 22.5f, 0, 1, 0)); + matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-15.5f)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 23; GuiGameElement.of(cogwheel()) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java index 9a0b92551..8c06b43aa 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java @@ -9,7 +9,7 @@ import com.simibubi.create.foundation.gui.GuiGameElement; import net.minecraft.client.Minecraft; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; public class AnimatedPress extends AnimatedKinetics { @@ -23,8 +23,8 @@ public class AnimatedPress extends AnimatedKinetics { public void draw(MatrixStack matrixStack, int xOffset, int yOffset) { matrixStack.push(); matrixStack.translate(xOffset, yOffset, 100); - matrixStack.multiply(new Quaternion( -15.5f, 1, 0, 0)); - matrixStack.multiply(new Quaternion( 22.5f, 0, 1, 0)); + matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-15.5f)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = basin ? 20 : 24; GuiGameElement.of(shaft(Axis.Z)) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSaw.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSaw.java index eeb9cb392..12fe38c72 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSaw.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSaw.java @@ -8,7 +8,7 @@ import com.simibubi.create.foundation.gui.GuiGameElement; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; public class AnimatedSaw extends AnimatedKinetics { @@ -20,8 +20,8 @@ public class AnimatedSaw extends AnimatedKinetics { matrixStack.translate(0, 0, 200); matrixStack.translate(-6, 19, 0); - matrixStack.multiply(new Quaternion( -22.5f, 1, 0, 0)); - matrixStack.multiply(new Quaternion(90 - 22.5f, 0, 1, 0)); + matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-22.5f)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90-225f)); int scale = 25; GuiGameElement.of(shaft(Axis.X)) diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java index 6fe251e91..89a85b2f1 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java @@ -71,9 +71,9 @@ public class SandPaperItemRenderer extends ItemStackTileEntityRenderer { if (itemInUseCount > 0) { int modifier = leftHand ? -1 : 1; ms.translate(modifier * .5f, 0, -.25f); - ms.multiply(new Quaternion(modifier * 40, 0, 0, 1)); - ms.multiply(new Quaternion(modifier * 10, 1, 0, 0)); - ms.multiply(new Quaternion(modifier * 90, 0, 1, 0)); + ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(modifier * 40)); + ms.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(modifier * 10)); + ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(modifier * 90)); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java index 3d55f1922..fdc50639d 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java @@ -19,7 +19,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; import net.minecraft.util.Hand; -import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; @@ -142,7 +142,7 @@ public class ZapperScreen extends AbstractSimiScreen { protected void renderBlock(MatrixStack matrixStack) { matrixStack.push(); matrixStack.translate(guiLeft + 7f, guiTop + 43.5f, 120); - matrixStack.multiply(new Quaternion( -30f, .5f, .9f, -.1f)); + matrixStack.multiply(new Vector3f(.5f, .9f, -.1f).getDegreesQuaternion(-30f)); matrixStack.scale(20, 20, 20); BlockState state = Blocks.AIR.getDefaultState(); diff --git a/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java b/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java index cbb9bb645..653f29c37 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java @@ -1,5 +1,6 @@ package com.simibubi.create.foundation.gui; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.mojang.blaze3d.matrix.MatrixStack; @@ -35,8 +36,8 @@ import net.minecraft.util.Direction; import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.IItemProvider; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Quaternion; import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3f; import net.minecraft.world.LightType; import net.minecraft.world.World; import net.minecraftforge.client.model.data.EmptyModelData; @@ -115,16 +116,8 @@ public class GuiGameElement { public abstract void render(MatrixStack matrixStack); - protected void prepare() { - RenderSystem.pushMatrix(); - RenderSystem.enableBlend(); - RenderSystem.enableRescaleNormal(); - RenderSystem.enableAlphaTest(); - RenderHelper.enableGuiDepthLighting(); - RenderSystem.alphaFunc(516, 0.1F); - RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - } + @Deprecated + protected void prepare() {} protected void prepareMatrix(MatrixStack matrixStack) { matrixStack.push(); @@ -137,6 +130,7 @@ public class GuiGameElement { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); } + @Deprecated protected void transform() { RenderSystem.translated(xBeforeScale, yBeforeScale, 0); RenderSystem.scaled(scale, scale, scale); @@ -155,17 +149,14 @@ public class GuiGameElement { matrixStack.translate(x, y, z); matrixStack.scale(1, -1, 1); matrixStack.translate(rotationOffset.x, rotationOffset.y, rotationOffset.z); - matrixStack.multiply(new Quaternion((float) zRot, 0, 0, 1)); - matrixStack.multiply(new Quaternion((float) xRot, 1, 0, 0)); - matrixStack.multiply(new Quaternion((float) yRot, 0, 1, 0)); + matrixStack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion((float) zRot)); + matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion((float) xRot)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion((float) yRot)); matrixStack.translate(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z); } - protected void cleanUp() { - RenderSystem.popMatrix(); - RenderSystem.disableAlphaTest(); - RenderSystem.disableRescaleNormal(); - } + @Deprecated + protected void cleanUp() {} protected void cleanUpMatrix(MatrixStack matrixStack) { matrixStack.pop(); @@ -259,8 +250,8 @@ public class GuiGameElement { ms.push(); ms.translate(.5, .5, .5); - ms.multiply(new Quaternion(AngleHelper.horizontalAngle(d), 0, 1, 0)); - ms.multiply(new Quaternion(AngleHelper.verticalAngle(d) - 90, 0, 0, 1)); + ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(AngleHelper.horizontalAngle(d))); + ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(AngleHelper.verticalAngle(d) - 90)); ms.translate(-.5, -.5, -.5); blockRenderer.renderFluid(new BlockPos(0, 1, 0), renderWorld, vb, blockState.getFluidState()); buffer.draw(type); @@ -315,11 +306,12 @@ public class GuiGameElement { } @Override - public int getLightLevel(LightType p_226658_1_, BlockPos p_226658_2_) { + public int getLightLevel(@Nullable LightType p_226658_1_, @Nullable BlockPos p_226658_2_) { return 15; } @Override + @Nonnull public BlockState getBlockState(BlockPos pos) { return Blocks.AIR.getDefaultState(); }