Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.6.1] onBlockActivated doesn't work anymore!


Recommended Posts

Hi again!

I have some blocks with custom tile entities rendering some models, but they both have onBlockActivated booleans, but when I right click absolutely nothing happens! and I know that on one of them I have it coded right cause it worked before i implemented the TileEnity!

Help?

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to post
Share on other sites

okay, if your wondering why I have a modloader function its because I cant get the forge one to work for me, mainly cause i cant understand it.

BlockTowerFloorBase:

package codelyoko;

import net.minecraft.block.*;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.src.ModLoader;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockTowerFloorBase extends BlockContainer
implements ITileEntityProvider
{

public BlockTowerFloorBase(int id, Material par1Material)
{

	super(id, par1Material);
	this.setCreativeTab(Lyoko.tabLyoko);

}
@Override
public TileEntity createNewTileEntity(World world)
{
    return new TileEntityTowerFloor(); //Rename to your tile entity 
}

@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
{
    TileEntity tile = world.getBlockTileEntity(x, y, z);  // Once again rename to your tile entity.
    if (tile instanceof TileEntityTowerFloor  && ((TileEntityTowerFloor)tile).shouldRender) {
        return AxisAlignedBB.getBoundingBox(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1);
    }
    return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
{
	par1World.setBlock(par2+1, par3, par4, Lyoko.TowerFloorGagBlock.blockID, 0, 2);
	par1World.setBlock(par2+1, par3, par4+1, Lyoko.TowerFloorGagBlock.blockID, 0, 2);
	par1World.setBlock(par2+1, par3, par4-1, Lyoko.TowerFloorGagBlock.blockID, 0, 2);
	par1World.setBlock(par2, par3, par4+1, Lyoko.TowerFloorGagBlock.blockID, 0, 2);
	par1World.setBlock(par2, par3, par4-1, Lyoko.TowerFloorGagBlock.blockID, 0, 2);
	par1World.setBlock(par2-1, par3, par4+1, Lyoko.TowerFloorGagBlock.blockID, 0, 2);
	par1World.setBlock(par2-1, par3, par4, Lyoko.TowerFloorGagBlock.blockID, 0, 2);
	par1World.setBlock(par2-1, par3, par4-1, Lyoko.TowerFloorGagBlock.blockID, 0, 2); 
	ModLoader.openGUI(par5EntityPlayer, new GUITowerFloorCreated());
	System.out.print("complete");
	return true;
}

//This will tell minecraft not to render any side of our cube.
public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
	return false;
}

//And this tell it that you can see through this block, and neighbor blocks should be rendered.
public boolean isOpaqueCube()
{
	return false;
}


}

 

BlockTowerConsole:

package codelyoko;

import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.src.ModLoader;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockTowerConsole extends Block
implements ITileEntityProvider{

public BlockTowerConsole(int par1, Material par2Material) {
	super(par1, par2Material);
	this.setCreativeTab(Lyoko.tabLyoko);
}

@Override
public TileEntity createNewTileEntity(World world) {
	return new TileEntityTowerConsoleBlock();
}

public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
	return false;
}

//And this tell it that you can see through this block, and neighbor blocks should be rendered.
public boolean isOpaqueCube()
{
	return false;
}

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5player){
	ModLoader.openGUI(par5player, new GuiTowerConsole());
	return true;
}
}

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to post
Share on other sites

The modloader command will be what's screwing it up. Try adding a print line at the start of the method too, saying "begin". Also try temporarily commenting out or removing the modloader code

 

The Forge version of the openGUI is:

 

 

                player.openGui([your mod ID].instance, 0, world, x, y, z);

 

The 0 is the ID of the GUI, and you need a GUI handler too. This one is just copied straight out of my mod, so you'll have to modify it to suit you:

 

package co.uk.silvania.city;

import co.uk.silvania.city.tileentities.ContainerATM;
import co.uk.silvania.city.tileentities.GuiATM;
import co.uk.silvania.city.tileentities.TileEntityATMEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {


	public GuiHandler() {
	}
        @Override
        public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
        	switch(id) {
        	case 0: {
                TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
                if(tileEntity instanceof TileEntityATMEntity) {
                        return new ContainerATM(player.inventory, (TileEntityATMEntity) tileEntity);
                }	
        	}
        }
		return null;	
    }

        @Override
        public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
        	switch(id) {
        	case 0: {
                TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
                if(tileEntity instanceof TileEntityATMEntity) {
                        return new GuiATM(player.inventory, (TileEntityATMEntity) tileEntity, world, x, y, z);
                }	
        	}
        }
		return null;
    }
}

 

And finally in the main class, again copied from the mod I have open at the time:

    @Instance("FlenixCities")
    public static GuiHandler roadsGuiHandler = new GuiHandler();

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    	NetworkRegistry.instance().registerGuiHandler(this, roadsGuiHandler);
    }

 

 

You may need some networking code too, I can't help with that.

 

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to post
Share on other sites

I don't remember how often this has been said. Whenever you (intend to) override a method (if you don't know what this is learn java first) mark it with @Override! If that gives you an error removing the annotation will NOT resolve anything. It just means that you are not overriding ANYTHING, even though you want to.

The method signature (again, learn java if you don't know what this is) has changed for onBlockActivated from 1.5 => 1.6.

Link to post
Share on other sites

::), not sure if @Override can be ran inside a method but,

any way, I tried to use a System.print.out("Begin") at the begining f the method and nothing showed up still, and I tried to @Override, and it threw an error.

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to post
Share on other sites

::), not sure if @Override can be ran inside a method but,

any way, I tried to use a System.print.out("Begin") at the begining f the method and nothing showed up still, and I tried to @Override, and it threw an error.

 

I don't know what you mean by "inside a method" - Your override should be like this:

        @Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
{
	blah
        }

 

I never noticed it wasn't there before :P

 

In relation to containers; you need to have one. BlockContainer is what you need to use for rendering models.

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to post
Share on other sites

Okay, is i okay to have a "blank" container?

and I mean that thier cant be say public void blah(parameters){

@override

blahblah

}

so yeah, and I tried putting an override on onBlockAtivated, and it said no.

 

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to post
Share on other sites

Sorry to say but this makes me angry like f***.

You added the @Override and it spits out an error. I talked about that EXACT situation and how to fix it. What you did is exactly what will NOT fix it (you removed the annotation again).

You can't expect to make a proper mod without the slightest of efforts to learn java. This is absolute basic java knowledge.

Link to post
Share on other sites

Okay, well get this, the @Override annotation you told me to put in, eclipse tole me to either remove it, or edit a base file!

So you need to check your stuff, cause you're being the dumbest modder ever if you think the answer is to edit a base file.

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to post
Share on other sites

YOU are the dumbest modder if you don't know such simple things about java. Eclipse is a very good IDE, but it can't help you if you don't know a f*** about java.

Eclipse suggest changing the base file to "fix" the discrepancy between your method signature and the signature in your parent class. If you can't edit the parent class (which you shouldn't) guess what you need to change.

Dude, go learn java before you start modding.

Link to post
Share on other sites

Figured this should be cleaned up just in case someone needs the info  ;)

 

KeeganDeathman was using:

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5player)

 

While this use to work the parameters have changed in 1.6 and is now viewed as a new method in KeeganDeathman's code, one which Minecraft never calls.

 

As diesieben07 pointed out, every time you override an existing method mark it with @Override .

With an @Override Elicpse will inform you the old method doesn't exist, this is a big hint to you to find the replacement and fix your code.

 

in this case onBlockActivated changed from

onBlockActivated(World, int, int, int, EntityPlayer)

to

onBlockActivated(World, int, int, int, EntityPlayer, int, float, float, float)

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.