From 31bd6865fc8cb64b5c53eb41942fb76494bb6a0b Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 26 Jun 2021 23:46:10 -0700 Subject: [PATCH] Custom lighting refactor and JEI tweaks - Create ILightingSettings and CustomLightingSettings to better manage custom lighting - Allow item GuiGameElements to have custom lighting - Add defaultBlockElement methods to automatically apply default custom lighting to JEI scenes - Add blaze head bobbing to JEI scenes - Shift elements on JEI washing scene - Use an empty screen instead of creating a new one in IScreenRenderable --- .../jei/category/FanSmokingCategory.java | 5 +- .../jei/category/FanWashingCategory.java | 10 +-- .../category/ProcessingViaFanCategory.java | 3 + .../animations/AnimatedBlazeBurner.java | 22 ++--- .../category/animations/AnimatedCrafter.java | 5 +- .../animations/AnimatedCrushingWheels.java | 12 ++- .../category/animations/AnimatedDeployer.java | 12 ++- .../animations/AnimatedItemDrain.java | 5 +- .../category/animations/AnimatedKinetics.java | 20 ++++- .../animations/AnimatedMillstone.java | 5 +- .../category/animations/AnimatedMixer.java | 11 ++- .../category/animations/AnimatedPress.java | 9 +- .../jei/category/animations/AnimatedSaw.java | 7 +- .../category/animations/AnimatedSpout.java | 15 ++-- .../gui/CustomLightingSettings.java | 83 +++++++++++++++++++ .../create/foundation/gui/GuiGameElement.java | 73 +++++++--------- .../foundation/gui/ILightingSettings.java | 12 +++ .../foundation/gui/IScreenRenderable.java | 6 +- .../create/foundation/gui/UIRenderHelper.java | 12 +-- 19 files changed, 200 insertions(+), 127 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java create mode 100644 src/main/java/com/simibubi/create/foundation/gui/ILightingSettings.java diff --git a/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java index 41af4afed..2cfbbfdd7 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java @@ -21,11 +21,10 @@ public class FanSmokingCategory extends ProcessingViaFanCategory @Override public void renderAttachedBlock(MatrixStack matrixStack) { - GuiGameElement.of(Blocks.FIRE.getDefaultState()) .scale(24) .atLocal(0, 0, 2) .render(matrixStack); - } -} \ No newline at end of file + +} diff --git a/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java index 8af3d75af..d6bb5a96d 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java @@ -49,7 +49,7 @@ public class FanWashingCategory extends ProcessingViaFanCategory 9 ? 8 : 0); - getRenderedSlot(recipe, i).draw(matrixStack, 121 + xOffset, 47 + yOffset); + getRenderedSlot(recipe, i).draw(matrixStack, 126 + xOffset, 47 + yOffset); } } @Override protected void translateFan(MatrixStack ms) { - ms.translate(43, 33, 0); + ms.translate(56 + 4, 33, 0); } @Override diff --git a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java index 69b2292d8..ace3e71e2 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java @@ -68,6 +68,7 @@ public abstract class ProcessingViaFanCategory> extends Cre if (matrixStack == null) return; renderWidgets(matrixStack, recipe, mouseX, mouseY); + matrixStack.push(); translateFan(matrixStack); matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-12.5f)); @@ -77,12 +78,14 @@ public abstract class ProcessingViaFanCategory> extends Cre GuiGameElement.of(AllBlockPartials.ENCASED_FAN_INNER) .rotateBlock(180, 0, AnimatedKinetics.getCurrentAngle() * 16) .scale(scale) + .lighting(AnimatedKinetics.DEFAULT_LIGHTING) .render(matrixStack); GuiGameElement.of(AllBlocks.ENCASED_FAN.getDefaultState()) .rotateBlock(0, 180, 0) .atLocal(0, 0, 0) .scale(scale) + .lighting(AnimatedKinetics.DEFAULT_LIGHTING) .render(matrixStack); renderAttachedBlock(matrixStack); 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 8d448783d..6757ced6d 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 @@ -5,12 +5,12 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; -import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.utility.AnimationTickHolder; -import mezz.jei.api.gui.drawable.IDrawable; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3f; -public class AnimatedBlazeBurner implements IDrawable { +public class AnimatedBlazeBurner extends AnimatedKinetics { private HeatLevel heatLevel; @@ -26,14 +26,15 @@ public class AnimatedBlazeBurner implements IDrawable { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 23; - GuiGameElement.of(AllBlocks.BLAZE_BURNER.getDefaultState()) + defaultBlockElement(AllBlocks.BLAZE_BURNER.getDefaultState()) .atLocal(0, 1.65, 0) .scale(scale) .render(matrixStack); + float offset = (MathHelper.sin(AnimationTickHolder.getRenderTime() / 16f) + 0.5f) / 16f; PartialModel blaze = AllBlockPartials.BLAZES.get(heatLevel); - GuiGameElement.of(blaze) - .atLocal(1, 1.65, 1) + defaultBlockElement(blaze) + .atLocal(1, 1.65 + offset, 1) .rotate(0, 180, 0) .scale(scale) .render(matrixStack); @@ -41,13 +42,4 @@ public class AnimatedBlazeBurner implements IDrawable { matrixStack.pop(); } - @Override - public int getWidth() { - return 50; - } - - @Override - public int getHeight() { - return 50; - } } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java index 826e1d9ec..525558289 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java @@ -3,7 +3,6 @@ package com.simibubi.create.compat.jei.category.animations; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.gui.AllGuiTextures; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.MatrixStacker; public class AnimatedCrafter extends AnimatedKinetics { @@ -20,12 +19,12 @@ public class AnimatedCrafter extends AnimatedKinetics { .rotateY(-22.5f); int scale = 22; - GuiGameElement.of(cogwheel()) + defaultBlockElement(cogwheel()) .rotateBlock(90, 0, getCurrentAngle()) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlocks.MECHANICAL_CRAFTER.getDefaultState()) + defaultBlockElement(AllBlocks.MECHANICAL_CRAFTER.getDefaultState()) .rotateBlock(0, 180, 0) .scale(scale) .render(matrixStack); 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 263add564..eecc33882 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 @@ -2,7 +2,6 @@ package com.simibubi.create.compat.jei.category.animations; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.gui.GuiGameElement; import net.minecraft.block.BlockState; import net.minecraft.state.properties.BlockStateProperties; @@ -11,6 +10,9 @@ import net.minecraft.util.math.vector.Vector3f; public class AnimatedCrushingWheels extends AnimatedKinetics { + private final BlockState wheel = AllBlocks.CRUSHING_WHEEL.getDefaultState() + .with(BlockStateProperties.AXIS, Axis.X); + @Override public void draw(MatrixStack matrixStack, int xOffset, int yOffset) { matrixStack.push(); @@ -18,16 +20,12 @@ public class AnimatedCrushingWheels extends AnimatedKinetics { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-22.5f)); int scale = 22; - BlockState wheel = AllBlocks.CRUSHING_WHEEL.get() - .getDefaultState() - .with(BlockStateProperties.AXIS, Axis.X); - - GuiGameElement.of(wheel) + defaultBlockElement(wheel) .rotateBlock(0, 90, -getCurrentAngle()) .scale(scale) .render(matrixStack); - GuiGameElement.of(wheel) + defaultBlockElement(wheel) .rotateBlock(0, 90, getCurrentAngle()) .atLocal(2, 0, 0) .scale(scale) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedDeployer.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedDeployer.java index 862e94194..b71bcd27b 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedDeployer.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedDeployer.java @@ -4,12 +4,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.deployer.DeployerBlock; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3f; public class AnimatedDeployer extends AnimatedKinetics { @@ -22,12 +20,12 @@ public class AnimatedDeployer extends AnimatedKinetics { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 20; - GuiGameElement.of(shaft(Axis.Z)) + defaultBlockElement(shaft(Axis.Z)) .rotateBlock(0, 0, getCurrentAngle()) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlocks.DEPLOYER.getDefaultState() + defaultBlockElement(AllBlocks.DEPLOYER.getDefaultState() .with(DeployerBlock.FACING, Direction.DOWN) .with(DeployerBlock.AXIS_ALONG_FIRST_COORDINATE, false)) .scale(scale) @@ -39,18 +37,18 @@ public class AnimatedDeployer extends AnimatedKinetics { matrixStack.push(); matrixStack.translate(0, offset * 17, 0); - GuiGameElement.of(AllBlockPartials.DEPLOYER_POLE) + defaultBlockElement(AllBlockPartials.DEPLOYER_POLE) .rotateBlock(90, 0, 0) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlockPartials.DEPLOYER_HAND_HOLDING) + defaultBlockElement(AllBlockPartials.DEPLOYER_HAND_HOLDING) .rotateBlock(90, 0, 0) .scale(scale) .render(matrixStack); matrixStack.pop(); - GuiGameElement.of(AllBlocks.DEPOT.getDefaultState()) + defaultBlockElement(AllBlocks.DEPOT.getDefaultState()) .atLocal(0, 2, 0) .scale(scale) .render(matrixStack); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedItemDrain.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedItemDrain.java index 41bed07e1..7bb1e0126 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedItemDrain.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedItemDrain.java @@ -3,7 +3,6 @@ package com.simibubi.create.compat.jei.category.animations; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.fluid.FluidRenderer; -import com.simibubi.create.foundation.gui.GuiGameElement; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer.Impl; @@ -28,7 +27,7 @@ public class AnimatedItemDrain extends AnimatedKinetics { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 20; - GuiGameElement.of(AllBlocks.ITEM_DRAIN.getDefaultState()) + defaultBlockElement(AllBlocks.ITEM_DRAIN.getDefaultState()) .scale(scale) .render(matrixStack); @@ -38,7 +37,7 @@ public class AnimatedItemDrain extends AnimatedKinetics { ms.scale(scale, -scale, scale); float from = 2/16f; float to = 1f - from; - FluidRenderer.renderTiledFluidBB(fluid, from, from, from, to, 3/4f, to, buffer, ms, 0xf000f0, false); + FluidRenderer.renderTiledFluidBB(fluid, from, from, from, to, 3/4f, to, buffer, ms, 0xF000F0, false); buffer.draw(); matrixStack.pop(); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java index fe8a3c37f..3aec8dd85 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java @@ -3,6 +3,9 @@ package com.simibubi.create.compat.jei.category.animations; import com.jozufozu.flywheel.core.PartialModel; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.gui.CustomLightingSettings; +import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.gui.ILightingSettings; import com.simibubi.create.foundation.utility.AnimationTickHolder; import mezz.jei.api.gui.drawable.IDrawable; @@ -12,8 +15,13 @@ import net.minecraft.util.Direction.Axis; public abstract class AnimatedKinetics implements IDrawable { + public static final ILightingSettings DEFAULT_LIGHTING = CustomLightingSettings.builder() + .firstLightRotation(12.5f, 45.0f) + .secondLightRotation(-20.0f, 50.0f) + .build(); + public static float getCurrentAngle() { - return ((AnimationTickHolder.getRenderTime()) * 4f) % 360; + return (AnimationTickHolder.getRenderTime() * 4f) % 360; } protected BlockState shaft(Axis axis) { @@ -24,6 +32,16 @@ public abstract class AnimatedKinetics implements IDrawable { return AllBlockPartials.SHAFTLESS_COGWHEEL; } + protected GuiGameElement.GuiRenderBuilder defaultBlockElement(BlockState state) { + return GuiGameElement.of(state) + .lighting(DEFAULT_LIGHTING); + } + + protected GuiGameElement.GuiRenderBuilder defaultBlockElement(PartialModel partial) { + return GuiGameElement.of(partial) + .lighting(DEFAULT_LIGHTING); + } + @Override public int getWidth() { return 50; diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java index 8e98eb372..147d9b2c4 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.gui.AllGuiTextures; -import com.simibubi.create.foundation.gui.GuiGameElement; public class AnimatedMillstone extends AnimatedKinetics { @@ -16,12 +15,12 @@ public class AnimatedMillstone extends AnimatedKinetics { matrixStack.translate(-2, 18, 0); int scale = 22; - GuiGameElement.of(AllBlockPartials.MILLSTONE_COG) + defaultBlockElement(AllBlockPartials.MILLSTONE_COG) .rotateBlock(22.5, getCurrentAngle() * 2, 0) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlocks.MILLSTONE.getDefaultState()) + defaultBlockElement(AllBlocks.MILLSTONE.getDefaultState()) .rotateBlock(22.5, 22.5, 0) .scale(scale) .render(matrixStack); 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 5359d7b76..05f9b806e 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 @@ -3,7 +3,6 @@ package com.simibubi.create.compat.jei.category.animations; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.math.MathHelper; @@ -19,31 +18,31 @@ public class AnimatedMixer extends AnimatedKinetics { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 23; - GuiGameElement.of(cogwheel()) + defaultBlockElement(cogwheel()) .rotateBlock(0, getCurrentAngle() * 2, 0) .atLocal(0, 0, 0) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlocks.MECHANICAL_MIXER.getDefaultState()) + defaultBlockElement(AllBlocks.MECHANICAL_MIXER.getDefaultState()) .atLocal(0, 0, 0) .scale(scale) .render(matrixStack); float animation = ((MathHelper.sin(AnimationTickHolder.getRenderTime() / 32f) + 1) / 5) + .5f; - GuiGameElement.of(AllBlockPartials.MECHANICAL_MIXER_POLE) + defaultBlockElement(AllBlockPartials.MECHANICAL_MIXER_POLE) .atLocal(0, animation, 0) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlockPartials.MECHANICAL_MIXER_HEAD) + defaultBlockElement(AllBlockPartials.MECHANICAL_MIXER_HEAD) .rotateBlock(0, getCurrentAngle() * 4, 0) .atLocal(0, animation, 0) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlocks.BASIN.getDefaultState()) + defaultBlockElement(AllBlocks.BASIN.getDefaultState()) .atLocal(0, 1.65, 0) .scale(scale) .render(matrixStack); 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 a7e1d262a..5ca8f159d 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 @@ -3,7 +3,6 @@ package com.simibubi.create.compat.jei.category.animations; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.Direction.Axis; @@ -25,22 +24,22 @@ public class AnimatedPress extends AnimatedKinetics { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = basin ? 20 : 24; - GuiGameElement.of(shaft(Axis.Z)) + defaultBlockElement(shaft(Axis.Z)) .rotateBlock(0, 0, getCurrentAngle()) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlocks.MECHANICAL_PRESS.getDefaultState()) + defaultBlockElement(AllBlocks.MECHANICAL_PRESS.getDefaultState()) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlockPartials.MECHANICAL_PRESS_HEAD) + defaultBlockElement(AllBlockPartials.MECHANICAL_PRESS_HEAD) .atLocal(0, -getAnimatedHeadOffset(), 0) .scale(scale) .render(matrixStack); if (basin) - GuiGameElement.of(AllBlocks.BASIN.getDefaultState()) + defaultBlockElement(AllBlocks.BASIN.getDefaultState()) .atLocal(0, 1.65, 0) .scale(scale) .render(matrixStack); 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 a13365b2e..b92e8cd2a 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 @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.saw.SawBlock; import com.simibubi.create.foundation.gui.AllGuiTextures; -import com.simibubi.create.foundation.gui.GuiGameElement; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; @@ -25,18 +24,18 @@ public class AnimatedSaw extends AnimatedKinetics { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90 - 225f)); int scale = 25; - GuiGameElement.of(shaft(Axis.X)) + defaultBlockElement(shaft(Axis.X)) .rotateBlock(-getCurrentAngle(), 0, 0) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlocks.MECHANICAL_SAW.getDefaultState() + defaultBlockElement(AllBlocks.MECHANICAL_SAW.getDefaultState() .with(SawBlock.FACING, Direction.UP)) .rotateBlock(0, 0, 0) .scale(scale) .render(matrixStack); - GuiGameElement.of(AllBlockPartials.SAW_BLADE_VERTICAL_ACTIVE) + defaultBlockElement(AllBlockPartials.SAW_BLADE_VERTICAL_ACTIVE) .rotateBlock(0, -90, -90) .scale(scale) .render(matrixStack); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java index 40f23c032..1f412683d 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java @@ -6,7 +6,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.fluid.FluidRenderer; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -33,7 +32,7 @@ public class AnimatedSpout extends AnimatedKinetics { matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(22.5f)); int scale = 20; - GuiGameElement.of(AllBlocks.SPOUT.getDefaultState()) + defaultBlockElement(AllBlocks.SPOUT.getDefaultState()) .scale(scale) .render(matrixStack); @@ -43,22 +42,22 @@ public class AnimatedSpout extends AnimatedKinetics { matrixStack.push(); - GuiGameElement.of(AllBlockPartials.SPOUT_TOP) + defaultBlockElement(AllBlockPartials.SPOUT_TOP) .scale(scale) .render(matrixStack); matrixStack.translate(0, -3 * squeeze / 32f, 0); - GuiGameElement.of(AllBlockPartials.SPOUT_MIDDLE) + defaultBlockElement(AllBlockPartials.SPOUT_MIDDLE) .scale(scale) .render(matrixStack); matrixStack.translate(0, -3 * squeeze / 32f, 0); - GuiGameElement.of(AllBlockPartials.SPOUT_BOTTOM) + defaultBlockElement(AllBlockPartials.SPOUT_BOTTOM) .scale(scale) .render(matrixStack); matrixStack.translate(0, -3 * squeeze / 32f, 0); matrixStack.pop(); - GuiGameElement.of(AllBlocks.DEPOT.getDefaultState()) + defaultBlockElement(AllBlocks.DEPOT.getDefaultState()) .atLocal(0, 2, 0) .scale(scale) .render(matrixStack); @@ -69,14 +68,14 @@ public class AnimatedSpout extends AnimatedKinetics { matrixStack.scale(16, -16, 16); float from = 2/16f; float to = 1f - from; - FluidRenderer.renderTiledFluidBB(fluids.get(0), from, from, from, to, to, to, buffer, matrixStack, 0xf000f0, false); + FluidRenderer.renderTiledFluidBB(fluids.get(0), from, from, from, to, to, to, buffer, matrixStack, 0xF000F0, false); matrixStack.pop(); float width = 1 / 128f * squeeze; matrixStack.translate(scale / 2f, scale * 1.5f, scale / 2f); matrixStack.scale(16, -16, 16); matrixStack.translate(-width / 2, 0, -width / 2); - FluidRenderer.renderTiledFluidBB(fluids.get(0), 0, -0.001f, 0, width, 2.001f, width, buffer, matrixStack, 0xf000f0, + FluidRenderer.renderTiledFluidBB(fluids.get(0), 0, -0.001f, 0, width, 2.001f, width, buffer, matrixStack, 0xF000F0, false); buffer.draw(); diff --git a/src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java b/src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java new file mode 100644 index 000000000..a66e908b0 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java @@ -0,0 +1,83 @@ +package com.simibubi.create.foundation.gui; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.simibubi.create.foundation.utility.VecHelper; + +import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3f; + +public class CustomLightingSettings implements ILightingSettings { + + private Vector3f light1; + private Vector3f light2; + private Matrix4f lightMatrix; + + protected CustomLightingSettings(float yRot, float xRot) { + init(yRot, xRot, 0, 0, false); + } + + protected CustomLightingSettings(float yRot1, float xRot1, float yRot2, float xRot2) { + init(yRot1, xRot1, yRot2, xRot2, true); + } + + protected void init(float yRot1, float xRot1, float yRot2, float xRot2, boolean doubleLight) { + light1 = Vector3f.POSITIVE_Z.copy(); + light1.func_214905_a(Vector3f.POSITIVE_Y.getDegreesQuaternion(yRot1)); + light1.func_214905_a(Vector3f.POSITIVE_X.getDegreesQuaternion(xRot1)); + + if (doubleLight) { + light2 = Vector3f.POSITIVE_Z.copy(); + light2.func_214905_a(Vector3f.POSITIVE_Y.getDegreesQuaternion(yRot2)); + light2.func_214905_a(Vector3f.POSITIVE_X.getDegreesQuaternion(xRot2)); + } else { + light2 = VecHelper.ZERO_3F; + } + + lightMatrix = new Matrix4f(); + lightMatrix.loadIdentity(); + } + + @Override + public void applyLighting() { + RenderSystem.setupLevelDiffuseLighting(light1, light2, lightMatrix); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private float yRot1, xRot1; + private float yRot2, xRot2; + private boolean doubleLight; + + public Builder firstLightRotation(float yRot, float xRot) { + yRot1 = yRot; + xRot1 = xRot; + return this; + } + + public Builder secondLightRotation(float yRot, float xRot) { + yRot2 = yRot; + xRot2 = xRot; + doubleLight = true; + return this; + } + + public Builder doubleLight() { + doubleLight = true; + return this; + } + + public CustomLightingSettings build() { + if (doubleLight) { + return new CustomLightingSettings(yRot1, xRot1, yRot2, xRot2); + } else { + return new CustomLightingSettings(yRot1, xRot1); + } + } + + } + +} 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 e1dfe6fb3..a7f88729c 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java @@ -35,15 +35,12 @@ import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.item.ItemStack; import net.minecraft.util.IItemProvider; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Vector2f; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3f; import net.minecraftforge.fluids.FluidStack; public class GuiGameElement { - public static Vector2f defaultBlockLighting = new Vector2f(30.0f, 7.5f); - public static GuiRenderBuilder of(ItemStack stack) { return new GuiItemRenderBuilder(stack); } @@ -72,8 +69,7 @@ public class GuiGameElement { protected double scale = 1; protected int color = 0xFFFFFF; protected Vector3d rotationOffset = Vector3d.ZERO; - protected boolean hasCustomLighting = false; - protected float lightingXRot, lightingYRot; + protected ILightingSettings customLighting = null; public GuiRenderBuilder atLocal(double x, double y, double z) { this.xLocal = x; @@ -109,15 +105,11 @@ public class GuiGameElement { return this; } - public GuiRenderBuilder lighting(float xRot, float yRot) { - hasCustomLighting = true; - lightingXRot = xRot; - lightingYRot = yRot; + public GuiRenderBuilder lighting(ILightingSettings lighting) { + customLighting = lighting; return this; } - public abstract void render(MatrixStack matrixStack); - protected void prepareMatrix(MatrixStack matrixStack) { matrixStack.push(); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -150,10 +142,17 @@ public class GuiGameElement { } protected void prepareLighting(MatrixStack matrixStack) { - RenderHelper.enableGuiDepthLighting(); + if (customLighting != null) { + customLighting.applyLighting(); + } else { + RenderHelper.enableGuiDepthLighting(); + } } protected void cleanUpLighting(MatrixStack matrixStack) { + if (customLighting != null) { + RenderHelper.enableGuiDepthLighting(); + } } } @@ -200,19 +199,6 @@ public class GuiGameElement { buffer.draw(); } - @Override - protected void prepareLighting(MatrixStack matrixStack) { - if (hasCustomLighting) { - UIRenderHelper.setupSimpleCustomLighting(lightingXRot, lightingYRot); - } else { - UIRenderHelper.setupSimpleCustomLighting(defaultBlockLighting.x, defaultBlockLighting.y); - } - } - - @Override - protected void cleanUpLighting(MatrixStack matrixStack) { - RenderHelper.enableGuiDepthLighting(); - } } public static class GuiBlockStateRenderBuilder extends GuiBlockModelRenderBuilder { @@ -244,7 +230,7 @@ public class GuiGameElement { ms.push(); RenderHelper.disableStandardItemLighting(); FluidRenderer.renderTiledFluidBB(new FluidStack(blockState.getFluidState() - .getFluid(), 1000), 0, 0, 0, 1.0001f, 1.0001f, 1.0001f, buffer, ms, 0xf000f0, true); + .getFluid(), 1000), 0, 0, 0, 1.0001f, 1.0001f, 1.0001f, buffer, ms, 0xF000F0, true); buffer.draw(RenderType.getTranslucent()); RenderHelper.enable(); ms.pop(); @@ -275,43 +261,42 @@ public class GuiGameElement { public void render(MatrixStack matrixStack) { prepareMatrix(matrixStack); transformMatrix(matrixStack); - renderItemIntoGUI(matrixStack, stack); + renderItemIntoGUI(matrixStack, stack, customLighting == null); cleanUpMatrix(matrixStack); } - public static void renderItemIntoGUI(MatrixStack matrixStack, ItemStack stack) { - ItemRenderer renderer = Minecraft.getInstance() - .getItemRenderer(); + public static void renderItemIntoGUI(MatrixStack matrixStack, ItemStack stack, boolean useDefaultLighting) { + ItemRenderer renderer = Minecraft.getInstance().getItemRenderer(); IBakedModel bakedModel = renderer.getItemModelWithOverrides(stack, null, null); + matrixStack.push(); renderer.textureManager.bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); - renderer.textureManager.getTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE) - .setBlurMipmapDirect(false, false); + renderer.textureManager.getTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE).setBlurMipmapDirect(false, false); RenderSystem.enableRescaleNormal(); RenderSystem.enableAlphaTest(); RenderSystem.enableCull(); RenderSystem.defaultAlphaFunc(); RenderSystem.enableBlend(); - RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, - GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - matrixStack.translate((float) 0, (float) 0, 100.0F + renderer.zLevel); + matrixStack.translate(0, 0, 100.0F + renderer.zLevel); matrixStack.translate(8.0F, -8.0F, 0.0F); matrixStack.scale(16.0F, 16.0F, 16.0F); - IRenderTypeBuffer.Impl buffer = Minecraft.getInstance() - .getBufferBuilders() - .getEntityVertexConsumers(); + IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getBufferBuilders().getEntityVertexConsumers(); boolean flatLighting = !bakedModel.isSideLit(); - if (flatLighting) { - RenderHelper.disableGuiDepthLighting(); + if (useDefaultLighting) { + if (flatLighting) { + RenderHelper.disableGuiDepthLighting(); + } } - renderer.renderItem(stack, ItemCameraTransforms.TransformType.GUI, false, matrixStack, - buffer, 0xF000F0, OverlayTexture.DEFAULT_UV, bakedModel); + renderer.renderItem(stack, ItemCameraTransforms.TransformType.GUI, false, matrixStack, buffer, 0xF000F0, OverlayTexture.DEFAULT_UV, bakedModel); buffer.draw(); RenderSystem.enableDepthTest(); - if (flatLighting) { - RenderHelper.enableGuiDepthLighting(); + if (useDefaultLighting) { + if (flatLighting) { + RenderHelper.enableGuiDepthLighting(); + } } RenderSystem.disableAlphaTest(); diff --git a/src/main/java/com/simibubi/create/foundation/gui/ILightingSettings.java b/src/main/java/com/simibubi/create/foundation/gui/ILightingSettings.java new file mode 100644 index 000000000..bd585d587 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/gui/ILightingSettings.java @@ -0,0 +1,12 @@ +package com.simibubi.create.foundation.gui; + +import net.minecraft.client.renderer.RenderHelper; + +public interface ILightingSettings { + + void applyLighting(); + + static final ILightingSettings DEFAULT_3D = () -> RenderHelper.enableGuiDepthLighting(); + static final ILightingSettings DEFAULT_FLAT = () -> RenderHelper.disableGuiDepthLighting(); + +} diff --git a/src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java b/src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java index 161bb01e2..bc1afb3ef 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java +++ b/src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java @@ -10,12 +10,14 @@ import net.minecraftforge.api.distmarker.OnlyIn; public interface IScreenRenderable { + Screen EMPTY_SCREEN = new Screen(new StringTextComponent("")) {}; + @OnlyIn(Dist.CLIENT) void draw(MatrixStack ms, AbstractGui screen, int x, int y); @OnlyIn(Dist.CLIENT) default void draw(MatrixStack ms, int x, int y) { - draw(ms, new Screen(new StringTextComponent("")) { - }, x, y); + draw(ms, EMPTY_SCREEN, x, y); } + } diff --git a/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java b/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java index 23adb2cc2..562751419 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.gui; -import java.awt.*; +import java.awt.Color; import javax.annotation.Nonnull; @@ -10,7 +10,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Couple; -import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; @@ -269,13 +268,4 @@ public class UIRenderHelper { WorldVertexBufferUploader.draw(bufferbuilder); } - public static void setupSimpleCustomLighting(float xRot, float yRot) { - Matrix4f lightingMatrix = new Matrix4f(); - lightingMatrix.loadIdentity(); - lightingMatrix.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(yRot)); - lightingMatrix.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(xRot)); - lightingMatrix.multiply(Matrix4f.translate(0, 0, 1)); - RenderSystem.setupLevelDiffuseLighting(VecHelper.ZERO_3F, VecHelper.ZERO_3F, lightingMatrix); - } - }