public class RenderNES extends TileEntitySpecialRenderer {
public static final ResourceLocation texture = new ResourceLocation(
Strings.MODID + ":" + "textures/model/NES.png");
private ModelNES model;
public RenderNES() {
this.model = new ModelNES();
}
private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
GL11.glPushMatrix();
GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
GL11.glPopMatrix();
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y,
double z, float f) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
this.bindTexture(texture);
;
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glPushMatrix();
TileEntityNES tile = (TileEntityNES) tileentity;
int direction = tile.direction;
GL11.glRotatef(direction * 90, 0.0F, 1.0F, 0.0F);
Well Jaws78 the simplest way is to have a block right click method(have it change a variable), and to have multiple resource locations. Do an if comparison(if the variable is true change) so the texture would be bound to the right one.
As long as the block works fine as it is the only thing you should have to change to make this work is the block file.
You can either use a variable within the file or use NBTs and save that to the tile entity and then change the value with the activated function. If you do anything other than NBTs then it will reset when the game is closed, but using NBTs will require more work to accomplish if you don't know how to do it
NBT is the thing minecraft uses to save stuff... It will just stop the texture from resetting to the default when you quit the world or go far away enough from it that it unloads. So, if you create a variable in you're tileentity. You can also override some methods for writing / reading.
public class TileEntityNES extends TileEntity {
public int direction;
public ResourceLocation texture = new ResourceLocation("minecraft:textures/items/diamond.png");
@Override
public TileEntityNES(){
markDirt(); //tells minecraft that this has information that needs to be saved and accessed
}
@Override
public void writeToNBT(NBTTageCompound nbt){
super.writeToNBT(nbt) //saves coords and stuff like that.
TileEntityNES tile = (TileEntityNES) tileentity; //tileentity is just a reference.
bindTexture(tile.texture);
}
}
In your block:
public class NES extends BlockContainer {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int notused0, float notused1, float notused2, float notused3){
((TileentityAnimationEditor) world.getTileEntity(x, y, z)).texture = new ResourceLocation("minecraft:textures/items/diamond.png"); //this loops through all the tileentities.
}
EDIT: Actually having an array of resource locations and each TileEntity storing an index to that thing would probably be the best way to do it. I think that's actually a lot like what a2937 said.
Well in the onBlockActivated method did you change "minecraft:textures/items/diamond.png" to something else like 'apple.png'. Also, in writeToNBT this nbt.setString("texture",texture.getResourceDomain()+texture.getResourcePath()); should be this nbt.setString("texture",texture.getResourceDomain()+':'+texture.getResourcePath());
Rollback Post to RevisionRollBack
Animate your minecraft builds with Animated Structures: Link Removed
Im trying to change the block texture onRightClick but I can't find out how.
Block
package com.jawser.blocks.nintendo;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import com.jawser.lib.Strings;
import com.jawser.main.MainRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class NES extends BlockContainer {
public NES(Material material) {
super(material);
this.setResistance(5.0F);
this.setCreativeTab(MainRegistry.gameTab);
}
public int getRenderType() {
return -1;
}
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileEntityNES();
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon(Strings.MODID + ":" + this.getUnlocalizedName().substring(5));
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
{
if (entity == null)
{
return;
}
TileEntityNES tile = (TileEntityNES) world.getTileEntity(x, y, z);
tile.direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
}
}
Block Render
package com.jawser.blocks.nintendo;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import com.jawser.lib.Strings;
public class RenderNES extends TileEntitySpecialRenderer {
public static final ResourceLocation texture = new ResourceLocation(
Strings.MODID + ":" + "textures/model/NES.png");
private ModelNES model;
public RenderNES() {
this.model = new ModelNES();
}
private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
GL11.glPushMatrix();
GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
GL11.glPopMatrix();
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y,
double z, float f) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
this.bindTexture(texture);
;
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glPushMatrix();
TileEntityNES tile = (TileEntityNES) tileentity;
int direction = tile.direction;
GL11.glRotatef(direction * 90, 0.0F, 1.0F, 0.0F);
this.model.renderModel(0.0625F);
GL11.glPopMatrix();
GL11.glPopMatrix();
}
}
Tile Entity
package com.jawser.blocks.nintendo;
import net.minecraft.tileentity.TileEntity;
public class TileEntityNES extends TileEntity {
public int direction;
}
Well Jaws78 the simplest way is to have a block right click method(have it change a variable), and to have multiple resource locations. Do an if comparison(if the variable is true change) so the texture would be bound to the right one.
As long as the block works fine as it is the only thing you should have to change to make this work is the block file.
You can either use a variable within the file or use NBTs and save that to the tile entity and then change the value with the activated function. If you do anything other than NBTs then it will reset when the game is closed, but using NBTs will require more work to accomplish if you don't know how to do it
sorry, im new to java so I dont know what NBT is
NBT is the thing minecraft uses to save stuff... It will just stop the texture from resetting to the default when you quit the world or go far away enough from it that it unloads. So, if you create a variable in you're tileentity. You can also override some methods for writing / reading.
public class TileEntityNES extends TileEntity {
public int direction;
public ResourceLocation texture = new ResourceLocation("minecraft:textures/items/diamond.png");
@Override
public TileEntityNES(){
markDirt(); //tells minecraft that this has information that needs to be saved and accessed
}
@Override
public void writeToNBT(NBTTageCompound nbt){
super.writeToNBT(nbt) //saves coords and stuff like that.
nbt.setString("texture",texture.getResourceDomain()+texture.getResourcePath());
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
texture = new ResourceLocation(nbt.getString("texture"));
}
}
In your TESR:
public class RenderNES extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y,double z, float f) {
TileEntityNES tile = (TileEntityNES) tileentity; //tileentity is just a reference.
bindTexture(tile.texture);
}
}
In your block:
public class NES extends BlockContainer {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int notused0, float notused1, float notused2, float notused3){
((TileentityAnimationEditor) world.getTileEntity(x, y, z)).texture = new ResourceLocation("minecraft:textures/items/diamond.png"); //this loops through all the tileentities.
}
EDIT: Actually having an array of resource locations and each TileEntity storing an index to that thing would probably be the best way to do it. I think that's actually a lot like what a2937 said.
Animate your minecraft builds with Animated Structures: Link Removed
It doesnt do anything when I rightClick
I got a few errors and i think when i fixed it it doesnt do anything.
Well in the onBlockActivated method did you change "minecraft:textures/items/diamond.png" to something else like 'apple.png'. Also, in writeToNBT this nbt.setString("texture",texture.getResourceDomain()+texture.getResourcePath()); should be this nbt.setString("texture",texture.getResourceDomain()+':'+texture.getResourcePath());
Animate your minecraft builds with Animated Structures: Link Removed
It doesnt change anything