Jump to content

[1.6.1] onBlockActivated doesn't work anymore!


KeeganDeathman

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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Im pretty sure it changed to:

 

public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)

If you really want help, give that modder a thank you.

 

Modders LOVE thank yous.

Link to comment
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.

 

Override goes outside the function, dimwit.

 

@Override

public void blah(parameters){

  blahblah

}

 

If it throws errors, then your function isn't overriding anything.  Functions aren't magic.

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.

Link to comment
Share on other sites

Just made a mental note to not help you in the future with issues, if this is how you're acting. I can tell you right now that both Draco18s and diesieben07 are infinitely better than you (and me) at modding, and probably Java in general. They're not the kind of people you want to be on the wrong side of if you need help in the future.

 

You can't deny you were using the override function wrongly in this post. Even right after I said:

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
        }

 

You put it in the wrong place in the next post:

 

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

and I mean that thier cant be say

 

public void blah(parameters){

@override //See how it's in the wrong place?

blahblah

}

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

 

Then when people tried to correct you you turned hostile and yeah, you know the rest.

width=463 height=200

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

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

i was saying that does not work read the post next time.

 

1) "Does not work" does not help anyone solve the problem

2) @Override throwing an error means that you, as the programmer, have done something wrong

3) I have lost all sympathy for you and will no longer reply to any post you make on any topic for any reason

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.

Link to comment
Share on other sites

You had sympathy for me? Wierd. Any way, i didn't mean to be rude, it's just, he was confusing, and I did figure something out, i was missing parms.

 

Like to point out some stuff,

A. Im awesome okay

B. When i put an annotation in a method, I WAS SHOWING IT DIDN'T WORK, IT WAS AN EXAMPLE OF WHAT NOT TO DO. (caps cause ive said this 3 TIMES!)

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

Link to comment
Share on other sites

*Breaks the ignore rule*

 

B. When i put an annotation in a method, I WAS SHOWING IT DIDN'T WORK, IT WAS AN EXAMPLE OF WHAT NOT TO DO. (caps cause ive said this 3 TIMES!)

 

Actually, that was the annotation DOING ITS GAWD DANG JOB!  It was alerting you to the fact that something about your function was different than the function in the base class.  As several people have said more than once.

 

Which is why I've blocked you.

 

Good day, sir.

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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