Jump to content

[1.7.10] Rotation on blocks resets when logging out


IvanTune

Recommended Posts

Hello there!

 

I'm trying to figure out why my blocks reset their rotation data when logging out.

It works fine while logged in, but when relogging all blocks face one direction.

 

I'm also doing proxy.registerTileEntities(); in main class in preInit.

 

Any help is very much appricated!

 

 

BlockCustomFurnace:

package com.IvanTune.futuregate.block;

import java.util.Random;

import javax.swing.Icon;

import com.IvanTune.futuregate.FutureGate;
import com.IvanTune.futuregate.init.ModBlocks;
import com.IvanTune.futuregate.reference.Reference;
import com.IvanTune.futuregate.tileentity.TileEntityCustomFurnace;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
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.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class BlockCustomFurnace extends BlockContainer {

private Random rand = new Random();

private final boolean isActive;

private static boolean keepInventory;

public BlockCustomFurnace(boolean isActive) {
	super(Material.rock);

	this.isActive = isActive;
}

public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}


public Item getItemDropped(int par1, Random random, int par3) {
	return Item.getItemFromBlock(ModBlocks.blockCustomFurnaceIdle);
}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX,
		float hitY, float hitZ) {
	if (world.isRemote) {
		return true;
	} else {
		TileEntityCustomFurnace tileentityCustomFurnace = (TileEntityCustomFurnace) world.getTileEntity(x, y, z);

		if (tileentityCustomFurnace != null) {
			player.openGui(FutureGate.instance, 0, world, x, y, z);

		}

		return true;
	}
}

public TileEntity createNewTileEntity(World world, int i) {
	return new TileEntityCustomFurnace();
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister){
	this.blockIcon = iconRegister.registerIcon(Reference.MOD_ID + ":" + this.getUnlocalizedName().substring(5));
}

@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random random) {
	if (this.isActive) {
		int direction = world.getBlockMetadata(x, y, z);

		float x1 = (float) x + 0.5F;
		float y1 = (float) ((float) y + random.nextInt(4) * 0.1);
		float z1 = (float) z + 0.5F;

		float f = 0.52F;
		float f1 = random.nextFloat() * 0.6F - 0.3F;

		if (direction == 4) {
			world.spawnParticle("smoke", (double) (x1 - f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double) (x1 - f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
		} else if (direction == 5) {
			world.spawnParticle("smoke", (double) (x1 + f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double) (x1 + f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
		} else if (direction == 2) {
			world.spawnParticle("smoke", (double) (x1 + f1), (double) (y1), (double) (z1 - f), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double) (x1 + f1), (double) (y1), (double) (z1 - f), 0.0D, 0.0D, 0.0D);
		} else if (direction == 3) {
			world.spawnParticle("smoke", (double) (x1 + f1), (double) (y1), (double) (z1 + f), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double) (x1 + f1), (double) (y1), (double) (z1 + f), 0.0D, 0.0D, 0.0D);
		}
	}
}

    @Override
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack)
    {
        int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
        int newFacing = 0;
        if (facing == 0)
        {
        	newFacing = 2;
        }
        if (facing == 1)
        {
        	newFacing = 5;
        }
        if (facing == 2)
        {
        	newFacing = 3;
        }
        if (facing == 3)
        {
        	newFacing = 4;
        }
        TileEntity te = world.getTileEntity(i, j, k);
        if (te != null && te instanceof TileEntityCustomFurnace)
        {
        	TileEntityCustomFurnace tet = (TileEntityCustomFurnace) te;
            tet.setFacingDirection(newFacing);
            world.markBlockForUpdate(i, j, k);
        }
    }

public static void updateCustomFurnaceBlock(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) {
	int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
	TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord);
	keepInventory = true;

	if (active) {
		// places block in a different location when block activates //	worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.blockCustomFurnaceActive);
	} else {
		worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.blockCustomFurnaceIdle);
	}

	keepInventory = false;

	worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);

	if (tileentity != null) {
		tileentity.validate();
		worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity);
	}
}

public void breakBlock(World world, int x, int y, int z, Block oldBlock, int oldMetadata) {
	if (!keepInventory) {
		TileEntityCustomFurnace tileentity = (TileEntityCustomFurnace) world.getTileEntity(x, y, z);

		if (tileentity != null) {
			for (int i = 0; i < tileentity.getSizeInventory(); i++) {
				ItemStack itemstack = tileentity.getStackInSlot(i);

				if (itemstack != null) {
					float f = this.rand.nextFloat() * 0.8F + 0.1F;
					float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
					float f2 = this.rand.nextFloat() * 0.8F + 0.1F;

					while (itemstack.stackSize > 0) {
						int j = this.rand.nextInt(21) + 10;

						if (j > itemstack.stackSize) {
							j = itemstack.stackSize;
						}

						itemstack.stackSize -= j;

						EntityItem item = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1),
								(double) ((float) z + f2),
								new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));

						if (itemstack.hasTagCompound()) {
							item.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
						}

						float f3 = 0.05F;
						item.motionX = (double) ((float) this.rand.nextGaussian() * f3);
						item.motionY = (double) ((float) this.rand.nextGaussian() * f3 + 0.2F);
						item.motionZ = (double) ((float) this.rand.nextGaussian() * f3);

						world.spawnEntityInWorld(item);
					}

				}
			}

			world.func_147453_f(x, y, z, oldBlock);
		}
	}

	super.breakBlock(world, x, y, z, oldBlock, oldMetadata);
}

public boolean hasComparatorInputOverride() {
	return true;
}

public int getComparatorInputOverride(World world, int x, int y, int z, int i) {
	return Container.calcRedstoneFromInventory((IInventory) world.getTileEntity(x, y, z));
}

public Item getItem(World world, int x, int y, int z) {
	return Item.getItemFromBlock(ModBlocks.blockCustomFurnaceIdle);
}

}

 

TileEntityCustomFurnace:

package com.IvanTune.futuregate.tileentity;

import com.IvanTune.futuregate.block.BlockCustomFurnace;

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityCustomFurnace extends TileEntity implements ISidedInventory {

private String localizedName;

private static final int[] slots_top = new int[] { 0 };
private static final int[] slots_bottom = new int[] { 2 };
private static final int[] slots_sides = new int[] { 1 };

public int getFacingDirection()
    {
        return facingDirection;
    }

public void setFacingDirection(int par1)
    {
        this.facingDirection = par1;
    }

private int facingDirection;

private ItemStack[] slots = new ItemStack[3];

public int furnaceSpeed = 100;

public int burnTime;

public int currentItemBurnTime;

public int cookTime;

public int getSizeInventory() {
	return this.slots.length;
}

public String getInventoryName() {
	return this.hasCustomInventoryName() ? this.localizedName : "container.customFurnace";
}

public boolean hasCustomInventoryName() {
	return this.localizedName != null && this.localizedName.length() > 0;
}

public void setGuiDisplayName(String displayName) {
	this.localizedName = displayName;

}

public ItemStack getStackInSlot(int i) {

	return this.slots[i];
}

public ItemStack decrStackSize(int i, int j) {
	if (this.slots[i] != null) {
		ItemStack itemstack;

		if (this.slots[i].stackSize <= j) {

			itemstack = this.slots[i];
			this.slots[i] = null;
			return itemstack;
		} else {
			itemstack = this.slots[i].splitStack(j);

			if (this.slots[i].stackSize == 0) {
				this.slots[i] = null;
			}

			return itemstack;
		}
	}

	return null;
}

public ItemStack getStackInSlotOnClosing(int i) {
	if (this.slots[i] != null) {
		ItemStack itemstack = this.slots[i];
		this.slots[i] = null;
		return itemstack;
	}

	return null;
}

public void setInventorySlotContents(int i, ItemStack itemstack) {
	this.slots[i] = itemstack;

	if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {
		itemstack.stackSize = this.getInventoryStackLimit();
	}
}

public int getInventoryStackLimit() {

	return 64;
}

public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	facingDirection = nbt.getInteger("facingDirection");

	NBTTagList list = nbt.getTagList("Items", 10);
	this.slots = new ItemStack[this.getSizeInventory()];

	for (int i = 0; i < list.tagCount(); i++) {
		NBTTagCompound compound = (NBTTagCompound) list.getCompoundTagAt(i);
		byte b = compound.getByte("Slot");

		if (b >= 0 && b < this.slots.length) {
			this.slots[b] = ItemStack.loadItemStackFromNBT(compound);

		}
	}

	this.burnTime = (int) nbt.getShort("BurnTime");
	this.cookTime = (int) nbt.getShort("CookTime");
	this.currentItemBurnTime = (int) nbt.getShort("CurrentBurnTime");

	if (nbt.hasKey("CustomName")) {
		this.localizedName = nbt.getString("CustomName");
	}
}

public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	nbt.setInteger("facingDirection", facingDirection);

	nbt.setShort("BurnTime", (short) this.burnTime);
	nbt.setShort("CookTime", (short) this.cookTime);
	nbt.setShort("CurrentBurnTime", (short) this.currentItemBurnTime);

	NBTTagList list = new NBTTagList();

	for (int i = 0; i < this.slots.length; i++) {
		if (this.slots[i] != null) {
			NBTTagCompound compound = new NBTTagCompound();
			compound.setByte("Slot", (byte) i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);

		}

	}

	nbt.setTag("Items", list);

	if (this.hasCustomInventoryName()) {
		nbt.setString("CustomName", this.localizedName);
	}
}

public boolean isUseableByPlayer(EntityPlayer entityplayer) {

	return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false
			: entityplayer.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D,
					(double) this.zCoord + 0.5D) <= 64.0D;
}

public boolean isBurning() {
	return this.burnTime > 0;
}

public void updateEntity() {
	boolean flag = this.burnTime > 0;
	boolean flag1 = false;

	if (this.burnTime > 0) {
		this.burnTime--;
	}

	if (!this.worldObj.isRemote) {
		if (this.burnTime == 0 && this.canSmelt()) {
			this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[1]);

			if (this.burnTime > 0) {
				flag1 = true;

				if (this.slots[1] != null) {
					this.slots[1].stackSize--;

					if (this.slots[1].stackSize == 0) {
						this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);

					}

				}
			}

		}

		if (this.isBurning() && this.canSmelt()) {
			this.cookTime++;

			if (this.cookTime == this.furnaceSpeed) {
				this.cookTime = 0;
				this.smeltItem();
				flag1 = true;
			}
		} else {
			this.cookTime = 0;
		}

		if (flag != this.burnTime > 0) {
			flag1 = true;
			BlockCustomFurnace.updateCustomFurnaceBlock(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord,
					this.zCoord);

		}
	}

	if (flag1) {
		this.markDirty();
	}

}

private boolean canSmelt() {
	if (this.slots[0] == null) {
		return false;
	} else {
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if (itemstack == null) return false;
		if (this.slots[2] == null) return true;
		if (!this.slots[2].isItemEqual(itemstack)) return false;

		int result = this.slots[2].stackSize + itemstack.stackSize;

		return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
	}
}

public void smeltItem() {
	if (this.canSmelt()) {
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if (this.slots[2] == null) {
			this.slots[2] = itemstack.copy();
		} else if (this.slots[2].isItemEqual(itemstack)) {
			this.slots[2].stackSize += itemstack.stackSize;
		}

		this.slots[0].stackSize--;

		if (this.slots[0].stackSize <= 0) {
			this.slots[0] = null;
		}
	}
}

public static int getItemBurnTime(ItemStack itemstack) {
	if (itemstack == null) {
		return 0;
	} else {
		Item item = itemstack.getItem();

		if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
			Block block = Block.getBlockFromItem(item);

			if (block == Blocks.wooden_slab) {
				return 150;
			}

			if (block.getMaterial() == Material.wood) {
				return 300;
			}

			if (block == Blocks.coal_block) {
				return 16000;
			}
		}

		if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD"))
			return 200;
		if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD"))
			return 200;
		if (item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD"))
			return 200;
		if (item == Items.stick)
			return 100;
		if (item == Items.coal)
			return 1600;
		if (item == Items.lava_bucket)
			return 100;
		if (item == Item.getItemFromBlock(Blocks.sapling))
			return 100;
		if (item == Items.blaze_rod)
			return 100;

		return GameRegistry.getFuelValue(itemstack);
	}
}

public static boolean isItemFuel(ItemStack itemstack) {
	return getItemBurnTime(itemstack) > 0;
}

public boolean isItemValidForSlot(int i, ItemStack itemstack) {

	return i == 2 ? false : (i == 1 ? isItemFuel(itemstack) : true);
}

public int[] getAccessibleSlotsFromSide(int var1) {

	return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_sides);
}

public boolean canInsertItem(int i, ItemStack itemstack, int j) {

	return this.isItemValidForSlot(i, itemstack);
}

public boolean canExtractItem(int i, ItemStack itemstack, int j) {

	return j != 0 || i != 1 || itemstack.getItem() == Items.bucket;
}

public int getBurnTimeRemainingScaled(int i) {
	if (this.currentItemBurnTime == 0) {
		this.currentItemBurnTime = this.furnaceSpeed;

	}
	return this.burnTime * i / this.currentItemBurnTime;
}

public int getCookProgressScaled(int i) {
	return this.cookTime * i / this.furnaceSpeed;
}

public void openInventory() {
}

public void closeInventory() {
}

}

 

RendererCustomFurnace:

package com.IvanTune.futuregate.renderer;

import org.lwjgl.opengl.GL11;

import com.IvanTune.futuregate.FutureGate;
import com.IvanTune.futuregate.model.ModelCustomFurnace;
import com.IvanTune.futuregate.reference.Reference;
import com.IvanTune.futuregate.tileentity.TileEntityCustomFurnace;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class RendererCustomFurnace extends TileEntitySpecialRenderer {

private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID, "textures/model/customFurnace.png");

private ModelCustomFurnace model;

public RendererCustomFurnace(){
	this.model = new ModelCustomFurnace();
}	      
	   
    public void render(TileEntityCustomFurnace 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);
        //Rotates model, as for some reason it is initially upside (180 = angle, 1.0F at end = about z axis)
        GL11.glRotatef(180, 0.0F, 0.0F, 1.0F);
        int facing = tileentity.getFacingDirection();
        int k = 0;
        //South
        if (facing == 2) {
            k = -90;
        }
        //North
        if (facing == 3) {
            k = 90;
        }
        //East
        if (facing == 4) {
            k = 180;
        }
        //West
        if (facing == 5) {
            k = 0;
        }
        //Rotates model on the spot, depending on direction, making the front always to player) (k = angle, 1.0F in middle = about y axis)
        GL11.glRotatef(k, 0.0F, 1.0F, 0.0F);
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_ALPHA_TEST);
        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
	}

    
    public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_)
    {
    	this.render((TileEntityCustomFurnace)p_147500_1_, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_);
    }
}

 

Common proxy:

package com.IvanTune.futuregate.proxy;

import com.IvanTune.futuregate.tileentity.TileEntityCustomFurnace;
import com.IvanTune.futuregate.tileentity.TileEntityCustomMacerator;
import com.IvanTune.futuregate.tileentity.TileEntityTestBlock;

import cpw.mods.fml.common.registry.GameRegistry;

public abstract class CommonProxy
{

public abstract void init();

public abstract void preInit();

public abstract void postInit();

public void registerRenderThings(){

}

public void registerTileEntities(){

	GameRegistry.registerTileEntity(TileEntityCustomFurnace.class, "tileEntityCustomFurnace");
	GameRegistry.registerTileEntity(TileEntityCustomMacerator.class, "tileEntityCustomMacerator");
	GameRegistry.registerTileEntity(TileEntityTestBlock.class, "tileEntityTestBlock");
}

public void initRenderers() {

}

}

 

Client Proxy:

package com.IvanTune.futuregate.proxy;

import com.IvanTune.futuregate.FutureGate;
import com.IvanTune.futuregate.client.KeyInputHandler;
import com.IvanTune.futuregate.client.Keybindings;
import com.IvanTune.futuregate.client.RenderDroid;
import com.IvanTune.futuregate.entities.EntityDroid;
import com.IvanTune.futuregate.init.ModBlocks;
import com.IvanTune.futuregate.init.ModItems;
import com.IvanTune.futuregate.model.ModelDroid;
import com.IvanTune.futuregate.renderer.ItemRenderTestBlock;
import com.IvanTune.futuregate.renderer.ItemRendererCustomFurnace;
import com.IvanTune.futuregate.renderer.ItemRendererCustomMacerator;
import com.IvanTune.futuregate.renderer.RendererCustomFurnace;
import com.IvanTune.futuregate.renderer.RendererCustomMacerator;
import com.IvanTune.futuregate.renderer.RendererDroidItem;
import com.IvanTune.futuregate.renderer.RendererTestBlock;
import com.IvanTune.futuregate.tileentity.TileEntityCustomFurnace;
import com.IvanTune.futuregate.tileentity.TileEntityCustomMacerator;
import com.IvanTune.futuregate.tileentity.TileEntityTestBlock;

import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.Item;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;

public class ClientProxy extends CommonProxy {


public void registerRenderThings(){
	//TestBlock
	TileEntitySpecialRenderer render = new RendererTestBlock();
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTestBlock.class, render);
	MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.testBlock), new ItemRenderTestBlock(render, new TileEntityTestBlock()));

	//CustomFurnace
	TileEntitySpecialRenderer render1 = new RendererCustomFurnace();
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCustomFurnace.class, render1);
	MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.blockCustomFurnaceIdle), new ItemRendererCustomFurnace(render1, new TileEntityCustomFurnace()));

	//CustomMacerator
	TileEntitySpecialRenderer render2 = new RendererCustomMacerator();
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCustomMacerator.class, render2);
	MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.blockCustomMaceratorIdle), new ItemRendererCustomMacerator(render2, new TileEntityCustomMacerator()));
}

public void registerTileEntities(){

}


@Override
public void initRenderers() {
	ModelDroid model = new ModelDroid();
	RenderingRegistry.registerEntityRenderingHandler(EntityDroid.class, new RenderDroid(model));
	MinecraftForgeClient.registerItemRenderer(ModItems.droid, new RendererDroidItem(model));

	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCustomMacerator.class, new RendererCustomMacerator());
}

@Override
public void preInit() {
	registerKeybinds();
}

private void registerKeybinds() {
	FMLCommonHandler.instance().bus().register(new KeyInputHandler());
	for (Keybindings key : Keybindings.values()) {
		ClientRegistry.registerKeyBinding(key.getKeybind());
	}
}

@Override
public void init() {

}

@Override
public void postInit() {

}
}

Link to comment
Share on other sites

Thanks for reply!

 

Something like this right?

 

it keeps crashing on line 28:

int meta = world.getBlockMetadata(x, y, z);

 

I feel like this shouln't be that hard, but whatever I try it always seems to fail somehow, hehe.

 

RendererCustomFurnace

package com.IvanTune.futuregate.renderer;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import com.IvanTune.futuregate.reference.Reference;

import org.lwjgl.opengl.GL11;

import com.IvanTune.futuregate.model.ModelCustomFurnace;

public class RendererCustomFurnace extends TileEntitySpecialRenderer {

    public final ModelCustomFurnace model;
    private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID, "textures/model/customMacerator.png");

    public RendererCustomFurnace() {
        this.model = new ModelCustomFurnace();
    }

    private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
        int meta = world.getBlockMetadata(x, y, z);
        GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
    }

    @Override
    public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float scale) {
        GL11.glPushMatrix();
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        Minecraft.getMinecraft().renderEngine.bindTexture(texture);
        GL11.glPushMatrix();
        adjustRotatePivotViaMeta(tileentity.getWorldObj(), tileentity.xCoord, tileentity.yCoord, tileentity.zCoord);
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
        model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
    }
}

Link to comment
Share on other sites

Oops, sorry!

 

---- Minecraft Crash Report ----
// Why is it breaking 

Time: 13.08.15 21:16
Description: Rendering item

java.lang.NullPointerException: Rendering item
at net.minecraft.tileentity.TileEntity.getBlockMetadata(TileEntity.java:157)
at com.IvanTune.futuregate.renderer.RendererCustomFurnace.renderAModelAt(RendererCustomFurnace.java:34)
at com.IvanTune.futuregate.renderer.RendererCustomFurnace.renderTileEntityAt(RendererCustomFurnace.java:77)
at com.IvanTune.futuregate.renderer.ItemRendererCustomFurnace.renderItem(ItemRendererCustomFurnace.java:38)
at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183)
at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583)
at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973)
at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209)
at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1114)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067)
at net.minecraft.client.Minecraft.run(Minecraft.java:962)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraft.tileentity.TileEntity.getBlockMetadata(TileEntity.java:157)
at com.IvanTune.futuregate.renderer.RendererCustomFurnace.renderAModelAt(RendererCustomFurnace.java:34)
at com.IvanTune.futuregate.renderer.RendererCustomFurnace.renderTileEntityAt(RendererCustomFurnace.java:77)
at com.IvanTune.futuregate.renderer.ItemRendererCustomFurnace.renderItem(ItemRendererCustomFurnace.java:38)
at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183)

-- Item being rendered --
Details:
Item Type: net.minecraft.item.ItemBlock@30b6cfc7
Item Aux: 0
Item NBT: null
Item Foil: false
Stacktrace:
at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583)
at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973)
at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209)
at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player72'/169, l='MpServer', x=1860,75, y=5,62, z=1496,60]]
Chunk stats: MultiplayerChunkCache: 265, 265
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (1874,4,1499), Chunk: (at 2,0,11 in 117,93; contains blocks 1872,0,1488 to 1887,255,1503), Region: (3,2; contains chunks 96,64 to 127,95, blocks 1536,0,1024 to 2047,255,1535)
Level time: 949 game time, 949 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 45 total; [EntityCow['Cow'/132, l='MpServer', x=1939,94, y=4,00, z=1433,81], EntitySheep['Sheep'/135, l='MpServer', x=1940,28, y=4,00, z=1440,84], EntityCow['Cow'/80, l='MpServer', x=1870,09, y=4,00, z=1428,81], EntityPig['Pig'/81, l='MpServer', x=1877,97, y=4,00, z=1422,91], EntityCow['Cow'/82, l='MpServer', x=1872,50, y=4,00, z=1423,19], EntityCow['Cow'/83, l='MpServer', x=1876,50, y=4,00, z=1421,50], EntityPig['Pig'/84, l='MpServer', x=1884,94, y=4,00, z=1433,09], EntityPig['Pig'/85, l='MpServer', x=1872,22, y=4,00, z=1431,31], EntityPig['Pig'/86, l='MpServer', x=1877,50, y=4,00, z=1424,50], EntityCow['Cow'/87, l='MpServer', x=1874,41, y=4,00, z=1427,97], EntityCow['Cow'/88, l='MpServer', x=1877,28, y=4,00, z=1431,78], EntityCow['Cow'/89, l='MpServer', x=1874,13, y=4,00, z=1426,56], EntityCow['Cow'/90, l='MpServer', x=1873,16, y=4,00, z=1428,22], EntityChicken['Chicken'/30, l='MpServer', x=1787,19, y=4,00, z=1501,81], EntityPig['Pig'/31, l='MpServer', x=1790,03, y=4,00, z=1513,41], EntityCow['Cow'/32, l='MpServer', x=1791,50, y=4,00, z=1570,50], EntityCow['Cow'/33, l='MpServer', x=1790,44, y=4,00, z=1571,66], EntityPig['Pig'/34, l='MpServer', x=1782,16, y=4,00, z=1569,81], EntityCow['Cow'/35, l='MpServer', x=1791,88, y=4,00, z=1573,44], EntityClientPlayerMP['Player72'/169, l='MpServer', x=1860,75, y=5,62, z=1496,60], EntityChicken['Chicken'/42, l='MpServer', x=1805,38, y=4,00, z=1500,63], EntityChicken['Chicken'/43, l='MpServer', x=1799,41, y=4,00, z=1510,75], EntityChicken['Chicken'/44, l='MpServer', x=1795,50, y=4,00, z=1511,50], EntityPig['Pig'/45, l='MpServer', x=1800,28, y=4,00, z=1510,75], EntityPig['Pig'/46, l='MpServer', x=1806,78, y=4,00, z=1504,59], EntityCow['Cow'/111, l='MpServer', x=1911,75, y=4,00, z=1506,75], EntityPig['Pig'/47, l='MpServer', x=1802,81, y=4,00, z=1506,81], EntityPig['Pig'/48, l='MpServer', x=1793,50, y=4,00, z=1511,50], EntityPig['Pig'/49, l='MpServer', x=1792,81, y=4,00, z=1508,53], EntityPig['Pig'/50, l='MpServer', x=1791,94, y=4,00, z=1504,94], EntityPig['Pig'/51, l='MpServer', x=1794,13, y=4,00, z=1573,41], EntityCow['Cow'/116, l='MpServer', x=1926,69, y=4,00, z=1500,31], EntityCow['Cow'/117, l='MpServer', x=1921,06, y=4,00, z=1495,97], EntityChicken['Chicken'/118, l='MpServer', x=1922,22, y=4,00, z=1499,38], EntityChicken['Chicken'/119, l='MpServer', x=1922,50, y=4,00, z=1503,50], EntityCow['Cow'/55, l='MpServer', x=1792,19, y=4,00, z=1572,03], EntityChicken['Chicken'/120, l='MpServer', x=1924,50, y=4,00, z=1502,50], EntityPig['Pig'/56, l='MpServer', x=1796,31, y=4,00, z=1572,13], EntityCow['Cow'/121, l='MpServer', x=1926,50, y=4,00, z=1498,50], EntityPig['Pig'/57, l='MpServer', x=1793,50, y=4,00, z=1574,94], EntityCow['Cow'/122, l='MpServer', x=1921,38, y=4,00, z=1498,44], EntityPig['Pig'/58, l='MpServer', x=1797,50, y=4,00, z=1575,50], EntityCow['Cow'/123, l='MpServer', x=1924,25, y=4,00, z=1497,78], EntityCow['Cow'/124, l='MpServer', x=1923,50, y=4,00, z=1506,50], EntityChicken['Chicken'/125, l='MpServer', x=1925,50, y=4,00, z=1506,50]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)
at net.minecraft.client.Minecraft.run(Minecraft.java:984)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_51, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 776453024 bytes (740 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1492 9 mods loaded, 9 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAAAA	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1492-1.7.10.jar) 
UCHIJAAAA	Forge{10.13.4.1492} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1492-1.7.10.jar) 
UCHIJAAAA	CodeChickenCore{1.0.4.29} [CodeChicken Core] (minecraft.jar) 
UCHIJAAAA	NotEnoughItems{1.0.3.74} [Not Enough Items] (NotEnoughItems-1.7.10-1.0.3.74-universal.jar) 
UCHIJAAAA	futuregate{1.0} [FutureGate] (bin) 
UCHIJAAAA	ForgeMultipart{1.1.2.331} [Forge Multipart] (ForgeMultipart-1.7.10-1.1.2.331-dev.jar) 
UCHIJAAAA	McMultipart{1.1.2.331} [Minecraft Multipart Plugin] (ForgeMultipart-1.7.10-1.1.2.331-dev.jar) 
UCHIJAAAA	ForgeMicroblock{1.1.2.331} [Forge Microblocks] (ForgeMultipart-1.7.10-1.1.2.331-dev.jar) 
GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 353.62' Renderer: 'GeForce GTX 970/PCIe/SSE2'
Launched Version: 1.7.10
LWJGL: 2.9.1
OpenGL: GeForce GTX 970/PCIe/SSE2 GL version 4.5.0 NVIDIA 353.62, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Anisotropic filtering is supported and maximum anisotropy is 16.
Shaders are available because OpenGL 2.1 is supported.

Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Anisotropic Filtering: Off (1)

 

Here is how i render the item in hand too:

ItemRendererCustomFurnace:

package com.IvanTune.futuregate.renderer;

import org.lwjgl.opengl.GL11;

import com.IvanTune.futuregate.model.ModelCustomFurnace;
import com.IvanTune.futuregate.tileentity.TileEntityCustomFurnace;

import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.IItemRenderer;

public class ItemRendererCustomFurnace implements IItemRenderer {

TileEntitySpecialRenderer render;
private TileEntity entity;

public ItemRendererCustomFurnace(TileEntitySpecialRenderer render, TileEntity entity){
	this.entity = entity;
	this.render = render;
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return true;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	return true;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	if(type == IItemRenderer.ItemRenderType.ENTITY)
		GL11.glTranslatef(-0.5F, 0.0F, -0.5F);
	this.render.renderTileEntityAt(this.entity, 0.0D, 0.0D, 0.0D, 0.0F);
}

}

Link to comment
Share on other sites

Got it working by removing the ItemRenderer in hand code, now block rotation stays put on login. :D

 

Who needs a beautiful, delicious, 3d model rendered in hand, on the go? Like.. yeah... :(

 

But yeah thanks for the help diesieben07, gonna figure it out eventually ;)

 

Link to comment
Share on other sites

Or you could check for a null world object and then supply a 0 for metadata instead.

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

That might have been a big rookie mistake by me earier there... :P

 

Added this in ItemRendererCustomFurnace class:

public ModelCustomFurnace model = new ModelCustomFurnace();
private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID, "textures/model/customFurnace.png");

 

Then in same class to render it out in hand:

	
GL11.glPushMatrix();
GL11.glScalef(1.0F, 1.0F, 1.0F);
GL11.glRotatef(180, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(0.0F, -1.F, 0.0F);
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
model.renderModel(0.0625F);
GL11.glPopMatrix();

 

Probably not the best way to do it but now the block renders in hand and block rotation on logout stays the same. :D

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.