Jump to content

{SOLVED}[1.10.2]Updating Blockstate on neighbor Change problem


Bitterholz

Recommended Posts

This is a Network of 2 Pipes just been placed. They connect up perfectly.

JfFQLa2.png

 

Now when I add in another Pipe:

Kxwyb2W.png

Watch how the New Pipe sets its connection accordingly, while the 2 older ones remain unchanged.

 

Now if i add ANOTHER one like this:

CyYCEye.png

See how it Updates the Oldest Pipe but does not form a connection to the newest one.

 

Link to comment
Share on other sites

What do you have right now? You might be able to use Block#onNeighborChanged (I might be wrong about the name, I don't have Eclipse on this computer...) or something like that in your block class. Then check

if (worldIn.getBlockState(pos).getBlock == ModBlocks.PIPE_THINGY)

and if the neighbor block is a PIPE_THINGY (replace this with your pipe's name ;)), then do Block#scheduleUpdate (again, it's something like this, but I don't have access to Eclipse right now...). This seems like an interesting thing to work on, so good luck!

 

Also, side question, do you have working ItemBlock models for your pipes? I have been fighting with this for a few months now.... :)

 

Trying with

@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
	this.requiresUpdates();
}

right now. lets hope thats a success.

 

Also if you mean "Item renders its OBJ model in the hand/UI, then Yes, my Pipe does render its model in hand.

Link to comment
Share on other sites

Sadly no change with requiresUpdate(); :/

 

Pipe Block Code:

 

public class PipeBasic extends BlockGenericPipe implements ITileEntityProvider{

public PipeBasic() {
	super(Material.IRON);
	setUnlocalizedName(References.NAME_PIPE_BASIC);
	setRegistryName(References.RN_PIPE_BASIC);
	setCreativeTab(CreativeTabs.TRANSPORTATION);

}

@Override
@SideOnly(Side.CLIENT)
public void initModel() {
	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));

}

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
	if(world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TileBasicPipe) {
		TileBasicPipe te = (TileBasicPipe)world.getTileEntity(pos);
		te.checkConnections(world, pos);
		return ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, te.state);
	}
	return state;
}

@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
	TileBasicPipe te = (TileBasicPipe)world.getTileEntity(pos);
	te.checkConnections(world, pos);
	this.requiresUpdates();
}



@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) {return false;}

@Override
public boolean isBlockNormalCube(IBlockState state) {return false;}

@Override
public boolean isOpaqueCube(IBlockState state) {return false;}

@Override
    public boolean isVisuallyOpaque() { return false; }

@Override
public int getMetaFromState(IBlockState state) {return 0;}

@Override
public boolean hasTileEntity() {return true;}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new TileBasicPipe();
}

@Override
public BlockStateContainer createBlockState() {
	return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] {Properties.AnimationProperty});
}

}

 

 

Tile Code

 

public class TileBasicPipe extends TileEntity{

private final List<String> hidden = new ArrayList<String>();
public final IModelState state = new IModelState()
{
	private final Optional<TRSRTransformation> value = Optional.of(TRSRTransformation.identity());

	@Override
	public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
        {
            if(part.isPresent())
            {
                // This whole thing is subject to change, but should do for now.
                UnmodifiableIterator<String> parts = Models.getParts(part.get());
                if(parts.hasNext())
                {
                    String name = parts.next();
                    // only interested in the root level
                    if(!parts.hasNext() && hidden.contains(name))
                    {
                        return value;
                    }
                }
            }
            return Optional.absent();
        }

};


@Override
public NBTTagCompound getUpdateTag() {return writeToNBT(new NBTTagCompound());}

@Override
public SPacketUpdateTileEntity getUpdatePacket() {
	NBTTagCompound nbtTag = new NBTTagCompound();
	this.writeToNBT(nbtTag);
	return new SPacketUpdateTileEntity(getPos(), 1, nbtTag);
}

@Override
    public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
        this.readFromNBT(packet.getNbtCompound());
    }

@Override
    public void readFromNBT(NBTTagCompound compound) {super.readFromNBT(compound);}

@Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound);
        
        return compound;
    }

public boolean canConnect(IBlockAccess world, BlockPos pos) {
	TileEntity te = world.getTileEntity(pos);
	return (te instanceof TileBasicPipe);
}

public void checkConnections(IBlockAccess world, BlockPos pos) {
	hidden.add("CUP");
	hidden.add("CDOWN");
	hidden.add("CNORTH");
	hidden.add("CSOUTH");
	hidden.add("CEAST");
	hidden.add("CWEST");
	hidden.add("GUP");
	hidden.add("GDOWN");
	hidden.add("GNORTH");
	hidden.add("GWEST");
	hidden.add("GSOUTH");
	hidden.add("GEAST");
	hidden.add("GCENTER");


	//North Connection
	if(canConnect(world, pos.north())) {
		//if(hidden.contains("UP"))
			hidden.remove(Connections.NORTH.toString());
	}
	else {hidden.add(Connections.NORTH.toString());}

	//South Connection
	if(canConnect(world, pos.south())) {
		//if(hidden.contains("DOWN"))
			hidden.remove(Connections.SOUTH.toString());
	}
	else{hidden.add(Connections.SOUTH.toString());}

	//East Connection
	if(canConnect(world, pos.east())) {
		//if(hidden.contains("EAST"))
			hidden.remove(Connections.EAST.toString());
	}
	else{hidden.add(Connections.EAST.toString());}

	//West Connection
	if(canConnect(world, pos.west())) {
		//if(hidden.contains("WEST"))
			hidden.remove(Connections.WEST.toString());
	}
	else{hidden.add(Connections.WEST.toString());}

	//Up Connection
	if(canConnect(world, pos.up())) {
		//if(hidden.contains("SOUTH"))
			hidden.remove(Connections.UP.toString());
	}
	else{hidden.add(Connections.UP.toString());}

	//Down Connection
	if(canConnect(world, pos.down())) {
		//if(hidden.contains("NORTH"))
			hidden.remove(Connections.DOWN.toString());
	}
	else{hidden.add(Connections.DOWN.toString());}

	this.markDirty();
}	
}

 

 

Link to comment
Share on other sites

I don't know why you're calling requiresUpdates(). It doesn't do anything:

 

    public boolean requiresUpdates()
    {
        return true;
    }

 

You need to call these, from your TE, so that the TE data is synced back to the client and the block is re-rendered:

		worldObj.markBlockRangeForRenderUpdate(pos, pos);
	worldObj.notifyBlockUpdate(pos, getState(), getState(), 3);
	worldObj.scheduleBlockUpdate(pos,this.getBlockType(),0,0);
	markDirty();

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

@Draco18s

Does the Tile have to be ITickable for that?

 

No.

 

Also what do you refer to with
getState()

?

 

getState just does this:

 

	private IBlockState getState() {
	return worldObj.getBlockState(pos);
}

 

I did it as sort of a replacement for 1.7's getMetadata() method.  You don't really need it as long as you in-line its functionality.

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

I see...

 

Well, now im doing

if(worldObj.isRemote) {
		this.worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
		this.worldObj.notifyBlockUpdate(pos, getState(), getState(), 3);
		this.worldObj.scheduleBlockUpdate(this.pos, this.getBlockType(), 0, 0);

		markDirty();
	}

At the end of checkConnections()

 

The Pipes do Update their State, but it does by no means happen immediately as i place a neighboring Pipe.

rather just happens slowly over time.

Link to comment
Share on other sites

Did I tell you to wrap it in an if(worldObj.isRemote) check?

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

I'm not sure then. My own TE-valued-states work just fine.

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

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Considering the financial revolution sparked by cryptocurrencies like Bitcoin, the digital era has opened up a plethora of opportunities. But this exciting new world also comes with a terrible reality: in the harsh, brutal blockchain environment, there's always a danger you could lose your precious digital assets. Services like ADWARE RECOVERY SPECIALIST are not merely recovery agents in this case; they are crypto lifelines, and my own experience attests to their vital importance. I had an amazing time exploring the world of Bitcoin on my own; it was exciting to be in a completely new place and to see the possibility of independent money. However, a careless mistake of choosing the incorrect platform for my investment sent me into total despair. It seemed as though my digital lifeblood, Bitcoin, had been devoured by the blockchain's vicious maw. Overwhelmed with hope, I began a frantic quest for solutions, looking up any clue of assistance on the internet. I discovered  ADWARE RECOVERY SPECIALIST at that point.  Initially, I was filled with misgivings, but their unwavering professionalism and clear communication offered me a glimpse of hope. I set them the very impossible task of locating my missing fortune. The ADWARE RECOVERY SPECIALIST team of professionals meticulously penetrated the labyrinthine depths of the blockchain with the aid of cutting-edge technology and years of honed experience, treating my case with the utmost care and respect and keeping me informed at every turn. I had never encountered anything like the recuperation process. The days of confusing technical jargon and excruciatingly long wait times were over. And then the miraculous happened. My Bitcoin miraculously reappeared in my wallet, coming safe and sound from the digital void in an almost amazing length of time. Integrating  ADWARE RECOVERY SPECIALIST into your Bitcoin recovery process is not as magical as waving a wand, but it sure feels like it with the seamless and effective tools it offers. By following best practices, training your staff, and learning from successful case studies, you can optimize your Bitcoin recovery efforts and stay ahead of potential risks. The future outlook for Bitcoin recovery with ADWARE RECOVERY SPECIALIST looks promising, providing users with the confidence and tools they need to navigate the ever-evolving landscape of digital assets. It was a very happy moment that showcased the ADWARE RECOVERY SPECIALIST team's remarkable talent and dedication. However, my experience serves more purposes than just self-interest; it serves as a sobering reminder of the expanding demand for dependable and trustworthy bitcoin recovery services, such as ADWARE online recovery.
    • Quick-Books is great with regards to coordinating your monetary data. You can decide to live talk with a specialist at Quick-Books to get the answer for your questions. You will actually want to get to the talk going to the landing page and call us +1855-210-1428.
    • Update: I managed to make the item not disappear after crafting, but it doesn't remove any durability. import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.UnbreakingEnchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class NuggetHammer extends Item { private boolean damage; public NuggetHammer(Properties p_i48487_1_) { super(p_i48487_1_); } @Override public int getMaxDamage(ItemStack stack) { return 54 - 1; } public boolean isBarVisible(ItemStack stack) { return false; } @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack copy = stack.copy(); copy.setCount(1); if (!this.damage) return copy; int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, stack); for (int i = 0; i < unbreaking; i++) { if (UnbreakingEnchantment.shouldIgnoreDurabilityDrop(stack, unbreaking, random)) return copy; } copy.setDamageValue(stack.getDamageValue() + 1); if (copy.getDamageValue() > stack.getMaxDamage()) return ItemStack.EMPTY; return copy; } }  
  • Topics

×
×
  • Create New...

Important Information

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