From 78b55db04bd81576bacc7829b0bfa8eb711e1e6b Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:04:45 -0700 Subject: [PATCH] Add ISpectacleBlock API so that addon mods can have their blocks highlighted by players wearing spectacles --- changelog.md | 1 + .../forestry/api/core/ISpectacleBlock.java | 18 ++++++++++++++++++ .../forestry/apiculture/tiles/TileHive.java | 5 +++-- .../arboriculture/tiles/TileLeaves.java | 9 ++++++++- .../core/client/CoreClientHandler.java | 5 ++--- .../MultiblockTileEntityForestry.java | 9 +++++++-- 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/main/java/forestry/api/core/ISpectacleBlock.java diff --git a/changelog.md b/changelog.md index ad8ea0d2a..ec5ebb56e 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ - Fixed incorrect translation of ru_ru.json (#101) - Add additional constructor to GuiForestryTitled that accepts ResourceLocation - Fix Alvearies and Multifarms not dropping their inventories when destroyed (#100) +- Add ISpectacleBlock API so that addon mods can have their blocks highlighted by players wearing spectacles ## Forestry 1.0.10 - Fixed Grafter for Forestry trees (#95) diff --git a/src/main/java/forestry/api/core/ISpectacleBlock.java b/src/main/java/forestry/api/core/ISpectacleBlock.java new file mode 100644 index 000000000..0c7a7a00e --- /dev/null +++ b/src/main/java/forestry/api/core/ISpectacleBlock.java @@ -0,0 +1,18 @@ +package forestry.api.core; + +import net.minecraft.world.entity.player.Player; + +/** + * Implement this interface on your block entities so that players wearing Spectacles can see them more easily. + */ +public interface ISpectacleBlock { + /** + * Determines whether a highlight should be drawn around this block. + * + * @param player The player wearing spectacles. + * @return {@code true} if a highlighted bounding box should be drawn around this block, {@code false} otherwise. + */ + default boolean isHighlighted(Player player) { + return true; + } +} diff --git a/src/main/java/forestry/apiculture/tiles/TileHive.java b/src/main/java/forestry/apiculture/tiles/TileHive.java index b8d10f3cf..deb257d6f 100644 --- a/src/main/java/forestry/apiculture/tiles/TileHive.java +++ b/src/main/java/forestry/apiculture/tiles/TileHive.java @@ -53,8 +53,10 @@ import forestry.api.apiculture.hives.IHiveTile; import forestry.api.core.HumidityType; import forestry.api.core.IErrorLogic; +import forestry.api.core.ISpectacleBlock; import forestry.api.core.TemperatureType; import forestry.api.genetics.capability.IIndividualHandlerItem; +import forestry.api.util.TickHelper; import forestry.apiculture.ModuleApiculture; import forestry.apiculture.WorldgenBeekeepingLogic; import forestry.apiculture.blocks.BlockBeeHive; @@ -68,11 +70,10 @@ import forestry.core.utils.ItemStackUtil; import forestry.core.utils.NetworkUtil; import forestry.core.utils.SpeciesUtil; -import forestry.api.util.TickHelper; import org.jetbrains.annotations.ApiStatus; -public class TileHive extends BlockEntity implements IHiveTile, IActivatable, IBeeHousing { +public class TileHive extends BlockEntity implements IHiveTile, IActivatable, IBeeHousing, ISpectacleBlock { private static final DamageSource damageSourceBeeHive = new DamageSourceForestry("bee.hive"); private final InventoryAdapter contained = new InventoryAdapter(2, "Contained"); diff --git a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java index 8bb94147b..0ac01ecb7 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java @@ -21,6 +21,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; @@ -40,6 +41,7 @@ import forestry.api.client.IForestryClientApi; import forestry.api.climate.IBiomeProvider; import forestry.api.core.HumidityType; +import forestry.api.core.ISpectacleBlock; import forestry.api.core.TemperatureType; import forestry.api.genetics.IEffectData; import forestry.api.genetics.IFruitBearer; @@ -59,7 +61,7 @@ import forestry.core.utils.NetworkUtil; import forestry.core.utils.SpeciesUtil; -public class TileLeaves extends TileTreeContainer implements IFruitBearer, IButterflyNursery, IRipeningPacketReceiver, IBiomeProvider { +public class TileLeaves extends TileTreeContainer implements IFruitBearer, IButterflyNursery, IRipeningPacketReceiver, IBiomeProvider, ISpectacleBlock { private static final String NBT_RIPENING = "RT"; private static final String NBT_DAMAGE = "ENC"; private static final String NBT_FRUIT_LEAF = "FL"; @@ -485,4 +487,9 @@ public HumidityType humidity() { public Level getWorldObj() { return level; } + + @Override + public boolean isHighlighted(Player player) { + return isPollinated(); + } } diff --git a/src/main/java/forestry/core/client/CoreClientHandler.java b/src/main/java/forestry/core/client/CoreClientHandler.java index 0bca9e7c4..d0501079f 100644 --- a/src/main/java/forestry/core/client/CoreClientHandler.java +++ b/src/main/java/forestry/core/client/CoreClientHandler.java @@ -47,13 +47,12 @@ import forestry.api.client.IClientModuleHandler; import forestry.api.client.IForestryClientApi; +import forestry.api.core.ISpectacleBlock; import forestry.apiculture.features.ApicultureBlocks; import forestry.apiculture.features.ApicultureItems; -import forestry.apiculture.tiles.TileHive; import forestry.apiimpl.plugin.PluginManager; import forestry.arboriculture.features.ArboricultureBlocks; import forestry.arboriculture.features.ArboricultureItems; -import forestry.arboriculture.tiles.TileLeaves; import forestry.core.circuits.GuiSolderingIron; import forestry.core.config.Constants; import forestry.core.features.CoreBlocks; @@ -300,7 +299,7 @@ private static void onClientTick(RenderLevelStageEvent event) { // Get all block entities in the chunk for (BlockEntity be : chunk.getBlockEntities().values()) { - if (be instanceof TileHive || (be instanceof TileLeaves leaves && leaves.isPollinated())) { + if (be instanceof ISpectacleBlock naturalist && naturalist.isHighlighted(player)) { BlockPos pos = be.getBlockPos(); stack.pushPose(); diff --git a/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java b/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java index 2699306f6..e1f0fd933 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java +++ b/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java @@ -30,6 +30,7 @@ import net.minecraftforge.network.NetworkHooks; import forestry.api.core.ILocationProvider; +import forestry.api.core.ISpectacleBlock; import forestry.api.multiblock.IMultiblockLogic; import forestry.api.multiblock.MultiblockTileEntityBase; import forestry.core.config.Constants; @@ -37,7 +38,7 @@ import forestry.core.inventory.IInventoryAdapter; import forestry.core.tiles.IFilterSlotDelegate; -public abstract class MultiblockTileEntityForestry extends MultiblockTileEntityBase implements WorldlyContainer, IFilterSlotDelegate, ILocationProvider, MenuProvider { +public abstract class MultiblockTileEntityForestry extends MultiblockTileEntityBase implements WorldlyContainer, IFilterSlotDelegate, ILocationProvider, MenuProvider, ISpectacleBlock { @Nullable private GameProfile owner; @@ -188,9 +189,13 @@ public final void setOwner(GameProfile owner) { this.owner = owner; } - @Override public void clearContent() { getInternalInventory().clearContent(); } + + @Override + public boolean isHighlighted(Player player) { + return player.isCreative() && getMultiblockLogic().getController() instanceof IMultiblockControllerInternal internal && this.worldPosition.equals(internal.getReferenceCoord()); + } }