Skip to content

Commit

Permalink
Fix PBF issues (#2615)
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg authored Dec 21, 2024
1 parent 56dddf8 commit d1202b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.machine;

import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.block.IMachineBlock;
import com.gregtechceu.gtceu.api.item.tool.IToolGridHighlight;
import com.gregtechceu.gtceu.common.machine.owner.IMachineOwner;
Expand Down Expand Up @@ -53,7 +54,13 @@ default void scheduleRenderUpdate() {
}

default long getOffsetTimer() {
return level() == null ? getOffset() : (level().getServer().getTickCount() + getOffset());
if (level() == null) return getOffset();
else if (level().isClientSide()) return GTValues.CLIENT_TIME + getOffset();

var server = level().getServer();
if (server != null) return server.getTickCount() + getOffset();

return getOffset();
}

default MachineDefinition getDefinition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void render(BlockEntity blockEntity, float partialTicks, PoseStack stack,

var up = RelativeDirection.UP.getRelativeFacing(lcb.getFrontFacing(), lcb.getUpwardsFacing(),
lcb.isFlipped());
if (up != Direction.UP && up != Direction.DOWN) up = up.getOpposite();
if (up.getAxis() != Direction.Axis.Y) up = up.getOpposite();
fluidBlockRenderer.drawPlane(up, lcb.getFluidBlockOffsets(), pose, consumer, cachedFluid,
RenderUtil.FluidTextureType.STILL, combinedOverlay, lcb.getPos());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@
@MethodsReturnNonnullByDefault
public class PrimitiveBlastFurnaceMachine extends PrimitiveWorkableMachine implements IUIMachine {

private TickableSubscription onServerTick;
private TickableSubscription hurtSubscription;

public PrimitiveBlastFurnaceMachine(IMachineBlockEntity holder, Object... args) {
super(holder, args);
this.onServerTick = subscribeServerTick(this::hurtEntities);
}

@Override
Expand All @@ -60,22 +59,22 @@ protected NotifiableItemStackHandler createExportItemHandler(Object... args) {
IO.NONE);
}

@Override
public void onLoad() {
super.onLoad();
this.onServerTick = subscribeServerTick(onServerTick, this::hurtEntities);
}

@Override
public void onUnload() {
super.onUnload();
this.onServerTick.unsubscribe();
unsubscribe(hurtSubscription);
}

@Override
public void onStructureFormed() {
super.onStructureFormed();
this.onServerTick = subscribeServerTick(onServerTick, this::hurtEntities);
this.hurtSubscription = subscribeServerTick(this::hurtEntities);
}

@Override
public void onStructureInvalid() {
super.onStructureInvalid();
unsubscribe(hurtSubscription);
}

@Override
Expand All @@ -90,10 +89,10 @@ public void clientTick() {
float zPos = facing.getStepZ() * 0.76F + pos.getZ() + 0.5F;

var up = RelativeDirection.UP.getRelativeFacing(getFrontFacing(), getUpwardsFacing(), isFlipped());
var sign = up == Direction.UP || up == Direction.EAST || up == Direction.SOUTH ? 1 : -1;
var shouldX = up == Direction.EAST || up == Direction.WEST;
var shouldY = up == Direction.UP || up == Direction.DOWN;
var shouldZ = up == Direction.NORTH || up == Direction.SOUTH;
var sign = up.getAxisDirection().getStep();
var shouldX = up.getAxis() == Direction.Axis.X;
var shouldY = up.getAxis() == Direction.Axis.Y;
var shouldZ = up.getAxis() == Direction.Axis.Z;
var speed = ((shouldY ? facing.getStepY() : shouldX ? facing.getStepX() : facing.getStepZ()) * 0.1F + 0.2F +
0.1F * GTValues.RNG.nextFloat()) * sign;
if (getOffsetTimer() % 20 == 0) {
Expand Down Expand Up @@ -170,7 +169,6 @@ public void animateTick(RandomSource random) {
}

private void hurtEntities() {
if (!isFormed) return;
BlockPos middlePos = self().getPos().offset(getFrontFacing().getOpposite().getNormal());
getLevel().getEntities(null,
new AABB(middlePos)).forEach(e -> e.hurt(e.damageSources().lava(), 3.0f));
Expand Down

0 comments on commit d1202b4

Please sign in to comment.