improve obstruction messages
This commit is contained in:
parent
897c1e5975
commit
e1eef02be4
|
@ -200,9 +200,9 @@ public class MyItem extends Item {
|
||||||
|
|
||||||
Vec3i size = x.getSize();
|
Vec3i size = x.getSize();
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case CLOCKWISE_90 -> loc = loc.add(new Vec3i(size.getX()-1, 0, 0));
|
case CLOCKWISE_90 -> loc = loc.add(new Vec3i(size.getX() - 1, 0, 0));
|
||||||
case CLOCKWISE_180 -> loc = loc.add(new Vec3i(size.getX()-1, 0, size.getZ()-1));
|
case CLOCKWISE_180 -> loc = loc.add(new Vec3i(size.getX() - 1, 0, size.getZ() - 1));
|
||||||
case COUNTERCLOCKWISE_90 -> loc = loc.add(new Vec3i(0, 0, size.getZ()-1));
|
case COUNTERCLOCKWISE_90 -> loc = loc.add(new Vec3i(0, 0, size.getZ() - 1));
|
||||||
}
|
}
|
||||||
} else if (tag.contains("offsetV2", 10)) {
|
} else if (tag.contains("offsetV2", 10)) {
|
||||||
Direction direction = c.getSide().getOpposite();
|
Direction direction = c.getSide().getOpposite();
|
||||||
|
@ -255,16 +255,21 @@ public class MyItem extends Item {
|
||||||
.setSize(x.getSize())
|
.setSize(x.getSize())
|
||||||
.setMirror(BlockMirror.NONE)
|
.setMirror(BlockMirror.NONE)
|
||||||
.setRotation(rotation);
|
.setRotation(rotation);
|
||||||
boolean success = false;
|
|
||||||
try {
|
try {
|
||||||
if (x.place((ServerWorld) c.getWorld(), loc, BlockPos.ORIGIN, ps, c.getWorld().getRandom(), 2))
|
if (x.place((ServerWorld) c.getWorld(), loc, BlockPos.ORIGIN, ps, c.getWorld().getRandom(), 2)) {
|
||||||
success = true;
|
|
||||||
} catch (PlacementNotAllowedException ignored) {
|
|
||||||
}
|
|
||||||
if (success) {
|
|
||||||
c.getStack().decrement(1);
|
c.getStack().decrement(1);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
} catch (PlacementNotAllowedException placementNotAllowedException) {
|
||||||
|
Text message =
|
||||||
|
Text.translatable("items.structure.spawner.invalid.location.reason",
|
||||||
|
placementNotAllowedException.getName(),
|
||||||
|
Text.literal(String.valueOf(placementNotAllowedException.getPos().getX())),
|
||||||
|
Text.literal(String.valueOf(placementNotAllowedException.getPos().getY())),
|
||||||
|
Text.literal(String.valueOf(placementNotAllowedException.getPos().getZ())));
|
||||||
|
sendPlayer(player, message);
|
||||||
|
return ActionResult.FAIL;
|
||||||
|
}
|
||||||
Text message =
|
Text message =
|
||||||
Text.translatable("items.structure.spawner.invalid.location");
|
Text.translatable("items.structure.spawner.invalid.location");
|
||||||
sendPlayer(player, message);
|
sendPlayer(player, message);
|
||||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldView;
|
import net.minecraft.world.WorldView;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MyPlacementSettings extends StructurePlacementData {
|
public class MyPlacementSettings extends StructurePlacementData {
|
||||||
|
@ -75,12 +74,13 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||||
if (currentBlockInfo != null && World.isValid(posToCheck = currentBlockInfo.pos())) {
|
if (currentBlockInfo != null && World.isValid(posToCheck = currentBlockInfo.pos())) {
|
||||||
for (Entity e : entitiesWithinAABB) {
|
for (Entity e : entitiesWithinAABB) {
|
||||||
if (e.getBoundingBox().intersects(new Box(posToCheck))) {
|
if (e.getBoundingBox().intersects(new Box(posToCheck))) {
|
||||||
throw new PlacementNotAllowedException();
|
throw new PlacementNotAllowedException(e.getName(), posToCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Block blockToCheck = world.getBlockState(posToCheck).getBlock();
|
Block blockToCheck = world.getBlockState(posToCheck).getBlock();
|
||||||
if (blacklist.contains(blockToCheck))
|
if (blacklist.contains(blockToCheck)) {
|
||||||
throw new PlacementNotAllowedException();
|
throw new PlacementNotAllowedException(blockToCheck.getName(), posToCheck);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return currentBlockInfo;
|
return currentBlockInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,22 @@
|
||||||
package quimufu.structure_item;
|
package quimufu.structure_item;
|
||||||
|
|
||||||
public class PlacementNotAllowedException extends RuntimeException{
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class PlacementNotAllowedException extends RuntimeException {
|
||||||
|
private final Text name;
|
||||||
|
private final BlockPos pos;
|
||||||
|
|
||||||
|
public PlacementNotAllowedException(Text name, BlockPos pos) {
|
||||||
|
this.name = name;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getPos() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"items.structure.spawner.invalid.block.clicked": "Digga %s is net %s, maan.",
|
"items.structure.spawner.invalid.block.clicked": "Can only be placed on %2$s, not %1$s.",
|
||||||
|
"items.structure.spawner.invalid.location.reason": "%s is in the way at %s, %s, %s!",
|
||||||
"items.structure.spawner.invalid.location": "Something is in the way!",
|
"items.structure.spawner.invalid.location": "Something is in the way!",
|
||||||
"items.structure.spawner.invalid.structure.name": "Invalid structure name",
|
"items.structure.spawner.invalid.structure.name": "Invalid structure name",
|
||||||
"items.structure.spawner.structure.nonexistent": "Structure: %s does not exist",
|
"items.structure.spawner.structure.nonexistent": "Structure: %s does not exist",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user