From d8c3b420455a04e9e41610ba38622d33388ffc18 Mon Sep 17 00:00:00 2001 From: agnor99 Date: Mon, 20 Feb 2023 20:54:16 +0100 Subject: [PATCH 1/2] Add gaia arena check to api --- .../java/vazkii/botania/api/BotaniaAPI.java | 9 +++++++++ .../botania/common/impl/BotaniaAPIImpl.java | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java b/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java index 4c0e580b82..dcc2d80b60 100644 --- a/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java +++ b/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java @@ -29,6 +29,7 @@ import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -220,4 +221,12 @@ default void sparkleFX(Level world, double x, double y, double z, float r, float default void registerCorporeaNodeDetector(CorporeaNodeDetector detector) { } + + default boolean isInGaiaArena(Entity entity) { + return isInGaiaArena(entity.getLevel(), entity.getX(), entity.getY(), entity.getZ()); + } + + default boolean isInGaiaArena(@Nullable Level level, double x, double y, double z) { + return false; + } } diff --git a/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java b/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java index d58182cdcf..2a76561097 100644 --- a/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java +++ b/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java @@ -27,8 +27,11 @@ import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.brew.Brew; @@ -37,6 +40,7 @@ import vazkii.botania.client.fx.SparkleParticleData; import vazkii.botania.common.block.flower.functional.SolegnoliaBlockEntity; import vazkii.botania.common.brew.BotaniaBrews; +import vazkii.botania.common.entity.GaiaGuardianEntity; import vazkii.botania.common.handler.BotaniaSounds; import vazkii.botania.common.handler.EquipmentHandler; import vazkii.botania.common.handler.ManaNetworkHandler; @@ -176,7 +180,7 @@ public Ingredient getRepairIngredient() { @Override public int apiVersion() { - return 2; + return 3; } @Override @@ -266,4 +270,17 @@ public void registerPaintableBlock(ResourceLocation block, Function guardianEntities = level.getEntitiesOfClass(GaiaGuardianEntity.class, AABB.ofSize(new Vec3(x, y, z), GaiaGuardianEntity.ARENA_RANGE * 4, GaiaGuardianEntity.ARENA_RANGE * 4, GaiaGuardianEntity.ARENA_RANGE * 4)); + for (GaiaGuardianEntity guardianEntity : guardianEntities) { + if (guardianEntity.getSource().distToCenterSqr(x, y, z) < GaiaGuardianEntity.ARENA_RANGE * GaiaGuardianEntity.ARENA_RANGE) { + return true; + } + } + return false; + } } From 3009b0765312851e3deaea9ea0bc5716d7dc5f33 Mon Sep 17 00:00:00 2001 From: agnor99 Date: Tue, 28 Feb 2023 14:22:20 +0100 Subject: [PATCH 2/2] use the arena provided by the guardian --- .../src/main/java/vazkii/botania/api/BotaniaAPI.java | 11 ++--------- .../botania/common/entity/GaiaGuardianEntity.java | 2 +- .../vazkii/botania/common/impl/BotaniaAPIImpl.java | 7 ++----- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java b/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java index dcc2d80b60..df97de6edc 100644 --- a/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java +++ b/Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java @@ -29,7 +29,6 @@ import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -218,15 +217,9 @@ default boolean hasSolegnoliaAround(Entity e) { default void sparkleFX(Level world, double x, double y, double z, float r, float g, float b, float size, int m) {} - default void registerCorporeaNodeDetector(CorporeaNodeDetector detector) { + default void registerCorporeaNodeDetector(CorporeaNodeDetector detector) {} - } - - default boolean isInGaiaArena(Entity entity) { - return isInGaiaArena(entity.getLevel(), entity.getX(), entity.getY(), entity.getZ()); - } - - default boolean isInGaiaArena(@Nullable Level level, double x, double y, double z) { + default boolean isInGaiaArena(Level level, double x, double y, double z) { return false; } } diff --git a/Xplat/src/main/java/vazkii/botania/common/entity/GaiaGuardianEntity.java b/Xplat/src/main/java/vazkii/botania/common/entity/GaiaGuardianEntity.java index bd07264986..aac252bc83 100644 --- a/Xplat/src/main/java/vazkii/botania/common/entity/GaiaGuardianEntity.java +++ b/Xplat/src/main/java/vazkii/botania/common/entity/GaiaGuardianEntity.java @@ -566,7 +566,7 @@ private static int countGaiaGuardiansAround(Level world, BlockPos source) { } @NotNull - private static AABB getArenaBB(@NotNull BlockPos source) { + public static AABB getArenaBB(@NotNull BlockPos source) { double range = 15.0; return new AABB(source.getX() + 0.5 - range, source.getY() + 0.5 - range, source.getZ() + 0.5 - range, source.getX() + 0.5 + range, source.getY() + 0.5 + range, source.getZ() + 0.5 + range); } diff --git a/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java b/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java index 2a76561097..8d0692aa89 100644 --- a/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java +++ b/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java @@ -31,7 +31,6 @@ import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.brew.Brew; @@ -272,12 +271,10 @@ public void registerCorporeaNodeDetector(CorporeaNodeDetector detector) { } @Override - public boolean isInGaiaArena(@Nullable Level level, double x, double y, double z) { - if (level == null) - return false; + public boolean isInGaiaArena(Level level, double x, double y, double z) { List guardianEntities = level.getEntitiesOfClass(GaiaGuardianEntity.class, AABB.ofSize(new Vec3(x, y, z), GaiaGuardianEntity.ARENA_RANGE * 4, GaiaGuardianEntity.ARENA_RANGE * 4, GaiaGuardianEntity.ARENA_RANGE * 4)); for (GaiaGuardianEntity guardianEntity : guardianEntities) { - if (guardianEntity.getSource().distToCenterSqr(x, y, z) < GaiaGuardianEntity.ARENA_RANGE * GaiaGuardianEntity.ARENA_RANGE) { + if (GaiaGuardianEntity.getArenaBB(guardianEntity.getSource()).contains(x, y, z)) { return true; } }