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.

Announcements



×
×
  • Create New...

Important Information

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