Paper/patches/server/1046-SW-WallBlock-Cache-Improvements.patch
Chaoscaot 037a909005
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Update to 1.21.1
2024-08-27 13:57:27 +02:00

119 Zeilen
6.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Chaoscaot <chaos@chaoscaot.de>
Date: Tue, 13 Aug 2024 11:40:37 +0200
Subject: [PATCH] SW WallBlock Cache Improvements
diff --git a/src/main/java/net/minecraft/world/level/block/WallBlock.java b/src/main/java/net/minecraft/world/level/block/WallBlock.java
index 83956032bef4d34eddb9899f0a2847e66bfd83f4..bea1d8a72d5528335b755aeda6168764778b924f 100644
--- a/src/main/java/net/minecraft/world/level/block/WallBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/WallBlock.java
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.mojang.serialization.MapCodec;
import java.util.Map;
+import java.util.Objects;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
@@ -35,8 +36,14 @@ public class WallBlock extends Block implements SimpleWaterloggedBlock {
public static final EnumProperty<WallSide> SOUTH_WALL = BlockStateProperties.SOUTH_WALL;
public static final EnumProperty<WallSide> WEST_WALL = BlockStateProperties.WEST_WALL;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
- private final Map<BlockState, VoxelShape> shapeByIndex;
- private final Map<BlockState, VoxelShape> collisionShapeByIndex;
+ private static final Map<Integer, VoxelShape> shapeByIndex;
+ private static final Map<Integer, VoxelShape> collisionShapeByIndex;
+
+ static {
+ shapeByIndex = makeShapes(4.0F, 3.0F, 16.0F, 0.0F, 14.0F, 16.0F);
+ collisionShapeByIndex = makeShapes(4.0F, 3.0F, 24.0F, 0.0F, 24.0F, 24.0F);
+ }
+
private static final int WALL_WIDTH = 3;
private static final int WALL_HEIGHT = 14;
private static final int POST_WIDTH = 4;
@@ -66,8 +73,6 @@ public class WallBlock extends Block implements SimpleWaterloggedBlock {
.setValue(WEST_WALL, WallSide.NONE)
.setValue(WATERLOGGED, Boolean.valueOf(false))
);
- this.shapeByIndex = this.makeShapes(4.0F, 3.0F, 16.0F, 0.0F, 14.0F, 16.0F);
- this.collisionShapeByIndex = this.makeShapes(4.0F, 3.0F, 24.0F, 0.0F, 24.0F, 24.0F);
}
private static VoxelShape applyWallShape(VoxelShape base, WallSide wallShape, VoxelShape tall, VoxelShape low) {
@@ -78,7 +83,7 @@ public class WallBlock extends Block implements SimpleWaterloggedBlock {
}
}
- private Map<BlockState, VoxelShape> makeShapes(float f, float g, float h, float i, float j, float k) {
+ private static Map<Integer, VoxelShape> makeShapes(float f, float g, float h, float i, float j, float k) {
float l = 8.0F - f;
float m = 8.0F + f;
float n = 8.0F - g;
@@ -92,7 +97,7 @@ public class WallBlock extends Block implements SimpleWaterloggedBlock {
VoxelShape voxelShape7 = Block.box((double)n, (double)i, (double)n, (double)o, (double)k, 16.0);
VoxelShape voxelShape8 = Block.box(0.0, (double)i, (double)n, (double)o, (double)k, (double)o);
VoxelShape voxelShape9 = Block.box((double)n, (double)i, (double)n, 16.0, (double)k, (double)o);
- Builder<BlockState, VoxelShape> builder = ImmutableMap.builder();
+ Builder<Integer, VoxelShape> builder = ImmutableMap.builder();
for (Boolean boolean_ : UP.getPossibleValues()) {
for (WallSide wallSide : EAST_WALL.getPossibleValues()) {
@@ -108,14 +113,8 @@ public class WallBlock extends Block implements SimpleWaterloggedBlock {
voxelShape10 = Shapes.or(voxelShape10, voxelShape);
}
- BlockState blockState = this.defaultBlockState()
- .setValue(UP, boolean_)
- .setValue(EAST_WALL, wallSide)
- .setValue(WEST_WALL, wallSide3)
- .setValue(NORTH_WALL, wallSide2)
- .setValue(SOUTH_WALL, wallSide4);
- builder.put(blockState.setValue(WATERLOGGED, Boolean.valueOf(false)), voxelShape10);
- builder.put(blockState.setValue(WATERLOGGED, Boolean.valueOf(true)), voxelShape10);
+ builder.put(hashWallState(wallSide, wallSide2, wallSide4, boolean_, Boolean.FALSE, wallSide3), voxelShape10);
+ builder.put(hashWallState(wallSide, wallSide2, wallSide4, boolean_, Boolean.TRUE , wallSide3), voxelShape10);
}
}
}
@@ -125,14 +124,36 @@ public class WallBlock extends Block implements SimpleWaterloggedBlock {
return builder.build();
}
+ private static int mapHashCode(Map<Property<?>, Comparable<?>> values) {
+ return hashWallState(
+ (WallSide) values.get(EAST_WALL),
+ (WallSide) values.get(NORTH_WALL),
+ (WallSide) values.get(SOUTH_WALL),
+ (Boolean) values.get(UP),
+ (Boolean) values.get(WATERLOGGED),
+ (WallSide) values.get(WEST_WALL)
+ );
+ }
+
+ private static int hashWallState(WallSide east, WallSide north, WallSide south, boolean up, boolean waterlogged, WallSide west) {
+ int hash = 7;
+ hash = 31 * hash + east.hashCode();
+ hash = 31 * hash + north.hashCode();
+ hash = 31 * hash + south.hashCode();
+ hash = 31 * hash + Objects.hashCode(up);
+ hash = 31 * hash + Objects.hashCode(waterlogged);
+ hash = 31 * hash + west.hashCode();
+ return hash;
+ }
+
@Override
protected VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
- return this.shapeByIndex.get(state);
+ return shapeByIndex.get(mapHashCode(state.getValues()));
}
@Override
protected VoxelShape getCollisionShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
- return this.collisionShapeByIndex.get(state);
+ return collisionShapeByIndex.get(mapHashCode(state.getValues()));
}
@Override