mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
Fix LitematicaEasyPlaceProtocol * 2
This commit is contained in:
@@ -9,34 +9,15 @@ MasaGadget(https://github.com/plusls/MasaGadget)
|
|||||||
litematica(https://github.com/maruohon/litematica)
|
litematica(https://github.com/maruohon/litematica)
|
||||||
|
|
||||||
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
||||||
index 6db566adf2d0df1d26221eda04aa01738df6d3d2..14387fa191fb52aaa8b25396292c1d528a6aed17 100644
|
index 6db566adf2d0df1d26221eda04aa01738df6d3d2..8f112f382190d606a87f38da8bcdf8dd5f31d1c5 100644
|
||||||
--- a/net/minecraft/world/item/BlockItem.java
|
--- a/net/minecraft/world/item/BlockItem.java
|
||||||
+++ b/net/minecraft/world/item/BlockItem.java
|
+++ b/net/minecraft/world/item/BlockItem.java
|
||||||
@@ -150,6 +150,27 @@ public class BlockItem extends Item {
|
@@ -149,7 +149,7 @@ public class BlockItem extends Item {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected BlockState getPlacementState(BlockPlaceContext context) {
|
protected BlockState getPlacementState(BlockPlaceContext context) {
|
||||||
BlockState stateForPlacement = this.getBlock().getStateForPlacement(context);
|
- BlockState stateForPlacement = this.getBlock().getStateForPlacement(context);
|
||||||
+ // Leaves start - alternativeBlockPlacement
|
+ BlockState stateForPlacement = this.getBlock().getRealStateForPlacement(context); // Leaves - alternativeBlockPlacement
|
||||||
+ switch (org.leavesmc.leaves.LeavesConfig.protocol.alternativeBlockPlacement) {
|
|
||||||
+ case CARPET -> {
|
|
||||||
+ BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacement(getBlock(), context);
|
|
||||||
+ if (tryState != null) {
|
|
||||||
+ stateForPlacement = tryState;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ case CARPET_FIX -> {
|
|
||||||
+ BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacementFix(getBlock(), context);
|
|
||||||
+ if (tryState != null) {
|
|
||||||
+ stateForPlacement = tryState;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ case LITEMATICA -> {
|
|
||||||
+ if (stateForPlacement != null && this.canPlace(context, stateForPlacement)) {
|
|
||||||
+ return org.leavesmc.leaves.protocol.LitematicaEasyPlaceProtocol.applyPlacementProtocol(stateForPlacement, context);
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ // Leaves end - alternativeBlockPlacement
|
|
||||||
return stateForPlacement != null && this.canPlace(context, stateForPlacement) ? stateForPlacement : null;
|
return stateForPlacement != null && this.canPlace(context, stateForPlacement) ? stateForPlacement : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +43,7 @@ index 12c6c8aeec89a0a55633c62fe98f5a3aa75fd476..1f0e7c391d02b18e2c89700025713ec3
|
|||||||
blockState = blockState1;
|
blockState = blockState1;
|
||||||
break;
|
break;
|
||||||
diff --git a/net/minecraft/world/level/block/Block.java b/net/minecraft/world/level/block/Block.java
|
diff --git a/net/minecraft/world/level/block/Block.java b/net/minecraft/world/level/block/Block.java
|
||||||
index 958914e40fceda5d67a98154817b4c5ce478a62d..02ea7616e0c19032374959f59a9ab186e91c5f7b 100644
|
index 958914e40fceda5d67a98154817b4c5ce478a62d..3c5fd8efbe577c9b262870444984ad249097b8c2 100644
|
||||||
--- a/net/minecraft/world/level/block/Block.java
|
--- a/net/minecraft/world/level/block/Block.java
|
||||||
+++ b/net/minecraft/world/level/block/Block.java
|
+++ b/net/minecraft/world/level/block/Block.java
|
||||||
@@ -439,6 +439,33 @@ public class Block extends BlockBehaviour implements ItemLike {
|
@@ -439,6 +439,33 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||||
@@ -72,7 +53,7 @@ index 958914e40fceda5d67a98154817b4c5ce478a62d..02ea7616e0c19032374959f59a9ab186
|
|||||||
+ // Leaves start - alternativeBlockPlacement
|
+ // Leaves start - alternativeBlockPlacement
|
||||||
+ @Nullable
|
+ @Nullable
|
||||||
+ public BlockState getRealStateForPlacement(BlockPlaceContext ctx) {
|
+ public BlockState getRealStateForPlacement(BlockPlaceContext ctx) {
|
||||||
+ BlockState vanillaState = getStateForPlacement(ctx);
|
+ BlockState vanillaState = this.getStateForPlacement(ctx);
|
||||||
+ switch (org.leavesmc.leaves.LeavesConfig.protocol.alternativeBlockPlacement) {
|
+ switch (org.leavesmc.leaves.LeavesConfig.protocol.alternativeBlockPlacement) {
|
||||||
+ case CARPET -> {
|
+ case CARPET -> {
|
||||||
+ BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacement(this, ctx);
|
+ BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacement(this, ctx);
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ index 8ec6f52f58bcc985fdc758a692798a35d6c86378..0d046133ea2b6d47e089cb792cf3bc3a
|
|||||||
public boolean canBeHitByProjectile() {
|
public boolean canBeHitByProjectile() {
|
||||||
return !this.isSpectator() && super.canBeHitByProjectile();
|
return !this.isSpectator() && super.canBeHitByProjectile();
|
||||||
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
||||||
index eff2c0418e1dc8dff1b9045d8f6ff619100964d1..8b6bbdf44a840e19722d42aec91fa1f8805f917b 100644
|
index a46a50d1385897cc7fcf0d6976f0de7e8078d260..593e65ef3a768d4039047e42e666c8382a5d38eb 100644
|
||||||
--- a/net/minecraft/world/item/BlockItem.java
|
--- a/net/minecraft/world/item/BlockItem.java
|
||||||
+++ b/net/minecraft/world/item/BlockItem.java
|
+++ b/net/minecraft/world/item/BlockItem.java
|
||||||
@@ -206,8 +206,9 @@ public class BlockItem extends Item {
|
@@ -185,8 +185,9 @@ public class BlockItem extends Item {
|
||||||
protected boolean canPlace(BlockPlaceContext context, BlockState state) {
|
protected boolean canPlace(BlockPlaceContext context, BlockState state) {
|
||||||
Player player = context.getPlayer();
|
Player player = context.getPlayer();
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.leavesmc.leaves.protocol;
|
package org.leavesmc.leaves.protocol;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
@@ -10,7 +9,7 @@ import net.minecraft.world.entity.LivingEntity;
|
|||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.BedBlock;
|
import net.minecraft.world.level.block.BedBlock;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.RepeaterBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
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.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
@@ -24,8 +23,6 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
public class LitematicaEasyPlaceProtocol {
|
public class LitematicaEasyPlaceProtocol {
|
||||||
|
|
||||||
@@ -53,10 +50,6 @@ public class LitematicaEasyPlaceProtocol {
|
|||||||
BlockStateProperties.ROTATION_16
|
BlockStateProperties.ROTATION_16
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final ImmutableMap<Property<?>, BiFunction<BlockState, BlockState, BlockState>> DYNAMIC_PROPERTIES = ImmutableMap.of(
|
|
||||||
BlockStateProperties.WATERLOGGED, (state, original) -> state.setValue(BlockStateProperties.WATERLOGGED, original.is(Blocks.WATER))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static BlockState applyPlacementProtocol(BlockState state, BlockPlaceContext context) {
|
public static BlockState applyPlacementProtocol(BlockState state, BlockPlaceContext context) {
|
||||||
return applyPlacementProtocolV3(state, UseContext.from(context, context.getHand()));
|
return applyPlacementProtocolV3(state, UseContext.from(context, context.getHand()));
|
||||||
}
|
}
|
||||||
@@ -71,17 +64,6 @@ public class LitematicaEasyPlaceProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EnumProperty<Direction> property = CarpetAlternativeBlockPlacement.getFirstDirectionProperty(state);
|
EnumProperty<Direction> property = CarpetAlternativeBlockPlacement.getFirstDirectionProperty(state);
|
||||||
BlockState original = context.getWorld().getBlockStateIfLoaded(context.pos);
|
|
||||||
if (original == null) {
|
|
||||||
return oldState;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<Property<?>, BiFunction<BlockState, BlockState, BlockState>> entry : DYNAMIC_PROPERTIES.entrySet()) {
|
|
||||||
if (state.hasProperty(entry.getKey())) {
|
|
||||||
state = entry.getValue().apply(state, original);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property != null && property != BlockStateProperties.VERTICAL_DIRECTION) {
|
if (property != null && property != BlockStateProperties.VERTICAL_DIRECTION) {
|
||||||
state = applyDirectionProperty(state, context, property, protocolValue);
|
state = applyDirectionProperty(state, context, property, protocolValue);
|
||||||
|
|
||||||
@@ -140,6 +122,10 @@ public class LitematicaEasyPlaceProtocol {
|
|||||||
LeavesLogger.LOGGER.warning("Exception trying to apply placement protocol value", e);
|
LeavesLogger.LOGGER.warning("Exception trying to apply placement protocol value", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state.getBlock() instanceof RepeaterBlock repeaterBlock) {
|
||||||
|
state = state.setValue(RepeaterBlock.LOCKED, repeaterBlock.isLocked(context.getWorld(), context.getPos(), state));
|
||||||
|
}
|
||||||
|
|
||||||
if (state.canSurvive(context.getWorld(), context.getPos())) {
|
if (state.canSurvive(context.getWorld(), context.getPos())) {
|
||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user