mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 08:59:23 +00:00
304 lines
17 KiB
Diff
304 lines
17 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Sat, 22 Jul 2023 16:52:31 +0800
|
|
Subject: [PATCH] Optimize PoweredRail
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java b/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java
|
|
index 40893e71fe8447b695350273bef9623bd5accdcd..0ec427fe0e1f85c07585e1a05269c4c38fc3e9f5 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java
|
|
@@ -32,22 +32,23 @@ public class PoweredRailBlock extends BaseRailBlock {
|
|
boolean flag1 = true;
|
|
RailShape blockpropertytrackposition = (RailShape) state.getValue(PoweredRailBlock.SHAPE);
|
|
|
|
+ // Leaf start - Optimize PoweredRail swtich
|
|
switch (blockpropertytrackposition) {
|
|
- case NORTH_SOUTH:
|
|
+ case NORTH_SOUTH -> {
|
|
if (flag) {
|
|
++l;
|
|
} else {
|
|
--l;
|
|
}
|
|
- break;
|
|
- case EAST_WEST:
|
|
+ }
|
|
+ case EAST_WEST -> {
|
|
if (flag) {
|
|
--j;
|
|
} else {
|
|
++j;
|
|
}
|
|
- break;
|
|
- case ASCENDING_EAST:
|
|
+ }
|
|
+ case ASCENDING_EAST -> {
|
|
if (flag) {
|
|
--j;
|
|
} else {
|
|
@@ -55,10 +56,9 @@ public class PoweredRailBlock extends BaseRailBlock {
|
|
++k;
|
|
flag1 = false;
|
|
}
|
|
-
|
|
blockpropertytrackposition = RailShape.EAST_WEST;
|
|
- break;
|
|
- case ASCENDING_WEST:
|
|
+ }
|
|
+ case ASCENDING_WEST -> {
|
|
if (flag) {
|
|
--j;
|
|
++k;
|
|
@@ -66,10 +66,9 @@ public class PoweredRailBlock extends BaseRailBlock {
|
|
} else {
|
|
++j;
|
|
}
|
|
-
|
|
blockpropertytrackposition = RailShape.EAST_WEST;
|
|
- break;
|
|
- case ASCENDING_NORTH:
|
|
+ }
|
|
+ case ASCENDING_NORTH -> {
|
|
if (flag) {
|
|
++l;
|
|
} else {
|
|
@@ -77,10 +76,9 @@ public class PoweredRailBlock extends BaseRailBlock {
|
|
++k;
|
|
flag1 = false;
|
|
}
|
|
-
|
|
blockpropertytrackposition = RailShape.NORTH_SOUTH;
|
|
- break;
|
|
- case ASCENDING_SOUTH:
|
|
+ }
|
|
+ case ASCENDING_SOUTH -> {
|
|
if (flag) {
|
|
++l;
|
|
++k;
|
|
@@ -88,11 +86,12 @@ public class PoweredRailBlock extends BaseRailBlock {
|
|
} else {
|
|
--l;
|
|
}
|
|
-
|
|
blockpropertytrackposition = RailShape.NORTH_SOUTH;
|
|
+ }
|
|
}
|
|
+ // Leaf end
|
|
|
|
- return this.isSameRailWithPower(world, new BlockPos(j, k, l), flag, distance, blockpropertytrackposition) ? true : flag1 && this.isSameRailWithPower(world, new BlockPos(j, k - 1, l), flag, distance, blockpropertytrackposition);
|
|
+ return this.isSameRailWithPower(world, new BlockPos(j, k, l), flag, distance, blockpropertytrackposition) || flag1 && this.isSameRailWithPower(world, new BlockPos(j, k - 1, l), flag, distance, blockpropertytrackposition); // Leaf - Optimize PoweredRail
|
|
}
|
|
}
|
|
|
|
@@ -104,7 +103,7 @@ public class PoweredRailBlock extends BaseRailBlock {
|
|
} else {
|
|
RailShape blockpropertytrackposition1 = (RailShape) iblockdata.getValue(PoweredRailBlock.SHAPE);
|
|
|
|
- return shape == RailShape.EAST_WEST && (blockpropertytrackposition1 == RailShape.NORTH_SOUTH || blockpropertytrackposition1 == RailShape.ASCENDING_NORTH || blockpropertytrackposition1 == RailShape.ASCENDING_SOUTH) ? false : (shape == RailShape.NORTH_SOUTH && (blockpropertytrackposition1 == RailShape.EAST_WEST || blockpropertytrackposition1 == RailShape.ASCENDING_EAST || blockpropertytrackposition1 == RailShape.ASCENDING_WEST) ? false : ((Boolean) iblockdata.getValue(PoweredRailBlock.POWERED) ? (world.hasNeighborSignal(pos) ? true : this.findPoweredRailSignal(world, pos, iblockdata, flag, distance + 1)) : false));
|
|
+ return (shape != RailShape.EAST_WEST || (blockpropertytrackposition1 != RailShape.NORTH_SOUTH && blockpropertytrackposition1 != RailShape.ASCENDING_NORTH && blockpropertytrackposition1 != RailShape.ASCENDING_SOUTH)) && ((shape != RailShape.NORTH_SOUTH || (blockpropertytrackposition1 != RailShape.EAST_WEST && blockpropertytrackposition1 != RailShape.ASCENDING_EAST && blockpropertytrackposition1 != RailShape.ASCENDING_WEST)) && ((Boolean) iblockdata.getValue(PoweredRailBlock.POWERED) && (world.hasNeighborSignal(pos) || this.findPoweredRailSignal(world, pos, iblockdata, flag, distance + 1)))); // Leaf - Optimize PoweredRail
|
|
}
|
|
}
|
|
|
|
@@ -137,119 +136,120 @@ public class PoweredRailBlock extends BaseRailBlock {
|
|
|
|
@Override
|
|
public BlockState rotate(BlockState state, Rotation rotation) {
|
|
+ // Leaf start - Optimize PoweredRail swtich
|
|
switch (rotation) {
|
|
case CLOCKWISE_180:
|
|
switch ((RailShape) state.getValue(PoweredRailBlock.SHAPE)) {
|
|
- case ASCENDING_EAST:
|
|
+ case ASCENDING_EAST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
|
|
- case ASCENDING_WEST:
|
|
+ }
|
|
+ case ASCENDING_WEST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
|
|
- case ASCENDING_NORTH:
|
|
+ }
|
|
+ case ASCENDING_NORTH -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
|
|
- case ASCENDING_SOUTH:
|
|
+ }
|
|
+ case ASCENDING_SOUTH -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
|
|
- case SOUTH_EAST:
|
|
+ }
|
|
+ case SOUTH_EAST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
- case SOUTH_WEST:
|
|
+ }
|
|
+ case SOUTH_WEST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
- case NORTH_WEST:
|
|
+ }
|
|
+ case NORTH_WEST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
- case NORTH_EAST:
|
|
+ }
|
|
+ case NORTH_EAST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
+ }
|
|
}
|
|
case COUNTERCLOCKWISE_90:
|
|
- switch ((RailShape) state.getValue(PoweredRailBlock.SHAPE)) {
|
|
- case NORTH_SOUTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
|
|
- case EAST_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
|
|
- case ASCENDING_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
|
|
- case ASCENDING_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
|
|
- case ASCENDING_NORTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
|
|
- case ASCENDING_SOUTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
|
|
- case SOUTH_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
- case SOUTH_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
- case NORTH_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
- case NORTH_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
- }
|
|
+ return switch ((RailShape) state.getValue(PoweredRailBlock.SHAPE)) {
|
|
+ case NORTH_SOUTH -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
|
|
+ case EAST_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
|
|
+ case ASCENDING_EAST ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
|
|
+ case ASCENDING_WEST ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
|
|
+ case ASCENDING_NORTH ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
|
|
+ case ASCENDING_SOUTH ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
|
|
+ case SOUTH_EAST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
+ case SOUTH_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
+ case NORTH_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
+ case NORTH_EAST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
+ };
|
|
case CLOCKWISE_90:
|
|
- switch ((RailShape) state.getValue(PoweredRailBlock.SHAPE)) {
|
|
- case NORTH_SOUTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
|
|
- case EAST_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
|
|
- case ASCENDING_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
|
|
- case ASCENDING_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
|
|
- case ASCENDING_NORTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
|
|
- case ASCENDING_SOUTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
|
|
- case SOUTH_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
- case SOUTH_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
- case NORTH_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
- case NORTH_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
- }
|
|
+ return switch ((RailShape) state.getValue(PoweredRailBlock.SHAPE)) {
|
|
+ case NORTH_SOUTH -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
|
|
+ case EAST_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
|
|
+ case ASCENDING_EAST ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
|
|
+ case ASCENDING_WEST ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
|
|
+ case ASCENDING_NORTH ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
|
|
+ case ASCENDING_SOUTH ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
|
|
+ case SOUTH_EAST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
+ case SOUTH_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
+ case NORTH_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
+ case NORTH_EAST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
+ };
|
|
default:
|
|
return state;
|
|
}
|
|
+ // Leaf end
|
|
}
|
|
|
|
@Override
|
|
public BlockState mirror(BlockState state, Mirror mirror) {
|
|
RailShape blockpropertytrackposition = (RailShape) state.getValue(PoweredRailBlock.SHAPE);
|
|
|
|
+ // Leaf start - Optimize PoweredRail swtich
|
|
switch (mirror) {
|
|
- case LEFT_RIGHT:
|
|
- switch (blockpropertytrackposition) {
|
|
- case ASCENDING_NORTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
|
|
- case ASCENDING_SOUTH:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
|
|
- case SOUTH_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
- case SOUTH_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
- case NORTH_WEST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
- case NORTH_EAST:
|
|
- return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
- default:
|
|
- return super.mirror(state, mirror);
|
|
- }
|
|
- case FRONT_BACK:
|
|
+ case LEFT_RIGHT -> {
|
|
+ return switch (blockpropertytrackposition) {
|
|
+ case ASCENDING_NORTH ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
|
|
+ case ASCENDING_SOUTH ->
|
|
+ (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
|
|
+ case SOUTH_EAST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
+ case SOUTH_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
+ case NORTH_WEST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
+ case NORTH_EAST -> (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
+ default -> super.mirror(state, mirror);
|
|
+ };
|
|
+ }
|
|
+ case FRONT_BACK -> {
|
|
switch (blockpropertytrackposition) {
|
|
- case ASCENDING_EAST:
|
|
+ case ASCENDING_EAST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
|
|
- case ASCENDING_WEST:
|
|
+ }
|
|
+ case ASCENDING_WEST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
|
|
- case ASCENDING_NORTH:
|
|
- case ASCENDING_SOUTH:
|
|
- default:
|
|
- break;
|
|
- case SOUTH_EAST:
|
|
+ }
|
|
+ default -> {
|
|
+ }
|
|
+ case SOUTH_EAST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
|
|
- case SOUTH_WEST:
|
|
+ }
|
|
+ case SOUTH_WEST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
|
|
- case NORTH_WEST:
|
|
+ }
|
|
+ case NORTH_WEST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
|
|
- case NORTH_EAST:
|
|
+ }
|
|
+ case NORTH_EAST -> {
|
|
return (BlockState) state.setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
|
|
+ }
|
|
}
|
|
+ }
|
|
}
|
|
+ // Leaf end
|
|
|
|
return super.mirror(state, mirror);
|
|
}
|