Skip to content

Commit

Permalink
just can build
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Nov 24, 2024
1 parent 240a151 commit 1abd354
Show file tree
Hide file tree
Showing 72 changed files with 131 additions and 55 deletions.
44 changes: 27 additions & 17 deletions patches/server/0034-Alternative-block-placement-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ index 48ced9994219dc21d593a7deaa0a318f55dd00c7..c6e872633f6044e9c8e2a63bcef6332d
return this.defaultBlockState();
diff --git a/src/main/java/org/leavesmc/leaves/protocol/CarpetAlternativeBlockPlacement.java b/src/main/java/org/leavesmc/leaves/protocol/CarpetAlternativeBlockPlacement.java
new file mode 100644
index 0000000000000000000000000000000000000000..03978356d2716296f8c5e4173d10862db57a3193
index 0000000000000000000000000000000000000000..e5c5bee2518ff2843270979d36d264f17a5cf0a6
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/CarpetAlternativeBlockPlacement.java
@@ -0,0 +1,162 @@
@@ -0,0 +1,167 @@
+package org.leavesmc.leaves.protocol;
+
+import net.minecraft.core.BlockPos;
Expand All @@ -128,7 +128,7 @@ index 0000000000000000000000000000000000000000..03978356d2716296f8c5e4173d10862d
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.level.block.state.properties.ComparatorMode;
+import net.minecraft.world.level.block.state.properties.DirectionProperty;
+import net.minecraft.world.level.block.state.properties.EnumProperty;
+import net.minecraft.world.level.block.state.properties.Half;
+import net.minecraft.world.level.block.state.properties.Property;
+import net.minecraft.world.level.block.state.properties.SlabType;
Expand All @@ -152,7 +152,7 @@ index 0000000000000000000000000000000000000000..03978356d2716296f8c5e4173d10862d
+ return null;
+ }
+
+ DirectionProperty directionProp = getFirstDirectionProperty(state);
+ EnumProperty<Direction> directionProp = getFirstDirectionProperty(state);
+ int protocolValue = ((int) relativeHitX - 2) / 2;
+
+ if (directionProp != null) {
Expand Down Expand Up @@ -209,7 +209,8 @@ index 0000000000000000000000000000000000000000..03978356d2716296f8c5e4173d10862d
+ return state;
+ }
+
+ public static BlockState alternativeBlockPlacementFix(Block block, BlockPlaceContext context) {
+ @Nullable
+ public static BlockState alternativeBlockPlacementFix(Block block, @NotNull BlockPlaceContext context) {
+ Direction facing;
+ Vec3 vec3d = context.getClickLocation();
+ BlockPos pos = context.getClickedPos();
Expand Down Expand Up @@ -258,22 +259,26 @@ index 0000000000000000000000000000000000000000..03978356d2716296f8c5e4173d10862d
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Nullable
+ public static DirectionProperty getFirstDirectionProperty(@NotNull BlockState state) {
+ public static EnumProperty<Direction> getFirstDirectionProperty(@NotNull BlockState state) {
+ for (Property<?> prop : state.getProperties()) {
+ if (prop instanceof DirectionProperty) {
+ return (DirectionProperty) prop;
+ if (prop instanceof EnumProperty<?> enumProperty) {
+ if (enumProperty.getValueClass().equals(Direction.class)) {
+ return (EnumProperty<Direction>) enumProperty;
+ }
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a4688f9eb
index 0000000000000000000000000000000000000000..eceb1b8322fa50809990636e6caed491828e2fd6
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java
@@ -0,0 +1,209 @@
@@ -0,0 +1,214 @@
+package org.leavesmc.leaves.protocol;
+
+import com.google.common.collect.ImmutableSet;
Expand All @@ -287,10 +292,11 @@ index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a
+import net.minecraft.world.level.block.BedBlock;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.level.block.state.properties.DirectionProperty;
+import net.minecraft.world.level.block.state.properties.EnumProperty;
+import net.minecraft.world.level.block.state.properties.Property;
+import net.minecraft.world.level.block.state.properties.SlabType;
+import net.minecraft.world.phys.Vec3;
+import org.jetbrains.annotations.NotNull;
+import org.leavesmc.leaves.LeavesLogger;
+
+import javax.annotation.Nullable;
Expand All @@ -311,6 +317,8 @@ index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a
+ BlockStateProperties.CHEST_TYPE,
+ BlockStateProperties.MODE_COMPARATOR,
+ BlockStateProperties.DOOR_HINGE,
+ BlockStateProperties.FACING_HOPPER,
+ BlockStateProperties.HORIZONTAL_FACING,
+ BlockStateProperties.ORIENTATION,
+ BlockStateProperties.RAIL_SHAPE,
+ BlockStateProperties.RAIL_SHAPE_STRAIGHT,
Expand All @@ -326,14 +334,15 @@ index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a
+ return applyPlacementProtocolV3(state, UseContext.from(context, context.getHand()));
+ }
+
+ private static <T extends Comparable<T>> BlockState applyPlacementProtocolV3(BlockState state, UseContext context) {
+ @Nullable
+ private static <T extends Comparable<T>> BlockState applyPlacementProtocolV3(BlockState state, @NotNull UseContext context) {
+ int protocolValue = (int) (context.getHitVec().x - (double) context.getPos().getX()) - 2;
+ BlockState oldState = state;
+ if (protocolValue < 0) {
+ return oldState;
+ }
+
+ @Nullable DirectionProperty property = CarpetAlternativeBlockPlacement.getFirstDirectionProperty(state);
+ EnumProperty<Direction> property = CarpetAlternativeBlockPlacement.getFirstDirectionProperty(state);
+
+ if (property != null && property != BlockStateProperties.VERTICAL_DIRECTION) {
+ state = applyDirectionProperty(state, context, property, protocolValue);
Expand All @@ -358,7 +367,7 @@ index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a
+
+ try {
+ for (Property<?> p : propList) {
+ if (!(p instanceof DirectionProperty) && WHITELISTED_PROPERTIES.contains(p)) {
+ if (((p instanceof EnumProperty<?> ep) && !ep.getValueClass().equals(Direction.class)) && WHITELISTED_PROPERTIES.contains(p)) {
+ @SuppressWarnings("unchecked")
+ Property<T> prop = (Property<T>) p;
+ List<T> list = new ArrayList<>(prop.getPossibleValues());
Expand Down Expand Up @@ -386,7 +395,7 @@ index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a
+ }
+ }
+ } catch (Exception e) {
+ LeavesLogger.LOGGER.warning("Exception trying to apply placement protocol value");
+ LeavesLogger.LOGGER.warning("Exception trying to apply placement protocol value", e);
+ }
+
+ if (state.canSurvive(context.getWorld(), context.getPos())) {
Expand All @@ -396,7 +405,7 @@ index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a
+ }
+ }
+
+ private static BlockState applyDirectionProperty(BlockState state, UseContext context, DirectionProperty property, int protocolValue) {
+ private static BlockState applyDirectionProperty(BlockState state, UseContext context, EnumProperty<Direction> property, int protocolValue) {
+ Direction facingOrig = state.getValue(property);
+ Direction facing = facingOrig;
+ int decodedFacingIndex = (protocolValue & 0xF) >> 1;
Expand Down Expand Up @@ -448,7 +457,8 @@ index 0000000000000000000000000000000000000000..92f90ebf04f00341360e9e0ba1da5e0a
+ this.itemPlacementContext = itemPlacementContext;
+ }
+
+ public static UseContext from(BlockPlaceContext ctx, InteractionHand hand) {
+ @NotNull
+ public static UseContext from(@NotNull BlockPlaceContext ctx, InteractionHand hand) {
+ Vec3 pos = ctx.getClickLocation();
+ return new UseContext(ctx.getLevel(), ctx.getClickedPos(), ctx.getClickedFace(), new Vec3(pos.x, pos.y, pos.z), ctx.getPlayer(), hand, ctx);
+ }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ index aaaadb7be8abf867624a1ca83371595bef4ab633..d2ed6f4d066833ca31db02ca8826f5ed
list1 = List.of();
}
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
index 9f188a921781f9620b6dcdc6c7549a8a4709efa1..346e5e82b5cfed3dbe5363c153015a8e37ef79ca 100644
index 4772d0b1c70213bb73aa22eca820ade21335b3a8..c553badbf28ce6aec7750d33a46f3f5e1a0df4d5 100644
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
@@ -131,7 +131,12 @@ public final class NaturalSpawner {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ index c7f0a3e36959843b557615f55d32e6f1b3e9f456..8ebc52da0f6914e5641e2f5a220a0e94
+ // Leaves end - force void trade
}
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
index a98f9c22f8485ff3a9812cce19d47a0b08f2c054..5f1b12bc2294d7c2e21c9bea212e29dbb93c7e02 100644
index 662c46e465feaf3917a93a6f8942febb25590922..5e83099ac5e3698debd4ff5eb97d0ba3347c2ea8 100644
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
@@ -348,6 +348,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
Expand Down
Loading

0 comments on commit 1abd354

Please sign in to comment.