This commit is contained in:
Shroopy 2024-11-27 15:06:02 -08:00
parent 0845797d0c
commit ba2417e417

View file

@ -35,12 +35,14 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
public List<ItemStack> particleItems = new ArrayList<>(); public List<ItemStack> particleItems = new ArrayList<>();
public PressingBehaviourSpecifics specifics; public PressingBehaviourSpecifics specifics;
public int prevRunningTicks; public float prevRunningTicks;
public int runningTicks; public float runningTicks;
public boolean running; public boolean running;
public boolean finished; public boolean finished;
public Mode mode; public Mode mode;
private boolean ticksPaused;
int entityScanCooldown; int entityScanCooldown;
public interface PressingBehaviourSpecifics { public interface PressingBehaviourSpecifics {
@ -73,7 +75,7 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
running = compound.getBoolean("Running"); running = compound.getBoolean("Running");
mode = Mode.values()[compound.getInt("Mode")]; mode = Mode.values()[compound.getInt("Mode")];
finished = compound.getBoolean("Finished"); finished = compound.getBoolean("Finished");
prevRunningTicks = runningTicks = compound.getInt("Ticks"); prevRunningTicks = runningTicks = compound.getFloat("Ticks");
super.read(compound, clientPacket); super.read(compound, clientPacket);
if (clientPacket) { if (clientPacket) {
@ -88,11 +90,12 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
compound.putBoolean("Running", running); compound.putBoolean("Running", running);
compound.putInt("Mode", mode.ordinal()); compound.putInt("Mode", mode.ordinal());
compound.putBoolean("Finished", finished); compound.putBoolean("Finished", finished);
compound.putInt("Ticks", runningTicks); compound.putFloat("Ticks", runningTicks);
super.write(compound, clientPacket); super.write(compound, clientPacket);
if (clientPacket) { if (clientPacket) {
compound.put("ParticleItems", NBTHelper.writeCompoundList(particleItems, ItemStack::serializeNBT)); compound.put("ParticleItems",
NBTHelper.writeCompoundList(particleItems, NBTSerializer::serializeNBTCompound));
particleItems.clear(); particleItems.clear();
} }
} }
@ -100,7 +103,7 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
public float getRenderedHeadOffset(float partialTicks) { public float getRenderedHeadOffset(float partialTicks) {
if (!running) if (!running)
return 0; return 0;
int runningTicks = Math.abs(this.runningTicks); float runningTicks = Math.abs(this.runningTicks);
float ticks = Mth.lerp(partialTicks, prevRunningTicks, runningTicks); float ticks = Mth.lerp(partialTicks, prevRunningTicks, runningTicks);
if (runningTicks < (CYCLE * 2) / 3) if (runningTicks < (CYCLE * 2) / 3)
return (float) Mth.clamp(Math.pow(ticks / CYCLE * 2, 3), 0, 1); return (float) Mth.clamp(Math.pow(ticks / CYCLE * 2, 3), 0, 1);
@ -156,7 +159,8 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
if (BasinBlock.isBasin(level, worldPosition.below(2))) if (BasinBlock.isBasin(level, worldPosition.below(2)))
return; return;
for (ItemEntity itemEntity : level.getEntitiesOfClass(ItemEntity.class, new AABB(worldPosition.below()).deflate(.125f))) { for (ItemEntity itemEntity : level.getEntitiesOfClass(ItemEntity.class,
new AABB(worldPosition.below()).deflate(.125f))) {
if (!itemEntity.isAlive() || !itemEntity.onGround()) if (!itemEntity.isAlive() || !itemEntity.onGround())
continue; continue;
if (!specifics.tryProcessInWorld(itemEntity, true)) if (!specifics.tryProcessInWorld(itemEntity, true))
@ -169,10 +173,12 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
return; return;
} }
if (level.isClientSide && runningTicks == -CYCLE / 2) { /*
if (level.isClientSide && ticksPaused) {
prevRunningTicks = CYCLE / 2; prevRunningTicks = CYCLE / 2;
return; return;
} }
*/
if (runningTicks >= CYCLE / 2 && !finished) { if (runningTicks >= CYCLE / 2 && !finished) {
if (inWorld()) if (inWorld())
@ -180,12 +186,11 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
if (onBasin()) if (onBasin())
applyOnBasin(); applyOnBasin();
if (level.getBlockState(worldPosition.below(2)) if (level.getBlockState(worldPosition.below(2)).getSoundType() == SoundType.WOOL)
.getSoundType() == SoundType.WOOL)
AllSoundEvents.MECHANICAL_PRESS_ACTIVATION_ON_BELT.playOnServer(level, worldPosition); AllSoundEvents.MECHANICAL_PRESS_ACTIVATION_ON_BELT.playOnServer(level, worldPosition);
else else
AllSoundEvents.MECHANICAL_PRESS_ACTIVATION.playOnServer(level, worldPosition, .5f, AllSoundEvents.MECHANICAL_PRESS_ACTIVATION.playOnServer(level, worldPosition, .5f,
.75f + (Math.abs(specifics.getKineticSpeed()) / 1024f)); .75f + (Math.abs(specifics.getKineticSpeed()) / 1024f));
if (!level.isClientSide) if (!level.isClientSide)
blockEntity.sendData(); blockEntity.sendData();
@ -193,22 +198,25 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
finished = true; finished = true;
} }
if (!level.isClientSide && runningTicks > CYCLE) { if (runningTicks > CYCLE) {
finished = false; finished = false;
particleItems.clear(); runningTicks -= CYCLE;
specifics.onPressingCompleted(); if (!level.isClientSide) {
blockEntity.sendData(); particleItems.clear();
runningTicks -= 240; specifics.onPressingCompleted();
return; blockEntity.sendData();
}
} }
prevRunningTicks = runningTicks; prevRunningTicks = runningTicks;
runningTicks += getRunningTickSpeed(); runningTicks += getRunningTickSpeed();
/*
if (prevRunningTicks < CYCLE / 2 && runningTicks >= CYCLE / 2) { if (prevRunningTicks < CYCLE / 2 && runningTicks >= CYCLE / 2) {
// Pause the ticks until a packet is received // Pause the ticks until a packet is received
if (level.isClientSide && !blockEntity.isVirtual()) if (level.isClientSide && !blockEntity.isVirtual())
runningTicks = -(CYCLE / 2); ticksPaused = true;
} }
*/
} }
protected void applyOnBasin() { protected void applyOnBasin() {
@ -245,11 +253,11 @@ public class PressingBehaviour extends BeltProcessingBehaviour {
} }
} }
public int getRunningTickSpeed() { public float getRunningTickSpeed() {
float speed = specifics.getKineticSpeed(); float speed = specifics.getKineticSpeed();
if (speed == 0) if (speed == 0)
return 0; return 0;
return (int) Mth.lerp(Mth.clamp(Math.abs(speed) / 512f, 0, 1), 1, 60); return 30 * speed / 256;
} }
protected void spawnParticles() { protected void spawnParticles() {