diff --git a/src/generated/resources/assets/pylons/lang/en_us.json b/src/generated/resources/assets/pylons/lang/en_us.json index 43312ad..72d5f91 100644 --- a/src/generated/resources/assets/pylons/lang/en_us.json +++ b/src/generated/resources/assets/pylons/lang/en_us.json @@ -3,6 +3,7 @@ "block.pylons.infusion_pylon": "Infusion Pylon", "chat.pylons.expelled": "You have been expelled from %s's chunk!", "gui.pylons.effects": "Active potion effects:", + "gui.pylons.insideWorldSpawn": "Too close to world spawn.", "gui.pylons.noOwner": "Owner not found. Pylon disabled.", "gui.pylons.owner": "Owner: %s", "gui.pylons.whitelist": "Add players to whitelist:", diff --git a/src/main/java/net/permutated/pylons/client/gui/ExpulsionPylonScreen.java b/src/main/java/net/permutated/pylons/client/gui/ExpulsionPylonScreen.java index 8f771dd..115e42d 100644 --- a/src/main/java/net/permutated/pylons/client/gui/ExpulsionPylonScreen.java +++ b/src/main/java/net/permutated/pylons/client/gui/ExpulsionPylonScreen.java @@ -16,10 +16,13 @@ public ExpulsionPylonScreen(ExpulsionPylonContainer container, Inventory inv, Co @Override protected void renderLabels(PoseStack matrixStack, int mouseX, int mouseY) { super.renderLabels(matrixStack, mouseX, mouseY); - if (this.menu.isAllowedDimension()) { - drawText(matrixStack, translate("whitelist"), 36); - } else { + + if (!this.menu.isAllowedDimension()) { drawText(matrixStack, translate("wrongDimension").withStyle(ChatFormatting.RED), 36); + } else if (!this.menu.isAllowedLocation()) { + drawText(matrixStack, translate("insideWorldSpawn").withStyle(ChatFormatting.RED), 36); + } else { + drawText(matrixStack, translate("whitelist"), 36); } } } diff --git a/src/main/java/net/permutated/pylons/data/client/Languages.java b/src/main/java/net/permutated/pylons/data/client/Languages.java index 2974535..e84ffbe 100644 --- a/src/main/java/net/permutated/pylons/data/client/Languages.java +++ b/src/main/java/net/permutated/pylons/data/client/Languages.java @@ -29,6 +29,7 @@ protected void addTranslations() { add(gui("owner"), "Owner: %s"); add(gui("noOwner"), "Owner not found. Pylon disabled."); add(gui("wrongDimension"), "This dimension is disabled."); + add(gui("insideWorldSpawn"), "Too close to world spawn."); add(gui("whitelist"), "Add players to whitelist:"); add(gui("effects"), "Active potion effects:"); add(tab(), "Pylons"); diff --git a/src/main/java/net/permutated/pylons/inventory/container/ExpulsionPylonContainer.java b/src/main/java/net/permutated/pylons/inventory/container/ExpulsionPylonContainer.java index a3f426d..f7ee54a 100644 --- a/src/main/java/net/permutated/pylons/inventory/container/ExpulsionPylonContainer.java +++ b/src/main/java/net/permutated/pylons/inventory/container/ExpulsionPylonContainer.java @@ -9,10 +9,12 @@ public class ExpulsionPylonContainer extends AbstractPylonContainer { private final boolean allowedDimension; + private final boolean allowedLocation; public ExpulsionPylonContainer(int windowId, Inventory playerInventory, FriendlyByteBuf packetBuffer) { super(ModRegistry.EXPULSION_PYLON_CONTAINER.get(), windowId, playerInventory, packetBuffer); allowedDimension = packetBuffer.readBoolean(); + allowedLocation = packetBuffer.readBoolean(); } @Override @@ -23,4 +25,8 @@ protected RegistryObject getBlock() { public boolean isAllowedDimension() { return allowedDimension; } + + public boolean isAllowedLocation() { + return allowedLocation; + } } diff --git a/src/main/java/net/permutated/pylons/tile/ExpulsionPylonTile.java b/src/main/java/net/permutated/pylons/tile/ExpulsionPylonTile.java index 9d7a772..07fdb93 100644 --- a/src/main/java/net/permutated/pylons/tile/ExpulsionPylonTile.java +++ b/src/main/java/net/permutated/pylons/tile/ExpulsionPylonTile.java @@ -16,6 +16,7 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -50,7 +51,7 @@ protected boolean isItemValid(ItemStack stack) { @Override public void tick() { - if (level != null && !level.isClientSide && canTick(10) && owner != null && isAllowedDimension()) { + if (level != null && !level.isClientSide && canTick(10) && owner != null && isAllowedDimension() && isAllowedLocation()) { LevelChunk chunk = level.getChunkAt(worldPosition); var chunkPos = chunk.getPos(); @@ -83,6 +84,7 @@ public void tick() { public void updateContainer(FriendlyByteBuf packetBuffer) { super.updateContainer(packetBuffer); packetBuffer.writeBoolean(isAllowedDimension()); + packetBuffer.writeBoolean(isAllowedLocation()); } public boolean isAllowedDimension() { @@ -100,6 +102,20 @@ public boolean isAllowedDimension() { return false; } + public boolean isAllowedLocation() { + if (level instanceof ServerLevel serverLevel) { + int spawnRadius = serverLevel.getGameRules().getInt(GameRules.RULE_SPAWN_RADIUS); + int configRadius = ConfigManager.COMMON.expulsionWorldSpawnRadius.get(); + + var bb = new BoundingBox(serverLevel.getSharedSpawnPos()); + var area = bb.inflatedBy(Math.max(configRadius, spawnRadius)); + + return !area.intersects(getBlockPos().getX(), getBlockPos().getZ(), getBlockPos().getX(), getBlockPos().getZ()); + } else { + return false; + } + } + /** * Iterates over Player Filters in the inventory and returns a list with all found UUIDs * @@ -156,11 +172,6 @@ private void doRespawn(MinecraftServer server, ServerPlayer player) { } } - // is the pylon within the world spawn radius? - if (inWorldSpawn(server, actualLevel)) { - return; - } - while (!actualLevel.noCollision(dummyPlayer) && dummyPlayer.getY() < 256.0D) { dummyPlayer.setPos(dummyPlayer.getX(), dummyPlayer.getY() + 1.0D, dummyPlayer.getZ()); } @@ -169,15 +180,7 @@ private void doRespawn(MinecraftServer server, ServerPlayer player) { player.sendMessage(new TranslatableComponent(TranslationKey.chat("expelled"), getOwnerName()).withStyle(ChatFormatting.RED), player.getUUID()); } - private boolean inWorldSpawn(MinecraftServer server, ServerLevel actualLevel) { - int spawnRadius = server.getSpawnRadius(actualLevel); - int configRadius = ConfigManager.COMMON.expulsionWorldSpawnRadius.get(); - var bb = new BoundingBox(actualLevel.getSharedSpawnPos()); - var area = bb.inflatedBy(Math.max(configRadius, spawnRadius)); - - return area.intersects(getBlockPos().getX(), getBlockPos().getZ(), getBlockPos().getX(), getBlockPos().getZ()); - } private boolean sameChunk(Level world, BlockPos target) { if (level != null && level.dimension() == world.dimension()) {