简体   繁体   中英

Re-initializing a variable

So I'm trying to make an electric cable system in a Minecraft mod, 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 (a Minecraft modelling program where you build your model piece by piece) 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 entire 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();
    }
}

Create a setter.

public void setModelCable(ModelCable other) {
    this.modelCable = other;
}

It looks like in your case you may just want to expose

public void setPartXVisibility(boolean visible) {
    this.modelCable.setPartXVisibility(visible);
}

At which point my Minecraft knowledge stops - you will likely need to notify the UI of this change, or something MVC-like, as part of your setter.

I'm not sure on this one, but if you remove the 'final' modifier, it might work.

Also, how do you change / access the variable to set the parts to true/false?

EDIT: I think you need to make your modelCable variable public & non-final. Then you can access it from anywhere. (And you can change it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM