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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
    • No dice. Unfortunately this fix didn't work, thank you though.
    • Maybe you need a rayon mod. https://www.curseforge.com/minecraft/mc-mods/rayon
    • Not sure what's going on the logs are making even less sense than usual to me. Any help would be much appreciated.   https://paste.ee/p/KBHyP#s=0
  • Topics

×
×
  • Create New...

Important Information

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