Jump to content

[1.10] Tile Entity won't tick


Son_Of_Diablo

Recommended Posts

Hello (I'm new on the modding scene and I'm just trying to figure out how the basics work).

 

I'm trying to get a Tile Entity to tick.

 

I implement

ITickable

and create the update method.

 

But it doesn't seem to be able to run the code I put in the update method :(

 

 

Am I missing something?

 

 

 

I'm trying to make a block that generates Cobble stone, right now I just want it to print some text (To see that it works)

 

 

My code:

 

ItemModelProvider:

package net.shadowfacts.tutorial.Item;

/**
* Created by Son_Of_Diablo on 11-01-2017.
*/
import net.minecraft.item.Item;

public interface ItemModelProvider {

    void registerItemModel(Item item);

}

 

BlockBase:

package net.shadowfacts.tutorial.Block;

/**
* Created by Son_Of_Diablo on 11-01-2017.
*/
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.shadowfacts.tutorial.Item.ItemModelProvider;
import net.shadowfacts.tutorial.TutorialMod;

public class BlockBase extends Block implements ItemModelProvider{

    protected String name;

    public BlockBase(Material material, String name) {
        super(material);

        this.name = name;

        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(TutorialMod.creativeTab);
    }

    @Override
    public void registerItemModel(Item item) {
        TutorialMod.proxy.registerItemRenderer(item, 0, name);
    }

}

 

BlockTileEntity:

package net.shadowfacts.tutorial.Block;

/**
* Created by Son_Of_Diablo on 15-01-2017.
*/
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import javax.annotation.Nullable;

public abstract class BlockTileEntity<TE extends TileEntity> extends BlockBase {

    public World world;

    public BlockTileEntity(Material material, String name) {
        super(material, name);
    }

    public abstract Class<TE> getTileEntityClass();

    public TE getTileEntity(IBlockAccess world, BlockPos pos) {
        return (TE)world.getTileEntity(pos);
    }

    boolean placed = false;
    @Override
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
        world = worldIn;
        if(!placed){
        System.out.println("I like cake!");}
        return super.onBlockPlaced(worldIn,pos,facing,hitX,hitY,hitZ,meta,placer);
    }

    @Override
    public boolean hasTileEntity(IBlockState state) {
        return true;
    }

    @Nullable
    @Override
    public abstract TE createTileEntity(World world, IBlockState state);

    ;

}

 

BlockCobbleGen:

package net.shadowfacts.tutorial.Block.cobblegen;

/**
* Created by Son_Of_Diablo on 15-01-2017.
*/

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.shadowfacts.tutorial.Block.BlockTileEntity;
import org.lwjgl.Sys;

import javax.annotation.Nullable;
import java.util.Random;

public class BlockCobbleGen extends BlockTileEntity<TileEntityCobbleGen> implements ITickable {

    public BlockCobbleGen() {
        super(Material.ROCK, "cobblegen");
    }

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {

        return true;
    }

    @Override
    public Class<TileEntityCobbleGen> getTileEntityClass() {
        return TileEntityCobbleGen.class;
    }

    @Nullable
    @Override
    public TileEntityCobbleGen createTileEntity(World world, IBlockState state) {
        return new TileEntityCobbleGen();
    }

    @Override
    public void update() {
        System.out.println("Yo!");
    }
}

 

TileEntityCobbleGen:

package net.shadowfacts.tutorial.Block.cobblegen;

/**
* Created by Son_Of_Diablo on 15-01-2017.
*/
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityCobbleGen extends TileEntity {

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        //compound.setInteger("count", count);
        return super.writeToNBT(compound);
    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        //count = compound.getInteger("count");
        super.readFromNBT(compound);
    }

}

Link to comment
Share on other sites

package net.shadowfacts.tutorial.Item
Please don't use other people's package names. It defeats the purpose of packages.

 

public abstract class BlockTileEntity<TE extends TileEntity> extends BlockBase {

 

    public World world;

This is a terrible idea. The Block instance handles all instances of your block, it is more of a block type. Hence storing a world here makes no sense, your Block (almost) always exists in at least two worlds at the same time: the client world and the server world.

 

boolean placed = false;
Same thing, see above. This field will be shared across all instances of your Block.

Yea I figured that out, I'm changing that right now :)

I was trying to save the World(s) so that I could use them later to run code on client/server only, but I have no clue as to how I would do that at this moment :/

 

public class BlockCobbleGen extends BlockTileEntity<TileEntityCobbleGen> implements ITickable {
Why did you implement
ITickable

here? Nothing will check for it on your Block class.

 

public class TileEntityCobbleGen extends TileEntity {
Where is
ITickable

?

 

ohh.. so I placed it in the wrong class? That would explain why it doesn't work ^^

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.



×
×
  • Create New...

Important Information

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