Skip to content

Commit

Permalink
Add ISpectacleBlock API so that addon mods can have their blocks high…
Browse files Browse the repository at this point in the history
…lighted by players wearing spectacles
  • Loading branch information
thedarkcolour committed Oct 15, 2024
1 parent d8f07d2 commit 78b55db
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/forestry/api/core/ISpectacleBlock.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 3 additions & 2 deletions src/main/java/forestry/apiculture/tiles/TileHive.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/forestry/arboriculture/tiles/TileLeaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -485,4 +487,9 @@ public HumidityType humidity() {
public Level getWorldObj() {
return level;
}

@Override
public boolean isHighlighted(Player player) {
return isPollinated();
}
}
5 changes: 2 additions & 3 deletions src/main/java/forestry/core/client/CoreClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
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;
import forestry.core.inventory.FakeInventoryAdapter;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.tiles.IFilterSlotDelegate;

public abstract class MultiblockTileEntityForestry<T extends IMultiblockLogic> extends MultiblockTileEntityBase<T> implements WorldlyContainer, IFilterSlotDelegate, ILocationProvider, MenuProvider {
public abstract class MultiblockTileEntityForestry<T extends IMultiblockLogic> extends MultiblockTileEntityBase<T> implements WorldlyContainer, IFilterSlotDelegate, ILocationProvider, MenuProvider, ISpectacleBlock {
@Nullable
private GameProfile owner;

Expand Down Expand Up @@ -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());
}
}

0 comments on commit 78b55db

Please sign in to comment.