Hello! I created custom block and trying to rotate it, but its position is good only for one direction (2), for others (0,1,3) its position is strange.
RenderTable.java
package com.bros.tastymod.rendering.entities.tiles.tileentities;
import com.bros.tastymod.model.ModelMeat;
import com.bros.tastymod.rendering.entities.tiles.TileEntityTable;
import jdk.nashorn.internal.runtime.regexp.joni.constants.EncloseType;
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;
public class RenderTable extends TileEntitySpecialRenderer {
private ModelMeat model;
private ResourceLocation texture = new ResourceLocation("tastymod:textures/blocks/Meat.png");
public RenderTable() {
model = new ModelMeat();
}
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale) {
GL11.glPushMatrix();
GL11.glTranslated(x - 0.3, y + 0.5, z + 0.3);
GL11.glRotated(0, 0, 0, 1);
TileEntityTable myTile = (TileEntityTable) tile;
int dir = myTile.direction;
GL11.glRotatef(dir * (-180F), 0.0F, 1.0F, 0.0F);
this.bindTexture(texture);
this.model.render((Entity) null, 0, -0.1f, 0, 0, 0, 0.0625f);
GL11.glPopMatrix();
}
}
BlockTable.java
package com.bros.tastymod.blocks;
import com.bros.tastymod.rendering.entities.tiles.TileEntityTable;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
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;
public class BlockTable extends BlockContainer {
public BlockTable() {
super(Material.iron);
setBlockName("table");
}
@Override
public int getRenderType(){
return -1;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean isNormalCube(){
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int id) {
return new TileEntityTable();
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
if (entity==null){
return;
}
TileEntityTable tile = (TileEntityTable) world.getTileEntity(x,y,z);
tile.direction = MathHelper.floor_double((double) (entity.rotationYaw*4.0F/360)+0.5D) &3;
if(tile.direction==1){
world.setBlockMetadataWithNotify(x,y,z,5,2);
}
}
}
TileEntityTable.java
package com.bros.tastymod.rendering.entities.tiles;
import net.minecraft.tileentity.TileEntity;
public class TileEntityTable extends TileEntity {
public int direction;
}