Poseidon5001 Posted May 19, 2017 Share Posted May 19, 2017 (edited) 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 May 20, 2017 by Poseidon5001 changed title Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted May 19, 2017 Share Posted May 19, 2017 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. Quote Link to comment Share on other sites More sharing options...
Poseidon5001 Posted May 20, 2017 Author Share Posted May 20, 2017 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 Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted May 20, 2017 Share Posted May 20, 2017 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? Quote Link to comment Share on other sites More sharing options...
Poseidon5001 Posted May 20, 2017 Author Share Posted May 20, 2017 (edited) 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 May 20, 2017 by Poseidon5001 Quote Link to comment Share on other sites More sharing options...
Poseidon5001 Posted May 20, 2017 Author Share Posted May 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
SuperJedi224 Posted May 20, 2017 Share Posted May 20, 2017 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? Quote Link to comment Share on other sites More sharing options...
Poseidon5001 Posted May 20, 2017 Author Share Posted May 20, 2017 (edited) 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 May 20, 2017 by Poseidon5001 clarification Quote Link to comment Share on other sites More sharing options...
Poseidon5001 Posted May 20, 2017 Author Share Posted May 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
SuperJedi224 Posted May 20, 2017 Share Posted May 20, 2017 I'm glad you figured it out, I've never really messed with those parts of the API before. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.