I am having some slight difficulties whenever i place this block i have made, facing different ways the direction of the block changes? I only want it to rotate 90 so it looks the same South but the way you are facing? any suggestions?
package evocity.blocks.gaspump;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import evocity.lib.ModInfo;
import evocity.lib.Names;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class TileEntityGasPumpBlock extends BlockContainer {
public TileEntityGasPumpBlock(int id) {
super(id, Material.iron);
this.setUnlocalizedName(Names.GasPump_unlocalizedName);
this.setCreativeTab(CreativeTabs.tabDecorations);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
this.setLightValue(0.5F);
}
public TileEntity createNewTileEntity(World world) {
return new TileEntityGasPumpEntity();
}
public int getRenderType() {
return -1;
}
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister icon){
this.blockIcon = icon.registerIcon(ModInfo.ID.toLowerCase() + ":" + "Gas");
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
{
if (entity == null)
{
return;
}
TileEntityGasPumpEntity tile = (TileEntityGasPumpEntity) world.getBlockTileEntity(x, y, z);
tile.direction = MathHelper.floor_double((double)(entity.rotationYaw * 4F / 360.0F) + 2.5D) & 3;
}
}
Entity
package evocity.blocks.gaspump;
import net.minecraft.tileentity.TileEntity;
public class TileEntityGasPumpEntity extends TileEntity {
public int direction;
}
Renderer
package evocity.blocks.gaspump;
import org.lwjgl.opengl.GL11;
import evocity.lib.ModInfo;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
public class TileEntityGasPumpRenderer extends TileEntitySpecialRenderer {
private static final ResourceLocation texture = new ResourceLocation(ModInfo.ID.toLowerCase(), "textures/entities/ModelGasPump.png");
private ModelGasPump model;
public TileEntityGasPumpRenderer(){
this.model = new ModelGasPump();
}
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
TileEntityGasPumpEntity myTile = (TileEntityGasPumpEntity) tileentity;
int direction = myTile.direction;
GL11.glPushMatrix();
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
GL11.glRotatef(direction * 90, 0F, 0F, 1F);
this.bindTexture(texture);
GL11.glPushMatrix();
this.model.renderModel(0.0625F);
GL11.glPopMatrix();
GL11.glPopMatrix();
}
}
Model
Block
Entity
Renderer