Jump to content

Recommended Posts

Posted (edited)

So I'm trying to code a Cobblestone Generator, but after having some problems, I decided to clean up everything and start again from scratch with a TE.

I noticed that when placed the update() on the TE works correctly, however when I exit and reload the world, the TE wont start updating until I right click it. (Had it working earlier, not sure how I broke it)

What could the problem be?

 

import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;

public class TECobblestoneGenerator extends TileEntity implements ITickable {
	
	private int cooldown;
    private int speed;

    public TECobblestoneGenerator(int speed){
        this.speed = speed;
        this.cooldown = 0;
    }

    public int getCooldown(){
    	return this.cooldown;
    }

	@Override
	public void update() {
		if (!this.world.isRemote)
        {
    		this.cooldown++;
    		
    		System.out.println(cooldown);
    		
    		if(this.cooldown >= this.speed) {
    			this.cooldown = 0;
    		}
    		
        }
		
	}
    
}

 

On the Block class I have:

 


public class CobblestoneGenerator extends GenericModBlock implements ITileEntityProvider{

    public CobblestoneGenerator(String name) {
        super(Material.ROCK, name);
        this.setUnlocalizedName(ModInfo.MODID + ":" + name);
        this.setHardness(2.0F);
        this.setSoundType(SoundType.STONE);

        ModBlocks.BLOCKS.add(this);
        ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
    }

    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
            TileEntity te = worldIn.getTileEntity(pos);

            if (te instanceof TECobblestoneGenerator)
            {
            	TECobblestoneGenerator tileentity = (TECobblestoneGenerator) worldIn.getTileEntity(pos);
            	playerIn.sendMessage(new TextComponentString("Cooldown: " + tileentity.getCooldown()));
            }

            return true;
        }
    }
    
    @Nullable
    @Override
    public TileEntity createNewTileEntity(World worldIn, int meta) {
        return new TECobblestoneGenerator(128);
    }
    
	@Override
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

	@Override
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
	
	
	@Override
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }
}

 

And for the registry I have:

 

public class ModTE {

	public static void registerTE() {
		
		GameRegistry.registerTileEntity(TECobblestoneGenerator.class, ModInfo.MODID + ":cobblestone_generator");
		
	}
}

that gets called on the main class at preInit

 

PS: I was having other issues, like not been sure how to save the stack of generated cobbles upon closing the world. But that may come later, as I believe some of the problems were probably caused by this first issue.

Edited by American2050
Posted (edited)

You need to have a TileEntity constructor without any arguments (and calling super()), as that's used for instantiating a TileEntity when the world's getting loaded. 

 

My advice: don't use custom TileEntity constructors. Instead, use setters as it removes any confusion with constructors.

Edited by larsgerrits
  • Like 3

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted (edited)

@diesieben07 : do we have a common issue for this yet? 

Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.