Added hot plate smelting

This commit is contained in:
Calclavia 2014-01-17 21:58:05 +08:00
parent 024873067f
commit db964cda7b
14 changed files with 416 additions and 54 deletions

View file

@ -9,7 +9,9 @@ import resonantinduction.archaic.crate.TileCrate;
import resonantinduction.archaic.engineering.BlockEngineeringTable;
import resonantinduction.archaic.engineering.TileEngineeringTable;
import resonantinduction.archaic.firebox.BlockFirebox;
import resonantinduction.archaic.firebox.BlockHotPlate;
import resonantinduction.archaic.firebox.TileFirebox;
import resonantinduction.archaic.firebox.TileHotPlate;
import resonantinduction.archaic.imprint.BlockImprinter;
import resonantinduction.archaic.imprint.ItemBlockImprint;
import resonantinduction.archaic.imprint.TileImprinter;
@ -28,56 +30,60 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
/** Resonant Induction Archaic Module
/**
* Resonant Induction Archaic Module
*
* @author DarkCow, Calclavia */
* @author DarkCow, Calclavia
*/
@Mod(modid = Archaic.ID, name = Archaic.NAME, version = Reference.VERSION, dependencies = "required-after:" + ResonantInduction.ID)
@NetworkMod(channels = Reference.CHANNEL, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class)
public class Archaic
{
/** Mod Information */
public static final String ID = "ResonantInduction|Archaic";
public static final String NAME = Reference.NAME + " Archaic";
/** Mod Information */
public static final String ID = "ResonantInduction|Archaic";
public static final String NAME = Reference.NAME + " Archaic";
@Instance(ID)
public static Archaic INSTANCE;
@Instance(ID)
public static Archaic INSTANCE;
@SidedProxy(clientSide = "resonantinduction.archaic.ClientProxy", serverSide = "resonantinduction.archaic.CommonProxy")
public static CommonProxy proxy;
@SidedProxy(clientSide = "resonantinduction.archaic.ClientProxy", serverSide = "resonantinduction.archaic.CommonProxy")
public static CommonProxy proxy;
@Mod.Metadata(ID)
public static ModMetadata metadata;
@Mod.Metadata(ID)
public static ModMetadata metadata;
public static final ContentRegistry contentRegistry = new ContentRegistry(Settings.CONFIGURATION, ID);
public static final ContentRegistry contentRegistry = new ContentRegistry(Settings.CONFIGURATION, ID);
public static Block blockEngineeringTable;
public static Block blockCrate;
public static Block blockImprinter;
public static Block blockTurntable;
public static Block blockFirebox;
public static Block blockEngineeringTable;
public static Block blockCrate;
public static Block blockImprinter;
public static Block blockTurntable;
public static Block blockFirebox;
public static Block blockHotPlate;
public static Item itemImprint;
public static Item itemImprint;
@EventHandler
public void preInit(FMLPreInitializationEvent evt)
{
Settings.load();
NetworkRegistry.instance().registerGuiHandler(this, proxy);
blockEngineeringTable = contentRegistry.createTile(BlockEngineeringTable.class, TileEngineeringTable.class);
blockCrate = contentRegistry.createBlock(BlockCrate.class, ItemBlockCrate.class, TileCrate.class);
blockImprinter = contentRegistry.createTile(BlockImprinter.class, TileImprinter.class);
blockTurntable = contentRegistry.createBlock(BlockTurntable.class);
blockFirebox = contentRegistry.createTile(BlockFirebox.class, TileFirebox.class);
@EventHandler
public void preInit(FMLPreInitializationEvent evt)
{
Settings.load();
NetworkRegistry.instance().registerGuiHandler(this, proxy);
blockEngineeringTable = contentRegistry.createTile(BlockEngineeringTable.class, TileEngineeringTable.class);
blockCrate = contentRegistry.createBlock(BlockCrate.class, ItemBlockCrate.class, TileCrate.class);
blockImprinter = contentRegistry.createTile(BlockImprinter.class, TileImprinter.class);
blockTurntable = contentRegistry.createBlock(BlockTurntable.class);
blockFirebox = contentRegistry.createTile(BlockFirebox.class, TileFirebox.class);
blockHotPlate = contentRegistry.createTile(BlockHotPlate.class, TileHotPlate.class);
itemImprint = contentRegistry.createItem(ItemBlockImprint.class);
proxy.preInit();
Settings.save();
}
itemImprint = contentRegistry.createItem(ItemBlockImprint.class);
proxy.preInit();
Settings.save();
}
@EventHandler
public void init(FMLInitializationEvent evt)
{
Settings.setModMetadata(metadata, ID, NAME);
proxy.init();
}
@EventHandler
public void init(FMLInitializationEvent evt)
{
Settings.setModMetadata(metadata, ID, NAME);
proxy.init();
}
}

View file

@ -114,10 +114,8 @@ public class BlockEngineeringTable extends BlockRI
{
if (!world.isRemote)
{
ItemStack current = player.inventory.getCurrentItem();
Vector2 hitVector = new Vector2(hitX, hitZ);
double regionLength = 1d / 3d;
final double regionLength = 1d / 3d;
/**
* Crafting Matrix
@ -204,12 +202,6 @@ public class BlockEngineeringTable extends BlockRI
this.iconFront = par1IconRegister.registerIcon(this.getTextureName() + "_front");
}
@Override
public boolean isControlDown(EntityPlayer player)
{
return ControlKeyModifer.isControlDown(player);
}
@Override
public TileEntity createNewTileEntity(World world)
{

View file

@ -17,7 +17,7 @@ public class RenderEngineeringTable extends RenderItemOverlayTile
if (tileEntity instanceof TileEngineeringTable)
{
TileEngineeringTable tile = (TileEngineeringTable) tileEntity;
renderTopCrafting(tileEntity, tile.craftingMatrix, x, y, z);
renderTopOverlay(tileEntity, tile.craftingMatrix, x, y, z);
renderItemOnSides(tileEntity, tile.getStackInSlot(9), x, y, z);
}
}

View file

@ -0,0 +1,136 @@
package resonantinduction.archaic.firebox;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import resonantinduction.core.Reference;
import resonantinduction.core.prefab.block.BlockRI;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
public class BlockHotPlate extends BlockRI
{
private Icon topOn;
private Icon topOff;
public BlockHotPlate()
{
super("hotPlate", Material.wood);
setTextureName(Reference.PREFIX + "material_stone_chiseled");
setBlockBounds(0, 0, 0, 1, 0.2f, 1);
this.setTickRandomly(true);
}
@Override
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileHotPlate)
{
TileHotPlate tile = (TileHotPlate) tileEntity;
extractItem(tile, 0, player);
}
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileHotPlate)
{
TileHotPlate tile = (TileHotPlate) tileEntity;
if (!world.isRemote)
{
Vector2 hitVector = new Vector2(hitX, hitZ);
final double regionLength = 1d / 2d;
/**
* Crafting Matrix
*/
matrix:
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 2; k++)
{
Vector2 check = new Vector2(j, k).scale(regionLength);
if (check.distance(hitVector) < regionLength)
{
int slotID = j * 2 + k;
interactCurrentItem(tile, slotID, player);
break matrix;
}
}
}
tile.onInventoryChanged();
}
return true;
}
return false;
}
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random random)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileHotPlate)
{
TileHotPlate tile = (TileHotPlate) tileEntity;
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 2; k++)
{
int i = j * 2 + k;
if (tile.getSmeltTime(i) > 0)
{
int timeSmelt = TileHotPlate.MAX_SMELT_TIME - tile.getSmeltTime(i);
System.out.println(timeSmelt);
for (int spawn = 0; spawn < timeSmelt / 20; spawn++)
{
Vector3 particlePosition = new Vector3(x, y, z).translate((double) (i / 2) / ((double) 2) + (0.5 / ((double) 2)), 0.2, (double) (i % 2) / ((double) 2) + (0.5 / ((double) 2)));
particlePosition.translate(new Vector3(random.nextFloat() * 0.1f, random.nextFloat() * 0.1f, random.nextFloat() * 0.1f));
world.spawnParticle("smoke", particlePosition.x, particlePosition.y, particlePosition.z, 0.0D, 0.0D, 0.0D);
}
}
}
}
}
}
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity par5Entity)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileHotPlate)
{
TileHotPlate tile = (TileHotPlate) tileEntity;
if (tile.isSmelting())
{
par5Entity.attackEntityFrom(DamageSource.inFire, 1);
}
}
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileHotPlate();
}
}

View file

@ -0,0 +1,23 @@
package resonantinduction.archaic.firebox;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.tileentity.TileEntity;
import resonantinduction.core.render.RenderItemOverlayTile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderHotPlate extends RenderItemOverlayTile
{
private final RenderBlocks renderBlocks = new RenderBlocks();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
{
if (tileEntity instanceof TileHotPlate)
{
TileHotPlate tile = (TileHotPlate) tileEntity;
renderTopOverlay(tileEntity, tile.getInventory().getContainedItems(), 2, 2, x, y - 0.8, z);
}
}
}

View file

@ -6,6 +6,7 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
@ -49,7 +50,7 @@ public class TileFirebox extends TileExternalInventory implements IPacketSender,
worldObj.setBlock(xCoord, yCoord + 1, zCoord, Block.fire.blockID);
}
if (burnTime-- == 0)
if (--burnTime == 0)
{
if (blockID == Block.fire.blockID)
{
@ -120,4 +121,18 @@ public class TileFirebox extends TileExternalInventory implements IPacketSender,
e.printStackTrace();
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
burnTime = nbt.getInteger("burnTime");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("burnTime", burnTime);
}
}

View file

@ -0,0 +1,177 @@
package resonantinduction.archaic.firebox;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import resonantinduction.core.ResonantInduction;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.IPacketSender;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.tile.TileExternalInventory;
import com.google.common.io.ByteArrayDataInput;
/**
* For smelting items.
*
* @author Calclavia
*
*/
public class TileHotPlate extends TileExternalInventory implements IPacketSender, IPacketReceiver
{
/**
* The power of the firebox in terms of thermal energy. The thermal energy can be transfered
* into fluids to increase their internal energy.
*/
private final int POWER = 50000;
public final int[] smeltTime = new int[] { 0, 0, 0, 0 };
public static final int MAX_SMELT_TIME = 200;
public TileHotPlate()
{
invSlots = 4;
}
@Override
public void updateEntity()
{
if (!worldObj.isRemote)
{
TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord);
if (tileEntity instanceof TileFirebox)
{
if (((TileFirebox) tileEntity).isBurning())
{
for (int i = 0; i < invSlots; i++)
{
if (canSmelt(this.getStackInSlot(i)))
{
if (smeltTime[i] <= 0)
{
/**
* Heat up all slots
*/
smeltTime[i] = MAX_SMELT_TIME * this.getStackInSlot(i).stackSize;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
else if (smeltTime[i] > 0)
{
/**
* Do the smelt action.
*/
if (--smeltTime[i] == 0)
{
ItemStack outputStack = FurnaceRecipes.smelting().getSmeltingResult(getStackInSlot(i)).copy();
outputStack.stackSize = this.getStackInSlot(i).stackSize;
setInventorySlotContents(i, outputStack);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
else
{
smeltTime[i] = 0;
}
}
}
}
}
}
public boolean canSmelt(ItemStack stack)
{
return FurnaceRecipes.smelting().getSmeltingResult(stack) != null;
}
public boolean isSmelting()
{
for (int i = 0; i < invSlots; i++)
{
if (getSmeltTime(i) > 0)
{
return true;
}
}
return false;
}
public int getSmeltTime(int i)
{
return smeltTime[i];
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemStack)
{
return i < invSlots && canSmelt(itemStack);
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(0).toArray());
}
@Override
public void onInventoryChanged()
{
super.onInventoryChanged();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
/**
* 1 - Description Packet
* 2 - Energy Update
* 3 - Tesla Beam
*/
@Override
public List getPacketData(int type)
{
List list = new ArrayList();
NBTTagCompound nbt = new NBTTagCompound();
this.writeToNBT(nbt);
list.add(nbt);
return list;
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
this.readFromNBT(PacketHandler.readNBTTagCompound(data));
this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord);
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
for (int i = 0; i < invSlots; i++)
smeltTime[i] = nbt.getInteger("smeltTime" + i);
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
for (int i = 0; i < invSlots; i++)
nbt.setInteger("smeltTime" + i, smeltTime[i]);
}
}

View file

@ -17,7 +17,7 @@ public class RenderImprinter extends RenderItemOverlayTile
if (tileEntity instanceof TileImprinter)
{
TileImprinter tile = (TileImprinter) tileEntity;
renderTopCrafting(tileEntity, tile.inventory, x, y, z);
renderTopOverlay(tileEntity, tile.inventory, x, y, z);
renderItemOnSides(tileEntity, tile.getStackInSlot(9), x, y, z);
}
}

View file

@ -1,6 +1,8 @@
package resonantinduction.core.prefab.block;
import codechicken.multipart.ControlKeyModifer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.Configuration;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInductionTabs;
@ -35,4 +37,9 @@ public class BlockRI extends BlockTile
this.setHardness(1f);
}
@Override
public boolean isControlDown(EntityPlayer player)
{
return ControlKeyModifer.isControlDown(player);
}
}

View file

@ -29,7 +29,12 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
{
private final RenderBlocks renderBlocks = new RenderBlocks();
public void renderTopCrafting(TileEntity tileEntity, ItemStack[] inventory, double x, double y, double z)
public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, double x, double y, double z)
{
renderTopOverlay(tileEntity, inventory, 3, 3, x, y, z);
}
public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, int matrixX, int matrixZ, double x, double y, double z)
{
/**
* Render the Crafting Matrix
@ -43,11 +48,11 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
isLooking |= objectPosition.blockX == tileEntity.xCoord && objectPosition.blockY == tileEntity.yCoord && objectPosition.blockZ == tileEntity.zCoord;
}
for (int i = 0; i < 9; i++)
for (int i = 0; i < (matrixX * matrixZ); i++)
{
if (inventory[i] != null)
{
Vector3 translation = new Vector3(x + (double) (i / 3) / 3d + (0.5 / 3d), y + 1.1, z + (double) (i % 3) / 3d + (0.5 / 3d));
Vector3 translation = new Vector3(x + (double) (i / matrixX) / ((double) matrixX) + (0.5 / ((double) matrixX)), y + 1.1, z + (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / ((double) matrixZ)));
GL11.glPushMatrix();
GL11.glTranslated(translation.x, translation.y, translation.z);
GL11.glScalef(0.7f, 0.7f, 0.7f);

View file

@ -13,7 +13,7 @@ public class BlockReleaseValve extends BlockRI
{
public BlockReleaseValve()
{
super("ReleaseValve");
super("releaseValve");
this.setHardness(1f);
this.setResistance(5f);
}

View file

@ -19,6 +19,7 @@ item.resonantinduction\:imprint.name=Imprint
tile.resonantinduction\:imprinter.name=Imprinter
tile.resonantinduction\:engineeringTable.name=Engineering Table
tile.resonantinduction\:firebox.name=Firebox
tile.resonantinduction\:hotPlate.name=Hot Plate
## Transport
tile.resonantinduction\:turntable.name=Turntable

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB