Skip to content

Commit

Permalink
Updated Frying pan rendering and block bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSpring committed Jan 29, 2016
1 parent 125d483 commit 0454331
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import dk.mrspring.kitchen.KitchenBlocks;
import dk.mrspring.kitchen.tileentity.TileEntityPan;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

Expand All @@ -27,62 +23,43 @@ public BlockFryingPan()
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
int metadata = world.getBlockMetadata(x, y, z);
int metadata = world.getBlockMetadata(x, y - 1, z);
float pixel = 0.06125F, height = 3 * pixel;
switch (metadata)
{
case 0:
this.setBlockBounds(2 * pixel, 0, 0, 0.5F + (2 * pixel), height, 0.5F);
break;
case 1:
this.setBlockBounds(0.5F + pixel, 0, 0, 1 + pixel, height, 0.5F);
break;
case 2:
this.setBlockBounds(0.5F + pixel, 0, 0.5F, 1 + pixel, height, 1);
break;
case 3:
this.setBlockBounds(2 * pixel, 0, 0.5F, 0.5F + (2 * pixel), height, 1);
break;
}
}

@Override
public void randomDisplayTick(World world, int x, int y, int z, Random random)
{
super.randomDisplayTick(world, x, y, z, random);

int metadata = world.getBlockMetadata(x, y, z);
float pixel = 0.06125F;
TileEntityPan tileEntityPan = (TileEntityPan) world.getTileEntity(x, y, z);

if (tileEntityPan.getCookTime() >= 400)
if (world.getBlock(x, y - 1, z) == KitchenBlocks.oven)
switch (metadata)
{
case 0:
world.spawnParticle("smoke",
x + 2 * pixel + (random.nextDouble() * (8 * pixel)),
y + 2 * pixel,
z + 0 + (random.nextDouble() * (8 * pixel)), 0, 0, 0);
this.setBlockBounds(0.5F, 0, 2 * pixel, 1F, height, 10 * pixel);
break;
case 1:
world.spawnParticle("smoke",
x + 0.5F + pixel + (random.nextDouble() * (8 * pixel)),
y + 2 * pixel,
z + 0.5F - (random.nextDouble() * (8 * pixel)), 0, 0, 0);
this.setBlockBounds(6 * pixel, 0, 0.5F, 14 * pixel, height, 1);
break;
case 2:
world.spawnParticle("smoke",
x + 0.5F + pixel + (random.nextDouble() * (8 * pixel)),
y + 2 * pixel,
z + 0.5F + (random.nextDouble() * (8 * pixel)), 0, 0, 0);
this.setBlockBounds(0, 0, 6 * pixel, 0.5F, height, 14 * pixel);
break;
case 3:
world.spawnParticle("smoke",
x + 2 * pixel + (random.nextDouble() * (8 * pixel)),
y + 2 * pixel,
z + 0.5F + (random.nextDouble() * (8 * pixel)), 0, 0, 0);
this.setBlockBounds(2 * pixel, 0, 0, 10 * pixel, height, 0.5F);
break;
}
else this.setBlockBounds(4 * pixel, 0, 4 * pixel, 12 * pixel, height, 12 * pixel);
}

@Override
public void randomDisplayTick(World world, int x, int y, int z, Random random)
{
super.randomDisplayTick(world, x, y, z, random);

double pixel = 0.06125D;
TileEntityPan tileEntityPan = (TileEntityPan) world.getTileEntity(x, y, z);
this.setBlockBoundsBasedOnState(world, x, y, z);

if (tileEntityPan.getCookTime() >= 400)
{
world.spawnParticle("smoke",
x + (minX + random.nextDouble() * (maxX - minX)),
y + 2.5D * pixel,
z + (minZ + random.nextDouble() * (maxZ - minZ)), 0D, 0D, 0D);
}
}

@Override
Expand Down Expand Up @@ -115,15 +92,6 @@ public boolean canPlaceBlockAt(World world, int x, int y, int z)
return world.getBlock(x, y - 1, z) == KitchenBlocks.oven;
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase placer, ItemStack placed)
{
int rotation = (MathHelper.floor_double((double) (placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3);
super.onBlockPlacedBy(world, x, y, z, placer, placed);

world.setBlockMetadataWithNotify(x, y, z, rotation, 0);
}

@Override
public boolean isOpaqueCube()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dk.mrspring.kitchen.tileentity.renderer;

import dk.mrspring.kitchen.KitchenBlocks;
import dk.mrspring.kitchen.ModInfo;
import dk.mrspring.kitchen.model.ModelPan;
import dk.mrspring.kitchen.pan.IIngredientRenderingHandler;
Expand All @@ -17,78 +18,63 @@
*/
public class TileEntityPanRenderer extends TileEntitySpecialRenderer
{
protected ModelPan model;
protected ResourceLocation textureLocation;

public TileEntityPanRenderer()
{
this.model = new ModelPan();
this.textureLocation = new ResourceLocation(ModInfo.toTexture("textures/models/pan.png"));
}

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float p_147500_8_)
{
GL11.glPushMatrix();

GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

GL11.glPushMatrix();

int metadata;
metadata = tileEntity.getBlockMetadata();

GL11.glRotatef(metadata * (90), 0F, 1F, 0F);

GL11.glPushMatrix();

float pixel = 0.0625F;
switch (metadata)
{
case 0:
GL11.glTranslatef(2 * pixel, 0F, -(4 * pixel));
break;
case 1:
GL11.glTranslatef(4 * pixel, 0F, -(5 * pixel));
break;
case 2:
GL11.glTranslatef(5 * pixel, 0F, -(4 * pixel));
break;
case 3:
GL11.glTranslatef(4 * pixel, 0F, -(2 * pixel));
break;
}


Minecraft.getMinecraft().renderEngine.bindTexture(this.textureLocation);
model.render(null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

TileEntityPan pan = (TileEntityPan) tileEntity;

Ingredient ingredient = pan.getIngredient();
if (ingredient != null)
if (ingredient != Ingredient.getIngredient("empty"))
{
IIngredientRenderingHandler renderingHandler = ingredient.getRenderingHandler();
ModelBase ingredientModel = renderingHandler.getModel(pan.getCookTime(), ingredient);
if (renderingHandler.useColorModifier(pan.getCookTime(), ingredient))
{
float[] colors = renderingHandler.getColorModifier(pan.getCookTime(), ingredient);
GL11.glColor4f(colors[0] / 255, colors[1] / 255, colors[2] / 255, 1F);
}
if (renderingHandler.scaleOnPan(pan.getCookTime(),ingredient))
{
GL11.glTranslatef(0.0F,0.835F,0.0F);
GL11.glScalef(0.4F, 0.4F, 0.4F);
}
ingredientModel.render(null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
}

GL11.glPopMatrix();

GL11.glPopMatrix();

GL11.glPopMatrix();
}
protected ModelPan model;
protected ResourceLocation textureLocation;

public TileEntityPanRenderer()
{
this.model = new ModelPan();
this.textureLocation = new ResourceLocation(ModInfo.toTexture("textures/models/pan.png"));
}

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float p_147500_8_)
{
GL11.glPushMatrix();

GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

int xc = tileEntity.xCoord, yc = tileEntity.yCoord, zc = tileEntity.zCoord;
boolean isOnOven = tileEntity.getWorldObj().getBlock(xc, yc - 1, zc) == KitchenBlocks.oven;

if (isOnOven)
{
float pixel = 0.0625F;
int metadata = tileEntity.getWorldObj().getBlockMetadata(xc, yc - 1, zc);
GL11.glRotatef(-metadata * (90), 0F, 1F, 0F);
GL11.glTranslatef(4 * pixel, 0F, -(2 * pixel));
}

GL11.glPushMatrix();

GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

Minecraft.getMinecraft().renderEngine.bindTexture(this.textureLocation);
model.render(null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

TileEntityPan pan = (TileEntityPan) tileEntity;

Ingredient ingredient = pan.getIngredient();
if (ingredient != null)
if (ingredient != Ingredient.getIngredient("empty"))
{
IIngredientRenderingHandler renderingHandler = ingredient.getRenderingHandler();
ModelBase ingredientModel = renderingHandler.getModel(pan.getCookTime(), ingredient);
if (renderingHandler.useColorModifier(pan.getCookTime(), ingredient))
{
float[] colors = renderingHandler.getColorModifier(pan.getCookTime(), ingredient);
GL11.glColor4f(colors[0] / 255, colors[1] / 255, colors[2] / 255, 1F);
}
if (renderingHandler.scaleOnPan(pan.getCookTime(), ingredient))
{
GL11.glTranslatef(0.0F, 0.835F, 0.0F);
GL11.glScalef(0.4F, 0.4F, 0.4F);
}
ingredientModel.render(null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
}

GL11.glPopMatrix();

GL11.glPopMatrix();
}
}

0 comments on commit 0454331

Please sign in to comment.