Skip to content

Instantly share code, notes, and snippets.

@marchermans
Created October 10, 2014 16:59
Show Gist options
  • Save marchermans/7bfe44e16e55a5606206 to your computer and use it in GitHub Desktop.
Save marchermans/7bfe44e16e55a5606206 to your computer and use it in GitHub Desktop.
Block firepit
package com.Orion.Armory.Common.Blocks;
/*
/ BlockFirePit
/ Created by : Orion
/ Created on : 02/10/2014
*/
import com.Orion.Armory.Common.Logic.Multiblock.IMultiBlockPart;
import com.Orion.Armory.Common.TileEntity.TileEntityFirePit;
import com.Orion.Armory.Util.References;
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.tileentity.TileEntityFurnace;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockFirePit extends BlockContainer implements IMultiBlockPart
{
protected String iInternalName = References.InternalNames.Blocks.FirePit;
public BlockFirePit() {
super(Material.fire);
}
@Override
public String getInternalName() {
return this.iInternalName;
}
@Override
public boolean validatePart(Integer pXCoord, Integer pYCoord, Integer pZCoord, World pWorld) {
if (pWorld.getBlock(pXCoord, pYCoord, pZCoord) == this)
{
return true;
}
return false;
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileEntityFirePit();
}
public void onBlockPlacedBy(World pWorld, int pX, int pY, int pZ, EntityLivingBase pPlacingEntity, ItemStack pItemStack)
{
int l = MathHelper.floor_double((double) (pPlacingEntity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
TileEntityFirePit tTE = (TileEntityFirePit) pWorld.getTileEntity(pX, pY, pZ);
if (l == 0)
{
tTE.setDirection(ForgeDirection.NORTH);
}
if (l == 1)
{
tTE.setDirection(ForgeDirection.EAST);
}
if (l == 2)
{
tTE.setDirection(ForgeDirection.SOUTH);
}
if (l == 3)
{
tTE.setDirection(ForgeDirection.WEST);
}
if (pItemStack.hasDisplayName())
{
tTE.setDisplayName(pItemStack.getDisplayName());
}
}
}
package com.Orion.Armory.Client.Renderer;
/*
* FirePitTEST
* Created by: Orion
* Created on: 10-10-2014
*/
import com.Orion.Armory.Client.Models.ModelFirePit;
import com.Orion.Armory.Common.TileEntity.TileEntityFirePit;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
public class FirePitTESR extends TileEntitySpecialRenderer
{
protected final ResourceLocation iOffTexture = new ResourceLocation("textures/blocks/FirePitTextureOff.png");
protected final ResourceLocation iBurningTexture = new ResourceLocation("texture/blocks/FirePitTextureOn.png");
protected final ResourceLocation iCoalSurfaceTexture = new ResourceLocation("textures/blocks/CoalSurface.png");
public final ModelFirePit iModel = new ModelFirePit();
public final RenderItem iItemRenderer;
public FirePitTESR()
{
iItemRenderer = new RenderItem()
{
@Override
public boolean shouldBob()
{
return false;
}
};
iItemRenderer.setRenderManager(RenderManager.instance);
}
@Override
public void renderTileEntityAt(TileEntity pEntity, double pX, double pY, double pZ, float pPartialTickTime) {
if (!(pEntity instanceof TileEntityFirePit))
{
return;
}
TileEntityFirePit tTEFirePit = (TileEntityFirePit) pEntity;
boolean tIsBurning = tTEFirePit.isBurning();
GL11.glPushMatrix();
scaleTranslateRotate(pX, pY, pZ, tTEFirePit.getDirection());
if(tIsBurning)
{
this.bindTexture(iBurningTexture);
iModel.renderPart("Furnace");
this.bindTexture(iCoalSurfaceTexture);
iModel.renderPart("CoalSurface");
}
else
{
this.bindTexture(iOffTexture);
iModel.renderPart("Furnace");
}
//TODO: Render the front tools.
GL11.glPopMatrix();
}
private void scaleTranslateRotate(double x, double y, double z, ForgeDirection orientation)
{
if (orientation == ForgeDirection.NORTH)
{
GL11.glTranslated(x + 1, y, z);
GL11.glRotatef(180F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
else if (orientation == ForgeDirection.EAST)
{
GL11.glTranslated(x + 1, y, z + 1);
GL11.glRotatef(90F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
else if (orientation == ForgeDirection.SOUTH)
{
GL11.glTranslated(x, y, z + 1);
GL11.glRotatef(0F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
else if (orientation == ForgeDirection.WEST)
{
GL11.glTranslated(x, y, z);
GL11.glRotatef(-90F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
}
}
package com.Orion.Armory.Common.TileEntity;
/*
/ TileEntityFirePit
/ Created by : Orion
/ Created on : 02/10/2014
*/
import com.Orion.Armory.Common.Factory.HeatedIngotFactory;
import com.Orion.Armory.Common.Registry.IngotRegistry;
import com.Orion.Armory.Util.HeatedIngots.NBTHelper;
import com.Orion.Armory.Util.References;
import net.minecraft.block.BlockChest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
public class TileEntityFirePit extends TileEntity implements IInventory
{
protected ArrayList<ItemStack> iIngotsInFire = new ArrayList<ItemStack>(5);
protected int iNumPlayersUsing;
protected float iCurrentTemperature = 20;
protected float iLastAddedHeat = 0;
protected boolean iIsBurning = false;
protected ForgeDirection iCurrentDirection = ForgeDirection.NORTH;
protected String iName = "Fire pit";
@Override
public int getSizeInventory() {
return iIngotsInFire.size();
}
@Override
public ItemStack getStackInSlot(int p_70301_1_) {
return iIngotsInFire.get(p_70301_1_);
}
@Override
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
if (this.iIngotsInFire.get(p_70298_1_) != null)
{
ItemStack itemstack;
if (this.iIngotsInFire.get(p_70298_1_).stackSize <= p_70298_2_)
{
itemstack = this.iIngotsInFire.get(p_70298_1_);
this.iIngotsInFire.set(p_70298_1_, null);
this.markDirty();
return itemstack;
}
else
{
itemstack = this.iIngotsInFire.get(p_70298_1_).splitStack(p_70298_2_);
if (this.iIngotsInFire.get(p_70298_1_).stackSize == 0)
{
this.iIngotsInFire.set(p_70298_1_, null);
}
this.markDirty();
return itemstack;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
if (this.iIngotsInFire.get(p_70304_1_) != null)
{
ItemStack itemstack = this.iIngotsInFire.get(p_70304_1_);
this.iIngotsInFire.set(p_70304_1_, null);
return itemstack;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
this.iIngotsInFire.set(p_70299_1_, p_70299_2_);
if (p_70299_2_ != null && p_70299_2_.stackSize > this.getInventoryStackLimit())
{
p_70299_2_.stackSize = this.getInventoryStackLimit();
}
this.markDirty();
}
@Override
public String getInventoryName() {
return References.InternalNames.TileEntities.FirePitContainer;
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public int getInventoryStackLimit() {
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : p_70300_1_.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
}
@Override
public void openInventory() {
if (this.iNumPlayersUsing < 0)
{
this.iNumPlayersUsing = 0;
}
++this.iNumPlayersUsing;
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, this.iNumPlayersUsing);
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType());
}
@Override
public void closeInventory() {
if (this.getBlockType() instanceof BlockChest)
{
--this.iNumPlayersUsing;
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, this.iNumPlayersUsing);
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType());
}
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
return false;
}
public void updateEntity()
{
int tTotalIngots = iIngotsInFire.size();
float tAddedHeat = this.iLastAddedHeat / (float) (tTotalIngots + 1);
for (ItemStack tIngot : iIngotsInFire)
{
int tIndex = iIngotsInFire.indexOf(tIngot);
if (IngotRegistry.geInstance().isHeatable(tIngot))
{
tIngot = HeatedIngotFactory.getInstance().convertToHeatedIngot(tIngot);
}
tIngot = NBTHelper.heatHeatedItem(tIngot, (int) tAddedHeat);
if (NBTHelper.getTemperatureOfIngot(tIngot) <= 20)
{
tIngot = HeatedIngotFactory.getInstance().convertToCooleadIngot(tIngot);
}
iIngotsInFire.add(tIndex, tIngot);
this.markDirty();
}
}
public float heatFurnace(float pFuelAmount)
{
this.iCurrentTemperature += pFuelAmount / 20F;
this.iLastAddedHeat = pFuelAmount / 20F;
return this.iCurrentTemperature;
}
public boolean isBurning() {return iIsBurning; }
public void setDirection(ForgeDirection pNewDirection)
{
this.iCurrentDirection = pNewDirection;
}
public ForgeDirection getDirection()
{
return this.iCurrentDirection;
}
public void setDisplayName(String pName)
{
this.iName = pName;
}
public String getDisplayName()
{
return this.iName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment