From 53f456320c2e297a57381aefb0fa5a9d1b19cb4e Mon Sep 17 00:00:00 2001 From: altrisi Date: Wed, 16 Feb 2022 00:03:44 +0100 Subject: [PATCH] Implement missing method in `BlockValue.PlacementContext` to fix exceptions in `place_item` (#1329) --- src/main/java/carpet/script/api/WorldAccess.java | 8 ++++++-- src/main/java/carpet/script/value/BlockValue.java | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 423c7a07..f6db8318 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -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(); diff --git a/src/main/java/carpet/script/value/BlockValue.java b/src/main/java/carpet/script/value/BlockValue.java index 5c1760c2..d8ec6e84 100644 --- a/src/main/java/carpet/script/value/BlockValue.java +++ b/src/main/java/carpet/script/value/BlockValue.java @@ -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;