Implement missing method in BlockValue.PlacementContext to fix exceptions in place_item (#1329)

This commit is contained in:
altrisi authored and GitHub committed 2022-02-16 00:03:44 +01:00
1 parent 91eefb4608
commit 53f456320c
2 files changed
+12 -3

No files matched your search

@@ -1006,9 +1006,13 @@ public class WorldAccess {
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
ItemInput stackArg = NBTSerializableValue.parseItem(itemString);
BlockPos where = new BlockPos(locator.vec);
String facing = "up";
if (lv.size() > locator.offset)
String facing;
if (lv.size() > locator.offset) {
facing = lv.get(locator.offset).getString();
} else {
// Paintings throw an exception if their direction is vertical, therefore we change the default here
facing = stackArg.getItem() != Items.PAINTING ? "up" : "north";
}
boolean sneakPlace = false;
if (lv.size() > locator.offset+1)
sneakPlace = lv.get(locator.offset+1).getBoolean();
@@ -10,13 +10,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.GlobalPos;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
@@ -314,6 +314,11 @@ public class BlockValue extends Value
return this.facing.getAxis() == Direction.Axis.Y ? Direction.NORTH : this.facing;
}
@Override
public Direction getNearestLookingVerticalDirection() {
return facing.getAxis() == Axis.Y ? facing : Direction.UP;
}
@Override
public boolean isSecondaryUseActive() {
return sneakPlace;