From ebd20f5173459d081f1065c719a48985605af9e2 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 23 Jan 2021 23:07:12 -0800 Subject: [PATCH] suddenly, everything is smooth and dry - replace all usages of Minecraft.getRenderPartialTicks() with AnimationTickHolder.getPartialTicks() - refactor stabilized and mounted lighters into one class - separate fancy contraption render logic and entity render logic, should maybe move *all* rendering to ContraptionRenderDispatcher --- .../category/animations/AnimatedKinetics.java | 4 +- .../category/animations/AnimatedPress.java | 8 +-- .../category/animations/AnimatedSpout.java | 14 +++-- .../PortableStorageInterfaceRenderer.java | 44 ++++++++-------- .../components/deployer/DeployerRenderer.java | 3 +- .../AbstractContraptionEntityRenderer.java | 20 +++++--- .../structureMovement/Contraption.java | 51 ++++++------------- ...Lighter.java => NonStationaryLighter.java} | 6 +-- .../StabilizedBearingMovementBehaviour.java | 14 ++--- .../bearing/StabilizedContraption.java | 17 ++----- .../bearing/StabilizedLighter.java | 37 -------------- .../glue/SuperGlueEntity.java | 32 +++--------- .../mounted/MountedContraption.java | 17 +++---- .../train/CouplingRenderer.java | 13 ++--- .../turntable/TurntableHandler.java | 4 +- .../curiosities/ChromaticCompoundColor.java | 3 +- .../curiosities/tools/ExtendoGripItem.java | 8 +-- .../tools/ExtendoGripItemRenderer.java | 8 ++- .../tools/ExtendoGripRenderHandler.java | 8 +-- .../tools/SandPaperItemRenderer.java | 3 +- .../zapper/ZapperRenderHandler.java | 15 +++--- .../blockzapper/BlockzapperItemRenderer.java | 16 ++---- .../WorldshaperItemRenderer.java | 10 ++-- .../client/SchematicAndQuillHandler.java | 40 +++++---------- .../schematics/client/SchematicHandler.java | 14 +++-- .../client/SchematicTransformation.java | 16 +++--- .../schematics/client/tools/DeployTool.java | 6 +-- .../client/tools/SchematicToolBase.java | 11 ++-- .../simibubi/create/events/ClientEvents.java | 2 +- .../render/TileEntityRenderHelper.java | 5 +- .../ContraptionRenderDispatcher.java | 45 ++++++++++++++-- .../utility/outliner/ChasingAABBOutline.java | 6 +-- .../utility/outliner/LineOutline.java | 6 +-- .../foundation/utility/outliner/Outliner.java | 15 ++---- 34 files changed, 204 insertions(+), 317 deletions(-) rename src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/{mounted/MountedLighter.java => NonStationaryLighter.java} (84%) delete mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java 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 33fe15a29..4339372d5 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,17 +3,15 @@ package com.simibubi.create.compat.jei.category.animations; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.utility.AnimationTickHolder; - import mezz.jei.api.gui.drawable.IDrawable; import net.minecraft.block.BlockState; -import net.minecraft.client.Minecraft; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction.Axis; public abstract class AnimatedKinetics implements IDrawable { public static float getCurrentAngle() { - return ((AnimationTickHolder.ticks + Minecraft.getInstance().getRenderPartialTicks()) * 4f) % 360; + return ((AnimationTickHolder.ticks + AnimationTickHolder.getPartialTicks()) * 4f) % 360; } protected BlockState shaft(Axis axis) { 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 4bafd18ed..7b2d99c6e 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 @@ -1,13 +1,10 @@ package com.simibubi.create.compat.jei.category.animations; -import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks; - import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.gui.GuiGameElement; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.Direction.Axis; public class AnimatedPress extends AnimatedKinetics { @@ -50,8 +47,7 @@ public class AnimatedPress extends AnimatedKinetics { } private float getAnimatedHeadOffset() { - float cycle = (ticks + Minecraft.getInstance() - .getRenderPartialTicks()) % 30; + float cycle = (AnimationTickHolder.getRenderTick()) % 30; if (cycle < 10) { float progress = cycle / 10; return -(progress * progress * progress); 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 32869ff0a..ad1ae4522 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 @@ -1,23 +1,22 @@ package com.simibubi.create.compat.jei.category.animations; -import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks; - -import java.util.List; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; 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 net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer.Impl; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fluids.FluidStack; +import java.util.List; + +import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks; + public class AnimatedSpout extends AnimatedKinetics { private List fluids; @@ -39,8 +38,7 @@ public class AnimatedSpout extends AnimatedKinetics { .scale(scale) .render(); - float cycle = (ticks + Minecraft.getInstance() - .getRenderPartialTicks()) % 30; + float cycle = (ticks + AnimationTickHolder.getPartialTicks()) % 30; float squeeze = cycle < 20 ? MathHelper.sin((float) (cycle / 20f * Math.PI)) : 0; squeeze *= 20; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java index 83f29fb32..9644fd71a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java @@ -1,19 +1,16 @@ package com.simibubi.create.content.contraptions.components.actors; -import java.util.function.Consumer; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.SuperByteBuffer; - import net.minecraft.block.BlockState; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -22,6 +19,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import java.util.function.Consumer; + public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer { public PortableStorageInterfaceRenderer(TileEntityRendererDispatcher dispatcher) { @@ -43,8 +42,7 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer drawCallback, MatrixStack... matrixStacks) { for (MatrixStack ms : matrixStacks) @@ -109,6 +91,22 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer double distance = context.position.distanceTo(center); double nextDistance = context.position.add(context.motion) .distanceTo(center); - factor = .5f - MathHelper.clamp(MathHelper.lerp(Minecraft.getInstance() - .getRenderPartialTicks(), distance, nextDistance), 0, 1); + factor = .5f - MathHelper.clamp(MathHelper.lerp(AnimationTickHolder.getPartialTicks(), distance, nextDistance), 0, 1); } Vec3d offset = new Vec3d(blockState.get(FACING) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index bb0e58296..3d5801a0a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -1,9 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; - -import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -24,6 +22,14 @@ public abstract class AbstractContraptionEntityRenderer { - public MountedLighter(MountedContraption contraption) { +public class NonStationaryLighter extends ContraptionLighter { + public NonStationaryLighter(C contraption) { super(contraption); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index d6b4c99e8..dc9a28356 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -2,15 +2,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; -import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.content.contraptions.components.structureMovement.*; import com.simibubi.create.foundation.render.SuperByteBuffer; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.state.properties.BlockStateProperties; @@ -28,8 +23,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { Direction facing = context.state.get(BlockStateProperties.FACING); AllBlockPartials top = AllBlockPartials.BEARING_TOP; SuperByteBuffer superBuffer = top.renderOn(context.state); - float renderPartialTicks = Minecraft.getInstance() - .getRenderPartialTicks(); + float renderPartialTicks = AnimationTickHolder.getPartialTicks(); // rotate to match blockstate Axis axis = facing.getAxis(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index 92b4e8298..5bb70f602 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -1,31 +1,22 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; - +import com.simibubi.create.content.contraptions.components.structureMovement.NonStationaryLighter; import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.utility.NBTHelper; -import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import java.util.UUID; - public class StabilizedContraption extends Contraption { - public UUID parentID; - private Direction facing; public StabilizedContraption() {} - public StabilizedContraption(UUID parentID, Direction facing) { - this.parentID = parentID; + public StabilizedContraption(Direction facing) { this.facing = facing; } @@ -55,14 +46,12 @@ public class StabilizedContraption extends Contraption { public CompoundNBT writeNBT(boolean spawnPacket) { CompoundNBT tag = super.writeNBT(spawnPacket); tag.putInt("Facing", facing.getIndex()); - tag.putUniqueId("Parent", parentID); return tag; } @Override public void readNBT(World world, CompoundNBT tag, boolean spawnData) { facing = Direction.byIndex(tag.getInt("Facing")); - parentID = tag.getUniqueId("Parent"); super.readNBT(world, tag, spawnData); } @@ -77,6 +66,6 @@ public class StabilizedContraption extends Contraption { @Override public ContraptionLighter makeLighter() { - return new StabilizedLighter(this); + return new NonStationaryLighter<>(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java deleted file mode 100644 index b92901b77..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.simibubi.create.content.contraptions.components.structureMovement.bearing; - -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.GridAlignedBB; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Vec3i; - -import java.util.List; - -public class StabilizedLighter extends ContraptionLighter { - public StabilizedLighter(StabilizedContraption contraption) { - super(contraption); - } - - @Override - public void tick(RenderedContraption owner) { - GridAlignedBB contraptionBounds = getContraptionBounds(); - - if (!contraptionBounds.sameAs(bounds)) { - lightVolume.move(contraption.entity.world, contraptionBoundsToVolume(contraptionBounds)); - bounds = contraptionBounds; - } - } - - @Override - public GridAlignedBB getContraptionBounds() { - GridAlignedBB bb = GridAlignedBB.fromAABB(contraption.bounds); - - bb.translate(contraption.entity.getPosition()); - - return bb; - } -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index f677487af..b9f5ab8dc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -1,9 +1,5 @@ package com.simibubi.create.content.contraptions.components.structureMovement.glue; -import javax.annotation.Nullable; - -import org.apache.commons.lang3.Validate; - import com.simibubi.create.AllEntityTypes; import com.simibubi.create.AllItems; import com.simibubi.create.AllSoundEvents; @@ -12,17 +8,13 @@ import com.simibubi.create.content.schematics.ISpecialEntityItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType; import com.simibubi.create.foundation.networking.AllPackets; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.BlockFace; - import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntitySize; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.Pose; +import net.minecraft.entity.*; import net.minecraft.entity.effect.LightningBoltEntity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; @@ -30,20 +22,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.IPacket; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Direction; +import net.minecraft.util.*; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.Hand; -import net.minecraft.util.Mirror; -import net.minecraft.util.Rotation; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.*; import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; @@ -52,6 +33,9 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.PacketDistributor; +import org.apache.commons.lang3.Validate; + +import javax.annotation.Nullable; public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnData, ISpecialEntityItemRequirement { @@ -266,7 +250,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat ClientPlayerEntity cPlayer = (ClientPlayerEntity) player; Minecraft mc = Minecraft.getInstance(); RayTraceResult ray = - cPlayer.pick(mc.playerController.getBlockReachDistance(), mc.getRenderPartialTicks(), false); + cPlayer.pick(mc.playerController.getBlockReachDistance(), AnimationTickHolder.getPartialTicks(), false); if (!(ray instanceof BlockRayTraceResult)) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index 38406550a..f13e6cb39 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -1,20 +1,14 @@ package com.simibubi.create.content.contraptions.components.structureMovement.mounted; -import static com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock.RAIL_SHAPE; - -import java.util.List; - -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import org.apache.commons.lang3.tuple.Pair; - import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.NonStationaryLighter; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity.CartMovementMode; +import com.simibubi.create.foundation.render.light.ContraptionLighter; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.minecart.AbstractMinecartEntity; @@ -33,6 +27,11 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.wrapper.CombinedInvWrapper; import net.minecraftforge.items.wrapper.InvWrapper; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.List; + +import static com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock.RAIL_SHAPE; public class MountedContraption extends Contraption { @@ -164,6 +163,6 @@ public class MountedContraption extends Contraption { @Override public ContraptionLighter makeLighter() { - return new MountedLighter(this); + return new NonStationaryLighter<>(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java index 0a8cb17b8..34a52daa3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java @@ -1,19 +1,13 @@ package com.simibubi.create.content.contraptions.components.structureMovement.train; -import static net.minecraft.util.math.MathHelper.lerp; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController; -import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.Couple; -import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.VecHelper; - +import com.simibubi.create.foundation.utility.*; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.Minecraft; @@ -28,6 +22,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import static net.minecraft.util.math.MathHelper.lerp; + public class CouplingRenderer { public static void renderAll(MatrixStack ms, IRenderTypeBuffer buffer) { @@ -115,8 +111,7 @@ public class CouplingRenderer { float y = (((float) (i >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F + 0.375F; float z = (((float) (i >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F; - float pt = Minecraft.getInstance() - .getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); double xIn = lerp(pt, cart.lastTickPosX, cart.getX()); double yIn = lerp(pt, cart.lastTickPosY, cart.getY()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java index a3ba8aaf9..d335edaf3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.turntable; import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.client.Minecraft; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -38,7 +38,7 @@ public class TurntableHandler { if (offset.length() > 1/4f) speed *= MathHelper.clamp((1/2f - offset.length()) * 2, 0, 1); - mc.player.rotationYaw = mc.player.prevRotationYaw - speed * mc.getRenderPartialTicks(); + mc.player.rotationYaw = mc.player.prevRotationYaw - speed * AnimationTickHolder.getPartialTicks(); mc.player.renderYawOffset = mc.player.rotationYaw; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java index 34b5b503d..60ba0545c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java +++ b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.curiosities; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; - import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.item.ItemStack; @@ -13,7 +12,7 @@ public class ChromaticCompoundColor implements IItemColor { @Override public int getColor(ItemStack stack, int layer) { Minecraft mc = Minecraft.getInstance(); - float pt = mc.getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); float progress = (float) ((mc.player.getYaw(pt)) / 180 * Math.PI) + (AnimationTickHolder.getRenderTick() / 10f); if (layer == 0) return ColorHelper.mixColors(0x6e5773, 0x6B3074, ((float) MathHelper.sin(progress) + 1) / 2); diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java index a74a092a0..dd9f57c99 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java @@ -1,13 +1,11 @@ package com.simibubi.create.content.curiosities.tools; -import java.util.UUID; - import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.networking.AllPackets; - +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.entity.Entity; @@ -35,6 +33,8 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import java.util.UUID; + @EventBusSubscriber public class ExtendoGripItem extends Item { @@ -125,7 +125,7 @@ public class ExtendoGripItem extends Item { .getValue(); if (!player.isCreative()) d0 -= 0.5f; - Vec3d vec3d = player.getEyePosition(mc.getRenderPartialTicks()); + Vec3d vec3d = player.getEyePosition(AnimationTickHolder.getPartialTicks()); Vec3d vec3d1 = player.getLook(1.0F); Vec3d vec3d2 = vec3d.add(vec3d1.x * d0, vec3d1.y * d0, vec3d1.z * d0); AxisAlignedBB axisalignedbb = player.getBoundingBox() diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java index 3788d6000..d37daa176 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java @@ -6,8 +6,6 @@ import com.simibubi.create.foundation.block.render.CustomRenderedItemModelRender import com.simibubi.create.foundation.item.PartialItemModelRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; - -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.item.ItemStack; @@ -28,9 +26,9 @@ public class ExtendoGripItemRenderer extends CustomRenderedItemModelRenderer mainHandAnimation && swingProgress > 0) mainHandAnimation = 0.95f; - float animation = MathHelper.lerp(Minecraft.getInstance() - .getRenderPartialTicks(), ExtendoGripRenderHandler.lastMainHandAnimation, - ExtendoGripRenderHandler.mainHandAnimation); + float animation = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), + ExtendoGripRenderHandler.lastMainHandAnimation, + ExtendoGripRenderHandler.mainHandAnimation); animation = animation * animation * animation; ms.translate(flip * (0.64000005F - .1f), -0.4F + equipProgress * -0.6F, -0.71999997F + .3f); 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 78b741a2b..8414e43c8 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 @@ -4,7 +4,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.foundation.block.render.CustomRenderedItemModel; import com.simibubi.create.foundation.utility.AnimationTickHolder; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -25,7 +24,7 @@ public class SandPaperItemRenderer extends ItemStackTileEntityRenderer { ClientPlayerEntity player = Minecraft.getInstance().player; SandPaperModel mainModel = (SandPaperModel) itemRenderer.getItemModelWithOverrides(stack, Minecraft.getInstance().world, null); TransformType perspective = mainModel.getCurrentPerspective(); - float partialTicks = Minecraft.getInstance().getRenderPartialTicks(); + float partialTicks = AnimationTickHolder.getPartialTicks(); boolean leftHand = perspective == TransformType.FIRST_PERSON_LEFT_HAND; boolean firstPerson = leftHand || perspective == TransformType.FIRST_PERSON_RIGHT_HAND; diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java index fe428b05d..2c8d579ce 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java @@ -1,14 +1,9 @@ package com.simibubi.create.content.curiosities.zapper; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.function.Supplier; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.CreateClient; - +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.AbstractClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity; @@ -30,6 +25,11 @@ import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.function.Supplier; + @EventBusSubscriber(value = Dist.CLIENT) public class ZapperRenderHandler { @@ -63,8 +63,7 @@ public class ZapperRenderHandler { } public static Vec3d getExactBarrelPos(boolean mainHand) { - float partialTicks = Minecraft.getInstance() - .getRenderPartialTicks(); + float partialTicks = AnimationTickHolder.getPartialTicks(); ClientPlayerEntity player = Minecraft.getInstance().player; float yaw = (float) ((player.getYaw(partialTicks)) / -180 * Math.PI); float pitch = (float) ((player.getPitch(partialTicks)) / -180 * Math.PI); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java index 3f05fca7f..6d8eaf1e7 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java @@ -1,20 +1,11 @@ package com.simibubi.create.content.curiosities.zapper.blockzapper; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Accelerator; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Amplifier; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Body; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Retriever; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Scope; -import static java.lang.Math.max; -import static net.minecraft.util.math.MathHelper.clamp; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.curiosities.zapper.ZapperItemRenderer; import com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.ComponentTier; import com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components; import com.simibubi.create.foundation.item.PartialItemModelRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -25,6 +16,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.HandSide; import net.minecraft.util.math.MathHelper; +import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.*; +import static java.lang.Math.max; +import static net.minecraft.util.math.MathHelper.clamp; + public class BlockzapperItemRenderer extends ZapperItemRenderer { @Override @@ -32,8 +27,7 @@ public class BlockzapperItemRenderer extends ZapperItemRenderer { @Override @@ -24,8 +23,7 @@ public class WorldshaperItemRenderer extends ZapperItemRenderer customRenderTEs, MatrixStack ms, MatrixStack localTransform, IRenderTypeBuffer buffer) { - float pt = Minecraft.getInstance() - .getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); Matrix4f matrix = localTransform.peek() .getModel(); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 6795420dc..8e85c187e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -1,26 +1,39 @@ package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; import com.simibubi.create.foundation.render.shader.Shader; import com.simibubi.create.foundation.render.shader.ShaderCallback; import com.simibubi.create.foundation.render.shader.ShaderHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererManager; +import net.minecraft.client.world.ClientWorld; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.World; -import org.lwjgl.opengl.*; +import net.minecraftforge.event.TickEvent; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL40; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; +import java.util.Map; public class ContraptionRenderDispatcher { public static final HashMap renderers = new HashMap<>(); - public static void markForRendering(World world, Contraption c, MatrixStack model) { - getRenderer(world, c).setRenderSettings(model.peek().getModel()); + public static void markForRendering(Contraption c, MatrixStack model) { + getRenderer(c.entity.world, c).setRenderSettings(model.peek().getModel()); } public static void notifyLightUpdate(ILightReader world, LightType type, SectionPos pos) { @@ -29,6 +42,31 @@ public class ContraptionRenderDispatcher { } } + public static void renderTick(TickEvent.RenderTickEvent event) { + ClientWorld world = Minecraft.getInstance().world; + if (event.phase == TickEvent.Phase.START && world != null) { + Map> map = ContraptionHandler.loadedContraptions.get(world); + + for (WeakReference weakReference : map.values()) { + AbstractContraptionEntity entity = weakReference.get(); + + EntityRendererManager renderManager = Minecraft.getInstance().getRenderManager(); + + EntityRenderer renderer = renderManager.getRenderer(entity); + + if (renderer instanceof AbstractContraptionEntityRenderer) { + updateTransform(entity, (AbstractContraptionEntityRenderer) renderer); + } + } + } + } + + private static void updateTransform(C c, AbstractContraptionEntityRenderer entityRenderer) { + MatrixStack stack = entityRenderer.makeTransformMatrix(c, AnimationTickHolder.getPartialTicks()); + + markForRendering(c.getContraption(), stack); + } + public static void tick() { for (RenderedContraption contraption : renderers.values()) { contraption.getLighter().tick(contraption); @@ -84,6 +122,7 @@ public class ContraptionRenderDispatcher { } } + for (Integer id : toRemove) { renderers.remove(id); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java index 2fcacb96a..931b2affb 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java @@ -2,8 +2,7 @@ package com.simibubi.create.foundation.utility.outliner; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.MathHelper; @@ -30,8 +29,7 @@ public class ChasingAABBOutline extends AABBOutline { @Override public void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { - renderBB(ms, buffer, interpolateBBs(prevBB, bb, Minecraft.getInstance() - .getRenderPartialTicks())); + renderBB(ms, buffer, interpolateBBs(prevBB, bb, AnimationTickHolder.getPartialTicks())); } private static AxisAlignedBB interpolateBBs(AxisAlignedBB current, AxisAlignedBB target, float pt) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java index 3f3a307ab..e76bbc56d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java @@ -2,8 +2,7 @@ package com.simibubi.create.foundation.utility.outliner; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -47,8 +46,7 @@ public class LineOutline extends Outline { @Override public void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { - float pt = Minecraft.getInstance() - .getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); float distanceToTarget = 1 - MathHelper.lerp(pt, prevProgress, progress); Vec3d start = end.add(this.start.subtract(end) .scale(distanceToTarget)); diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java index 39a019c65..f820fa384 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java @@ -1,24 +1,18 @@ package com.simibubi.create.foundation.utility.outliner; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.outliner.LineOutline.EndChasingLineOutline; import com.simibubi.create.foundation.utility.outliner.Outline.OutlineParams; - -import net.minecraft.client.Minecraft; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import java.util.*; + public class Outliner { final Map outlines; @@ -143,8 +137,7 @@ public class Outliner { float fadeticks = OutlineEntry.fadeTicks; float lastAlpha = prevTicks >= 0 ? 1 : 1 + (prevTicks / fadeticks); float currentAlpha = 1 + (entry.ticksTillRemoval / fadeticks); - float alpha = MathHelper.lerp(Minecraft.getInstance() - .getRenderPartialTicks(), lastAlpha, currentAlpha); + float alpha = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), lastAlpha, currentAlpha); outline.params.alpha = alpha * alpha * alpha; if (outline.params.alpha < 1 / 8f)