Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted
package com.daposeidonguy.testmod.blocks;

import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class PencilBlock extends BaseBlock {

	
	private static final AxisAlignedBB BOUND_BOX = new AxisAlignedBB(0, 0, 0, 16*.0625, .0625, 16*.0625);
	
	public PencilBlock() {
		super(Material.CARPET, "tilePencil");
		this.setCreativeTab(null);
		this.setBlockUnbreakable();
		this.setHardness(100f);
        this.setResistance(1f);
	}
	
	
    @Override
	public int quantityDropped(Random random) {
    	return 0;
    }
    
    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
    	return BOUND_BOX;
    }
    
    @Override
    public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
    		List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
    	super.addCollisionBoxToList(pos, entityBox, collidingBoxes, BOUND_BOX);
    }
    
	
	@Override
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
    {
        return true;
    }
	
	@Override
	public boolean isOpaqueCube(IBlockState state) {
		return false;
	}
	
	@Override
    public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
		this.requiresUpdates();
	}
	
	@Override
	public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
		this.requiresUpdates();
	}
	
	@Override
	public boolean requiresUpdates() {
		System.out.println("change");
		Minecraft.getMinecraft().thePlayer.sendChatMessage("change");
		return true;
	}
	
	@Override
	public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
		this.requiresUpdates();
	}
	
	@Override
	public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
		this.requiresUpdates();
	}
	

}

I have been attempting to get my block to register changes to blocks nearby.
Right now, as the code shows, I'm in a state of desperate debugging.
Neither updateTick, neighbourchanged or onneighbourchanged are triggering requiresUpdates.
 However, onBlockClicked is.
Any ideas?
Help is greatly appreciated.
Thanks in advance,

Edited by Poseidon5001
changed title

32 minutes ago, Poseidon5001 said:

updateTick

will not fire for the block if it is not set to tick randomly. (Block::setTickRandomly(boolean))

32 minutes ago, Poseidon5001 said:

neighborChanged

should work just fine for block updates nearby. However as you have not specified the game version you are modding for I will assume it is 1.11.x and if it indeed is 1.11.x then your signature is incorrect. It is 

neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)

and yours is 

neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)

While you do have an override annotation and the compiler would tell you that there is nothing to override normally you are extending BaseBlock which is your imlementation you have not posted code for, and that can contain that method without an override annotation.

 

As far as I am able to tell Block::onNeighborChange only has something to do with comparator logic and not block updates.

Oh, and also not relevant to your issue but I fail to see what is the purpose of

32 minutes ago, Poseidon5001 said:

this.setBlockUnbreakable();

If you are setting the hardness literally 1 line below.

  • Author
20 minutes ago, V0idWa1k3r said:

will not fire for the block if it is not set to tick randomly. (Block::setTickRandomly(boolean))

should work just fine for block updates nearby. However as you have not specified the game version you are modding for I will assume it is 1.11.x and if it indeed is 1.11.x then your signature is incorrect. It is 


neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)

and yours is 


neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)

While you do have an override annotation and the compiler would tell you that there is nothing to override normally you are extending BaseBlock which is your imlementation you have not posted code for, and that can contain that method without an override annotation.

 

As far as I am able to tell Block::onNeighborChange only has something to do with comparator logic and not block updates.

Oh, and also not relevant to your issue but I fail to see what is the purpose of

If you are setting the hardness literally 1 line below.

My code is kind of a clusterf*** right now. I'll clean it up a bit and make a github repo for it so all my code is readily available.
Version is 1.10.2, sorry I forgot to mention it.
Here's the github link:

https://github.com/daPoseidonGuy/PencilMod

I do not see any obvious issues with it(although I have never worked with 1.10.x so I might be missing something) apart from calling Minecraft from common code. How do you know it is not working? What happens if you place a breakpoint inside the neighborChanged method?

  • Author
9 minutes ago, V0idWa1k3r said:

I do not see any obvious issues with it(although I have never worked with 1.10.x so I might be missing something) apart from calling Minecraft from common code. How do you know it is not working? What happens if you place a breakpoint inside the neighborChanged method?

in onNeighborChange and neighborChanged i call doUpdate().
Destroying blocks around the PencilBlock or causing a block update via other means doesn't result in the display of the message, whilst a click does, so I know doUpdate() itself works. I will try adding a breakpoint now.


EDIT: Adding a breakpoint didn't seem to do anything. Also calling Minecraft is only temporary (for debugging)

Edited by Poseidon5001

  • Author

New update: I realized that upon logging out, my block disappears from the world. This probably has to do with the way my itemPencil places it.
When giving myself the BlockItem via /give and placing it down, it recieves block updates.
So this has something to do with using world.setBlockState() to place my block i guess.

4 minutes ago, Poseidon5001 said:

New update: I realized that upon logging out, my block disappears from the world.

Did you remember to register it?

  • Author
12 minutes ago, SuperJedi224 said:

Did you remember to register it?

Yes, when placed normally, the block stays. Only when placed via the itemPencil Item does it disappear on logout.
Something in the way itemPencil creates the block makes it disappear on logout and impervious to any block updates.
Edit: Updated github:
https://github.com/daPoseidonGuy/PencilMod

Edited by Poseidon5001
clarification

  • Author

Fixed it now. I was using EnumActionResult.SUCCESS instead of EnumActionResult.PASS.

I also added the swingingArm animation since EnumActionResult.PASS wouldn't add it.
I'm guessing EnumActionResult.PASS passes it on to the vanilla code to register stuff serverside instead of just clientside.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.