Hello all, I'm trying to make a block that implements ITickableTileEntity and does something every minute, but tick() doesn't seem to be running at all.
I'm following McJty's tutorial series (for 1.14). The forge documentation mentions using net.minecraft.util.ITickable, but the IDE highlighting seems to suggest this doesn't exist.
// snip imports
public class BaitStationTile extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
private LazyOptional<IItemHandler> handler = LazyOptional.of(this::createHandler);
private int counter;
public BaitStationTile() {
super(BAIT_STATION_BLOCK_TILE.get());
}
@Override
public void tick() {
// this line is not running
LogManager.getLogger().debug("ticking Bait Station, remote: " + world.isRemote + "handler: " + handler.toString());
if (world.isRemote) {
return;
}
handler.ifPresent(h -> {
ItemStack stack = h.getStackInSlot(0);
// snip functionality
});
}
private IItemHandler createHandler() {
return new ItemStackHandler(1) {
@Override
protected void onContentsChanged(int slot) {
markDirty();
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return BaitStation.baitEntities.exists(stack.getItem());
}
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
// TODO fancy logic or something
if (!BaitStation.baitEntities.exists(stack.getItem())) {
return stack;
}
return super.insertItem(slot, stack, simulate);
}
};
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return handler.cast();
}
return super.getCapability(cap, side);
}
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent(getType().getRegistryName().getPath());
}
@Nullable
@Override
public Container createMenu(int i, PlayerInventory playerInventory, PlayerEntity playerEntity) {
return new BaitStationContainer(i, world, pos, playerInventory, playerEntity);
}
}