Jump to content

Editing a custom rendered block instance live?


Roboguy99

Recommended Posts

So I'm trying to make an electric cable system, which obviously requires an ability to connect/detach from other cables. Currently I am only working on the aesthetics and so want to change whether or not each part of a wire is shown.

My wire model is made in Techne and consists of 7 parts (a core and up, down, north, south, east, west). They can be toggled currently when the model is first instanced using a boolean for each direction (I don't need to toggle the core):

public RenderCable()
{
this.modelCable = new ModelCableAll(true, true, true, false, false, false);
}

 

The problem with this is that the state can only be changed by restarting the game, so how can I live update the state/edit the existing instance/remake the instance of the model?

 

Here is the full class:

package foodTech.tileEntities.render;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import foodTech.tileEntities.models.cable.ModelCableAll;

public class RenderCable extends TileEntitySpecialRenderer {

    ResourceLocation textureOff = (new ResourceLocation("roboguy99:textures/models/cableOff.png"));
    ResourceLocation textureOn = (new ResourceLocation("roboguy99:textures/models/cableOn.png"));

private final ModelCableAll modelCable;

public RenderCable()
{
	this.modelCable = new ModelCableAll(false, false, false, false, false, false);
}

public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale) 
{
	GL11.glTranslatef((float) x + 0.5F, (float) y - 0.5F, (float) z + 0.5F);
	setConnections();
	GL11.glTranslatef((float) x - 0.5F, (float) y + 0.5F, (float) z - 0.5F);
}

public void setConnections()
{
	GL11.glPushMatrix();
		Minecraft.getMinecraft().renderEngine.bindTexture(textureOff);
		this.modelCable.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
	GL11.glPopMatrix();
}
}

I have no idea what I'm doing.

Link to comment
Share on other sites

Add the following to your tileentity class

 

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
NBTTagCompound nbttagcompound = pkt.func_148857_g();
this.readFromNBT(nbttagcompound);
}

@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.blockMetadata, nbttagcompound);
}

 

this will sync to the client, mostly used for renders.

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.