Jump to content

[1.15.2] Tile Entity not ticking (resolved)


TheOnly8Z

Recommended Posts

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);
    }
}

 

Edited by TheOnly8Z
resolved
Link to comment
Share on other sites

25 minutes ago, Alpvax said:

Have you checked that your TileEntity is actually being registered and created?

I have these lines regarding the TileEntity in other classes:

// In a registry class
private static final DeferredRegister<TileEntityType<?>> TILES = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, MOD_ID);
public static final RegistryObject<TileEntityType<BaitStationTile>> BAIT_STATION_BLOCK_TILE = TILES.register("bait_station", () -> TileEntityType.Builder.create(BaitStationTile::new, BAIT_STATION_BLOCK.get()).build(null));

// In the block class
@Override
public boolean hasTileEntity(BlockState state) {
  return true;
}
@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
  return new BaitStationTile();
}

 

EDIT: I noticed that the item I place in the container isn't saved - when I quit and rejoin the item disappears. 

Edited by TheOnly8Z
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.