Skip to content

Commit

Permalink
Make TileAlveary extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkcolour committed Oct 7, 2024
1 parent fe5dd4c commit 76a62d6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/main/java/forestry/api/multiblock/IAlvearyComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public interface IAlvearyComponent<T extends IMultiblockLogicAlveary> extends IM
/**
* Implemented by alveary parts to apply a beeListener to the completed structure.
*/
interface BeeListener extends IAlvearyComponent {
interface BeeListener<T extends IMultiblockLogicAlveary> extends IAlvearyComponent<T> {
IBeeListener getBeeListener();
}

/**
* Implemented by alveary parts to apply a beeModifier to the completed structure.
*/
interface BeeModifier extends IAlvearyComponent {
interface BeeModifier<T extends IMultiblockLogicAlveary> extends IAlvearyComponent<T> {
IBeeModifier getBeeModifier();
}

/**
* Implemented by alveary parts to apply a climate change to the completed structure.
*/
interface Climatiser extends IAlvearyComponent {
interface Climatiser<T extends IMultiblockLogicAlveary> extends IAlvearyComponent<T> {
/**
* Called every tick by the alveary.
*
Expand All @@ -51,7 +51,7 @@ interface Climatiser extends IAlvearyComponent {
/**
* Implemented by alveary parts to receive ticks from the completed structure.
*/
interface Active extends IAlvearyComponent {
interface Active<T extends IMultiblockLogicAlveary> extends IAlvearyComponent<T> {
void updateServer(int tickCount);

void updateClient(int tickCount);
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/forestry/apiculture/multiblock/TileAlveary.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;

Expand Down Expand Up @@ -55,12 +56,19 @@
import forestry.core.owner.IOwnerHandler;
import forestry.core.tiles.ITitled;

public class TileAlveary extends MultiblockTileEntityForestry<MultiblockLogicAlveary> implements IBeeHousing, IAlvearyComponent, IOwnedTile, IStreamableGui, ITitled, IClimateProvider {
private final String unlocalizedTitle;
public class TileAlveary extends MultiblockTileEntityForestry<MultiblockLogicAlveary> implements IBeeHousing, IAlvearyComponent<MultiblockLogicAlveary>, IOwnedTile, IStreamableGui, ITitled, IClimateProvider {
private final String translationKey;

// For Forestry only
public TileAlveary(BlockAlvearyType type, BlockPos pos, BlockState state) {
super(type.getTileType().tileType(), pos, state, new MultiblockLogicAlveary());
this.unlocalizedTitle = ApicultureBlocks.ALVEARY.get(type).getTranslationKey();
this(type.getTileType().tileType(), ApicultureBlocks.ALVEARY.get(type).getTranslationKey(), pos, state);
}

// For addons
public TileAlveary(BlockEntityType<?> type, String translationKey, BlockPos pos, BlockState state) {
super(type, pos, state, new MultiblockLogicAlveary());

this.translationKey = translationKey;
}

@Override
Expand Down Expand Up @@ -168,7 +176,7 @@ public IInventoryAdapter getInternalInventory() {

@Override
public Component getTitle() {
return Component.translatable(this.unlocalizedTitle);
return Component.translatable(this.translationKey);
}

/* IStreamableGui */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import forestry.energy.ForestryEnergyStorage;

// Used by Heater and Fan, which increase and decrease Temperature, respectively
public abstract class TileAlvearyClimatiser extends TileAlveary implements IActivatable, IAlvearyComponent.Climatiser {
public abstract class TileAlvearyClimatiser extends TileAlveary implements IActivatable, IAlvearyComponent.Climatiser<MultiblockLogicAlveary> {
private static final int TICKS_PER_CYCLE = 1;
private static final int FE_PER_OPERATION = 50;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.utils.RecipeUtils;

public class TileAlvearyHygroregulator extends TileAlveary implements Container, ILiquidTankTile, IAlvearyComponent.Climatiser {
public class TileAlvearyHygroregulator extends TileAlveary implements Container, ILiquidTankTile, IAlvearyComponent.Climatiser<MultiblockLogicAlveary> {
private final TankManager tankManager;
private final FilteredTank liquidTank;
private final IInventoryAdapter inventory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.watchers.ISlotPickupWatcher;

public class TileAlvearySieve extends TileAlveary implements IAlvearyComponent.BeeListener {
public class TileAlvearySieve extends TileAlveary implements IAlvearyComponent.BeeListener<MultiblockLogicAlveary> {
private final IBeeListener beeListener;
private final InventoryAlvearySieve inventory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import forestry.api.multiblock.IAlvearyComponent;
import forestry.apiculture.blocks.BlockAlvearyType;

public class TileAlvearyStabiliser extends TileAlveary implements IAlvearyComponent.BeeModifier {
public class TileAlvearyStabiliser extends TileAlveary implements IAlvearyComponent.BeeModifier<MultiblockLogicAlveary> {
private static final IBeeModifier MODIFIER = new IBeeModifier() {
@Override
public float modifyMutationChance(IGenome genome, IGenome mate, IMutation<IBeeSpecies> mutation, float currentChance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import forestry.core.tiles.IActivatable;
import forestry.core.utils.SpeciesUtil;

public class TileAlvearySwarmer extends TileAlveary implements WorldlyContainer, IActivatable, IAlvearyComponent.Active {
public class TileAlvearySwarmer extends TileAlveary implements WorldlyContainer, IActivatable, IAlvearyComponent.Active<MultiblockLogicAlveary> {
private final InventorySwarmer inventory;
private final ArrayDeque<ItemStack> pendingSpawns = new ArrayDeque<>();

Expand Down

0 comments on commit 76a62d6

Please sign in to comment.