9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-21 15:59:26 +00:00

Drop useless reduce movement allocations patch

This commit is contained in:
Samsuik
2024-07-20 00:23:26 +01:00
parent 17b32245f6
commit ff811ffd5c
70 changed files with 104 additions and 341 deletions

View File

@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <40902469+Samsuik@users.noreply.github.com>
Date: Mon, 16 Oct 2023 22:41:12 +0100
Subject: [PATCH] Cache MovingBlockEntity collision shape
diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
index b35f476e26a020cf75e53a5eb488717d996a6935..d555ad1dd2f648b84920eceec6cc99e8801334b3 100644
--- a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
@@ -42,6 +42,11 @@ public class PistonMovingBlockEntity extends BlockEntity {
private float progressO;
private long lastTicked;
private int deathTicks;
+ // Sakura start
+ private VoxelShape collisionShape = Shapes.empty();
+ private Direction shapeDirection = null;
+ private float shapeProgress = Float.MIN_VALUE;
+ // Sakura end
public PistonMovingBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityType.PISTON, pos, state);
@@ -349,6 +354,18 @@ public class PistonMovingBlockEntity extends BlockEntity {
}
public VoxelShape getCollisionShape(BlockGetter world, BlockPos pos) {
+ // Sakura start
+ var direction = NOCLIP.get();
+ if (progress == shapeProgress && direction == shapeDirection) {
+ return collisionShape;
+ } else {
+ shapeProgress = progress;
+ shapeDirection = direction;
+ return collisionShape = createCollisionShape(world, pos);
+ }
+ }
+ private VoxelShape createCollisionShape(BlockGetter world, BlockPos pos) {
+ // Sakura end
VoxelShape voxelShape;
if (!this.extending && this.isSourcePiston && this.movedState.getBlock() instanceof PistonBaseBlock) {
voxelShape = this.movedState.setValue(PistonBaseBlock.EXTENDED, Boolean.valueOf(true)).getCollisionShape(world, pos);