Skip to content

Commit

Permalink
Improve rotation speed of the wind generator item
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Feb 26, 2024
1 parent d3ea197 commit 9945aaf
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import java.util.List;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.render.item.MekanismISTER;
import mekanism.generators.client.model.ModelWindGenerator;
import mekanism.generators.common.config.MekanismGeneratorsConfig;
Expand All @@ -17,6 +18,7 @@
public class RenderWindGeneratorItem extends MekanismISTER {

public static final RenderWindGeneratorItem RENDERER = new RenderWindGeneratorItem();
private static final int SPEED = 16;
private static float lastTicksUpdated = 0;
private static int angle = 0;
private ModelWindGenerator windGenerator;
Expand All @@ -29,21 +31,28 @@ public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
@Override
public void renderByItem(@NotNull ItemStack stack, @NotNull ItemDisplayContext displayContext, @NotNull PoseStack matrix, @NotNull MultiBufferSource renderer,
int light, int overlayLight) {
float renderPartialTicks = Minecraft.getInstance().getFrameTime();
if (lastTicksUpdated != renderPartialTicks) {
//Only update the angle if we are in a world and that world is not blacklisted
if (Minecraft.getInstance().level != null) {
List<ResourceLocation> blacklistedDimensions = MekanismGeneratorsConfig.generators.windGenerationDimBlacklist.get();
if (blacklistedDimensions.isEmpty() || !blacklistedDimensions.contains(Minecraft.getInstance().level.dimension().location())) {
angle = (angle + 2) % 360;
float ticks = Minecraft.getInstance().levelRenderer.getTicks();
boolean paused = Minecraft.getInstance().isPaused();
if (!paused) {
if (lastTicksUpdated != ticks) {
//Only update the angle if we are in a world and that world is not blacklisted
if (Minecraft.getInstance().level != null) {
List<ResourceLocation> blacklistedDimensions = MekanismGeneratorsConfig.generators.windGenerationDimBlacklist.get();
if (blacklistedDimensions.isEmpty() || !blacklistedDimensions.contains(Minecraft.getInstance().level.dimension().location())) {
angle = (angle + SPEED) % 360;
}
}
lastTicksUpdated = ticks;
}
lastTicksUpdated = renderPartialTicks;
}
float renderAngle = angle;
if (!paused) {
renderAngle = (renderAngle + SPEED * MekanismRenderer.getPartialTick()) % 360;
}
matrix.pushPose();
matrix.translate(0.5, 0.5, 0.5);
matrix.mulPose(Axis.ZP.rotationDegrees(180));
windGenerator.render(matrix, renderer, angle, light, overlayLight, stack.hasFoil());
windGenerator.render(matrix, renderer, renderAngle, light, overlayLight, stack.hasFoil());
matrix.popPose();
}
}

0 comments on commit 9945aaf

Please sign in to comment.