Skip to content

Commit f166c7d

Browse files
committed
Improve integration with vanilla's new tick commands:
- Ensure rendering related thing that pauses when the game is paused, also stops updating the state when the tick rate manager is frozen - Made dosimeter and geiger counter radiation decay timer take the current target tickrate into account (still displays the number even if the tick rate is frozen, but of course it won't actually happen if frozen) - Allow logistical sorter tooltips to display to two decimals, so that at sub 20 tps target rates, basic transporters don't just display zero - Made radiation properly not decay when things aren't ticking - Similar to minecarts, don't have sounds play while the tick rate is frozen - Use gui ticks for hud and overlay rendering so that things can properly go away while tick rate is frozen - Don't tick transmitter networks when the tick manager isn't running (but still allow network formation logic to run)
1 parent 0d23574 commit f166c7d

32 files changed

+145
-97
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ the potential for us making breaking changes where APIs may change slightly or h
2222
changes. For this reason we do not recommend including Mekanism in any "large" packs that players may expect
2323
things to work properly/upgrade safely from one version to the next.
2424

25-
We have not yet had the chance to go through and fully integrate with all of vanilla's new features,
26-
recipes, blocks, entities, or even things like the tickrate command. Additionally, there is a handful
27-
of things that we haven't finished porting yet.
25+
~~We have not yet had the chance to go through and fully integrate with all of vanilla's new features,
26+
recipes, blocks, entities, or even things like the tickrate command.~~ (Previous Sentence Fixed 10.6.4)
27+
Additionally, there is a handful of things that we haven't finished porting yet.
2828

2929
## Known Bugs/Things that aren't done being ported yet ##
3030
- Options in the Module Tweaker that have side effects don't currently have those side effects displayed

src/generators/java/mekanism/generators/client/render/RenderTurbineRotor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import mekanism.generators.common.GeneratorsProfilerConstants;
1111
import mekanism.generators.common.content.turbine.TurbineMultiblockData;
1212
import mekanism.generators.common.tile.turbine.TileEntityTurbineRotor;
13-
import net.minecraft.client.Minecraft;
1413
import net.minecraft.client.renderer.MultiBufferSource;
1514
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
1615
import net.minecraft.core.BlockPos;
@@ -47,7 +46,7 @@ public void render(TileEntityTurbineRotor tile, PoseStack matrix, VertexConsumer
4746
return;
4847
}
4948
int baseIndex = tile.getPosition() * 2;
50-
if (!Minecraft.getInstance().isPaused()) {
49+
if (isTickingNormally(tile)) {
5150
UUID multiblockUUID = tile.getMultiblockUUID();
5251
if (multiblockUUID != null && TurbineMultiblockData.clientRotationMap.containsKey(multiblockUUID)) {
5352
float rotateSpeed = TurbineMultiblockData.clientRotationMap.getFloat(multiblockUUID) * BASE_SPEED;

src/generators/java/mekanism/generators/client/render/item/RenderWindGeneratorItem.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class RenderWindGeneratorItem extends MekanismISTER {
1919

2020
public static final RenderWindGeneratorItem RENDERER = new RenderWindGeneratorItem();
2121
private static final int SPEED = 16;
22-
private static float lastTicksUpdated = 0;
22+
private static int lastTicksUpdated = 0;
2323
private static int angle = 0;
2424
private ModelWindGenerator windGenerator;
2525

@@ -31,22 +31,23 @@ public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
3131
@Override
3232
public void renderByItem(@NotNull ItemStack stack, @NotNull ItemDisplayContext displayContext, @NotNull PoseStack matrix, @NotNull MultiBufferSource renderer,
3333
int light, int overlayLight) {
34-
float ticks = Minecraft.getInstance().levelRenderer.getTicks();
35-
boolean paused = Minecraft.getInstance().isPaused();
36-
if (!paused) {
34+
Minecraft minecraft = Minecraft.getInstance();
35+
boolean tickingNormally = MekanismRenderer.isRunningNormally();
36+
if (tickingNormally) {
37+
int ticks = Minecraft.getInstance().levelRenderer.getTicks();
3738
if (lastTicksUpdated != ticks) {
3839
//Only update the angle if we are in a world and that world is not blacklisted
39-
if (Minecraft.getInstance().level != null) {
40+
if (minecraft.level != null) {
4041
List<ResourceLocation> blacklistedDimensions = MekanismGeneratorsConfig.generators.windGenerationDimBlacklist.get();
41-
if (blacklistedDimensions.isEmpty() || !blacklistedDimensions.contains(Minecraft.getInstance().level.dimension().location())) {
42+
if (blacklistedDimensions.isEmpty() || !blacklistedDimensions.contains(minecraft.level.dimension().location())) {
4243
angle = (angle + SPEED) % 360;
4344
}
4445
}
4546
lastTicksUpdated = ticks;
4647
}
4748
}
4849
float renderAngle = angle;
49-
if (!paused) {
50+
if (tickingNormally) {
5051
renderAngle = (renderAngle + SPEED * MekanismRenderer.getPartialTick()) % 360;
5152
}
5253
matrix.pushPose();

src/main/java/mekanism/client/ClientTickHandler.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import mekanism.api.radial.RadialData;
1212
import mekanism.client.gui.GuiRadialSelector;
1313
import mekanism.client.key.MekKeyHandler;
14+
import mekanism.client.render.MekanismRenderer;
1415
import mekanism.client.render.hud.MekanismStatusOverlay;
1516
import mekanism.client.render.lib.ScrollIncrementer;
1617
import mekanism.client.sound.GeigerSound;
@@ -127,6 +128,7 @@ public static boolean isVisionEnhancementOn(Player player) {
127128
}
128129

129130
public static void portableTeleport(Player player, InteractionHand hand, FrequencyIdentity identity) {
131+
//TODO - 1.21: Handle and validate the delay takes place server side
130132
int delay = MekanismConfig.gear.portableTeleporterDelay.get();
131133
if (delay == 0) {
132134
PacketUtils.sendToServer(new PacketPortableTeleporterTeleport(hand, identity));
@@ -156,13 +158,16 @@ public void onTick(ClientTickEvent.Pre event) {
156158
shouldReset = false;
157159
}
158160

159-
if (minecraft.level != null && minecraft.player != null && !minecraft.isPaused()) {
160-
HolidayManager.notify(Minecraft.getInstance().player);
161+
if (minecraft.level != null && minecraft.player != null) {
162+
boolean tickingNormally = MekanismRenderer.isRunningNormally();
163+
HolidayManager.notify(minecraft.player);
161164

162165
//Reboot player sounds if needed
163166
SoundHandler.restartSounds();
164167

165-
RadiationManager.get().tickClient(minecraft.player);
168+
if (tickingNormally) {
169+
RadiationManager.get().tickClient(minecraft.player);
170+
}
166171

167172
UUID playerUUID = minecraft.player.getUUID();
168173
// Update player's state for various items; this also automatically notifies server if something changed and
@@ -173,19 +178,22 @@ public void onTick(ClientTickEvent.Pre event) {
173178
Mekanism.playerState.setScubaMaskState(playerUUID, isScubaMaskOn(minecraft.player), true);
174179
Mekanism.playerState.setGravitationalModulationState(playerUUID, isGravitationalModulationOn(minecraft.player), true);
175180

176-
for (Iterator<Entry<Player, TeleportData>> iter = portableTeleports.entrySet().iterator(); iter.hasNext(); ) {
177-
Entry<Player, TeleportData> entry = iter.next();
178-
Player player = entry.getKey();
179-
for (int i = 0; i < 100; i++) {
180-
double x = player.getX() + rand.nextDouble() - 0.5D;
181-
double y = player.getY() + rand.nextDouble() * 2 - 2D;
182-
double z = player.getZ() + rand.nextDouble() - 0.5D;
183-
minecraft.level.addParticle(ParticleTypes.PORTAL, x, y, z, 0, 1, 0);
184-
}
185-
TeleportData data = entry.getValue();
186-
if (minecraft.level.getGameTime() == data.teleportTime) {
187-
PacketUtils.sendToServer(new PacketPortableTeleporterTeleport(data.hand, data.identity));
188-
iter.remove();
181+
if (tickingNormally) {
182+
//Note: If we aren't ticking normally we can skip adding the particles or checking if the time matches as we know the time hasn't changed
183+
for (Iterator<Entry<Player, TeleportData>> iter = portableTeleports.entrySet().iterator(); iter.hasNext(); ) {
184+
Entry<Player, TeleportData> entry = iter.next();
185+
Player player = entry.getKey();
186+
for (int i = 0; i < 100; i++) {
187+
double x = player.getX() + rand.nextDouble() - 0.5D;
188+
double y = player.getY() + rand.nextDouble() * 2 - 2D;
189+
double z = player.getZ() + rand.nextDouble() - 0.5D;
190+
minecraft.level.addParticle(ParticleTypes.PORTAL, x, y, z, 0, 1, 0);
191+
}
192+
TeleportData data = entry.getValue();
193+
if (minecraft.level.getGameTime() == data.teleportTime) {
194+
PacketUtils.sendToServer(new PacketPortableTeleporterTeleport(data.hand, data.identity));
195+
iter.remove();
196+
}
189197
}
190198
}
191199

@@ -234,7 +242,7 @@ public void onTick(ClientTickEvent.Pre event) {
234242
}
235243
}
236244

237-
if (MekanismConfig.client.enablePlayerSounds.get()) {
245+
if (tickingNormally && MekanismConfig.client.enablePlayerSounds.get()) {
238246
RadiationScale scale = RadiationManager.get().getClientScale();
239247
if (scale != RadiationScale.NONE && !SoundHandler.radiationSoundMap.containsKey(scale)) {
240248
GeigerSound sound = GeigerSound.create(minecraft.player, scale);

src/main/java/mekanism/client/render/HUDRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void renderHUD(Minecraft minecraft, GuiGraphics guiGraphics, Font font, D
7373

7474
private void update(Level level, Player player) {
7575
// if we're just now rendering the HUD after a pause, reset the pitch/yaw trackers
76-
if (lastTick == -1 || level.getGameTime() - lastTick > 1) {
76+
if (lastTick == -1 || level.getGameTime() - lastTick > 1 || !level.tickRateManager().runsNormally()) {
7777
prevRotationYaw = player.getYRot();
7878
prevRotationPitch = player.getXRot();
7979
}

src/main/java/mekanism/client/render/MekanismRenderer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ public static void renderColorOverlay(GuiGraphics guiGraphics, int x, int y, int
255255
guiGraphics.fill(RenderType.guiOverlay(), x, y, guiGraphics.guiWidth(), guiGraphics.guiHeight(), color);
256256
}
257257

258+
public static boolean isRunningNormally() {
259+
Minecraft minecraft = Minecraft.getInstance();
260+
return !minecraft.isPaused() && MekanismUtils.isTickingNormally(minecraft.level);
261+
}
262+
258263
public static float getPartialTick() {
259264
return Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false);
260265
}

src/main/java/mekanism/client/render/RenderTickHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void renderArm(RenderArmEvent event) {
246246
public void tickEnd(ClientTickEvent.Post event) {
247247
//Note: We check that the game mode is not null as if it is that means the world is unloading, and we don't actually want to be rendering
248248
// as our data may be out of date or invalid. For example configs could unload while it is still unloading
249-
if (minecraft.player != null && minecraft.player.level() != null && !minecraft.isPaused() && minecraft.gameMode != null) {
249+
if (minecraft.player != null && minecraft.player.level() != null && minecraft.gameMode != null && MekanismRenderer.isRunningNormally()) {
250250
Player player = minecraft.player;
251251
Level world = minecraft.player.level();
252252
float partialTicks = minecraft.getTimer().getGameTimeDeltaPartialTick(false);

src/main/java/mekanism/client/render/hud/MekanismStatusOverlay.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class MekanismStatusOverlay implements LayeredDraw.Layer {
2222
private static final int BASE_TIMER = 5 * SharedConstants.TICKS_PER_SECOND;
2323

2424
private int modeSwitchTimer = 0;
25-
private long lastTick;
25+
private int lastTick;
2626

2727
private MekanismStatusOverlay() {
2828
}
@@ -62,8 +62,8 @@ public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker delta) {
6262
}
6363
}
6464
//Only decrement the switch timer once a tick
65-
if (lastTick != minecraft.player.level().getGameTime()) {
66-
lastTick = minecraft.player.level().getGameTime();
65+
if (lastTick != minecraft.gui.getGuiTicks()) {
66+
lastTick = minecraft.gui.getGuiTicks();
6767
modeSwitchTimer--;
6868
}
6969
}

src/main/java/mekanism/client/render/hud/RadiationOverlay.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class RadiationOverlay implements LayeredDraw.Layer {
1818
public static final RadiationOverlay INSTANCE = new RadiationOverlay();
1919

2020
private double prevRadiation = 0;
21-
private long lastTick;
21+
private int lastTick;
2222

2323
private RadiationOverlay() {
2424
}
@@ -29,13 +29,14 @@ public void resetRadiation() {
2929

3030
@Override
3131
public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker delta) {
32-
Player player = Minecraft.getInstance().player;
32+
Minecraft minecraft = Minecraft.getInstance();
33+
Player player = minecraft.player;
3334
if (player != null && IRadiationManager.INSTANCE.isRadiationEnabled() && MekanismUtils.isPlayingMode(player)) {
3435
double radiation = player.getData(MekanismAttachmentTypes.RADIATION);
3536
double severity = RadiationScale.getScaledDoseSeverity(radiation) * 0.8;
3637
//Only update the previous radiation level at most once a tick
37-
if (lastTick != player.level().getGameTime()) {
38-
lastTick = player.level().getGameTime();
38+
if (lastTick != minecraft.gui.getGuiTicks()) {
39+
lastTick = minecraft.gui.getGuiTicks();
3940
if (prevRadiation < severity) {
4041
prevRadiation = Math.min(severity, prevRadiation + 0.01);
4142
}

src/main/java/mekanism/client/render/item/ChemicalFluidBarDecorator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ private static int convertWidth(double width) {
8787
static int getDisplayTank(int tanks) {
8888
if (tanks == 0) {
8989
return -1;
90-
} else if (tanks > 1 && Minecraft.getInstance().level != null) {
90+
} else if (tanks > 1) {
9191
//Cycle through multiple tanks every second, to save some space if multiple tanks are present
92-
return (int) (Minecraft.getInstance().level.getGameTime() / SharedConstants.TICKS_PER_SECOND) % tanks;
92+
return (Minecraft.getInstance().gui.getGuiTicks() / SharedConstants.TICKS_PER_SECOND) % tanks;
9393
}
9494
return 0;
9595
}

0 commit comments

Comments
 (0)