Got tesla transfering power
This commit is contained in:
parent
9b3ca1e547
commit
0c26e84808
10 changed files with 209 additions and 8 deletions
BIN
resources/assets/resonantinduction/textures/blocks/machine.png
Normal file
BIN
resources/assets/resonantinduction/textures/blocks/machine.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
|
@ -5,19 +5,25 @@ package resonantinduction;
|
|||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.render.BlockRenderingHandler;
|
||||
import resonantinduction.render.RenderTesla;
|
||||
import resonantinduction.tesla.TileEntityTesla;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
@Override
|
||||
public void registerRenderers()
|
||||
{
|
||||
RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE);
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla());
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,10 @@ package resonantinduction;
|
|||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface ITesla
|
||||
{
|
||||
public void transfer(float transferEnergy);
|
||||
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ public class ResonantInduction
|
|||
* Settings
|
||||
*/
|
||||
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), NAME + ".cfg"));
|
||||
public static float POWER_PER_COAL = 5;
|
||||
|
||||
/** Block ID by Jyzarc */
|
||||
private static final int BLOCK_ID_PREFIX = 3200;
|
||||
|
@ -103,6 +104,8 @@ public class ResonantInduction
|
|||
LOGGER.setParent(FMLLog.getLogger());
|
||||
|
||||
CONFIGURATION.load();
|
||||
POWER_PER_COAL = (float) CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Coal Wattage", POWER_PER_COAL).getDouble(POWER_PER_COAL);
|
||||
|
||||
blockTesla = new BlockTesla(getNextBlockID());
|
||||
CONFIGURATION.save();
|
||||
|
||||
|
|
53
src/resonantinduction/base/Vector3.java
Normal file
53
src/resonantinduction/base/Vector3.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction.base;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class Vector3
|
||||
{
|
||||
public double x, y, z;
|
||||
|
||||
public Vector3(double x, double y, double z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3()
|
||||
{
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Vector3(TileEntity tileEntity)
|
||||
{
|
||||
this(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
|
||||
public Vector3 difference(Vector3 compare)
|
||||
{
|
||||
return new Vector3(compare.x - this.x, compare.y - this.y, compare.z - this.z);
|
||||
}
|
||||
|
||||
public double getMagnitudeSquared()
|
||||
{
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
|
||||
public double getMagnitude()
|
||||
{
|
||||
return Math.sqrt(this.getMagnitudeSquared());
|
||||
}
|
||||
|
||||
public double distance(Vector3 compare)
|
||||
{
|
||||
Vector3 difference = this.difference(compare);
|
||||
return this.getMagnitude();
|
||||
}
|
||||
}
|
47
src/resonantinduction/render/BlockRenderingHandler.java
Normal file
47
src/resonantinduction/render/BlockRenderingHandler.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction.render;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
|
||||
{
|
||||
public static final BlockRenderingHandler INSTANCE = new BlockRenderingHandler();
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId()
|
||||
{
|
||||
return RenderingRegistry.getNextAvailableRenderId();
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,8 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import resonantinduction.ResonantInduction;
|
||||
import resonantinduction.model.ModelTeslaBottom;
|
||||
import resonantinduction.model.ModelTeslaMiddle;
|
||||
|
@ -17,6 +19,7 @@ import resonantinduction.model.ModelTeslaMiddle;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderTesla extends TileEntitySpecialRenderer
|
||||
{
|
||||
public static final ResourceLocation TEXTURE_BOTTOM = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "tesla_bottom.png");
|
||||
|
|
|
@ -7,7 +7,11 @@ import net.minecraft.block.ITileEntityProvider;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.ResonantInduction;
|
||||
import resonantinduction.base.BlockBase;
|
||||
import resonantinduction.render.BlockRenderingHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
|
@ -18,6 +22,7 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
|
|||
public BlockTesla(int id)
|
||||
{
|
||||
super("tesla", id, Material.iron);
|
||||
this.func_111022_d(ResonantInduction.PREFIX + "machine");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,10 +31,11 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
|
|||
return new TileEntityTesla();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int getRenderType()
|
||||
{
|
||||
return -1;
|
||||
return BlockRenderingHandler.INSTANCE.getRenderId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,4 +49,5 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction;
|
||||
package resonantinduction.tesla;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import resonantinduction.ITesla;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -50,7 +51,12 @@ public class TeslaGrid
|
|||
this.tileEntities.remove(iTesla);
|
||||
}
|
||||
|
||||
public static TeslaGrid getInstance()
|
||||
public Set<ITesla> get()
|
||||
{
|
||||
return this.tileEntities;
|
||||
}
|
||||
|
||||
public static TeslaGrid instance()
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
{
|
|
@ -3,9 +3,16 @@
|
|||
*/
|
||||
package resonantinduction.tesla;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.BlockFurnace;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import resonantinduction.ITesla;
|
||||
import resonantinduction.TeslaGrid;
|
||||
import resonantinduction.ResonantInduction;
|
||||
import resonantinduction.base.TileEntityBase;
|
||||
import resonantinduction.base.Vector3;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
|
@ -13,10 +20,13 @@ import resonantinduction.base.TileEntityBase;
|
|||
*/
|
||||
public class TileEntityTesla extends TileEntityBase implements ITesla
|
||||
{
|
||||
private float energy = 0;
|
||||
private boolean doTransfer = false;
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
TeslaGrid.getInstance().register(this);
|
||||
TeslaGrid.instance().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,17 +34,82 @@ public class TileEntityTesla extends TileEntityBase implements ITesla
|
|||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (this.ticks % 2 == 0 && this.getEnergyStored() > 0 && this.doTransfer)
|
||||
{
|
||||
Set<ITesla> transferTeslaCoils = new HashSet<ITesla>();
|
||||
|
||||
for (ITesla tesla : TeslaGrid.instance().get())
|
||||
{
|
||||
if (new Vector3((TileEntity) tesla).distance(new Vector3(this)) < this.getRange())
|
||||
{
|
||||
transferTeslaCoils.add(tesla);
|
||||
}
|
||||
}
|
||||
|
||||
float transferEnergy = this.getEnergyStored() / transferTeslaCoils.size();
|
||||
|
||||
for (ITesla tesla : transferTeslaCoils)
|
||||
{
|
||||
tesla.transfer(transferEnergy);
|
||||
this.transfer(-transferEnergy);
|
||||
}
|
||||
}
|
||||
|
||||
TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
|
||||
|
||||
if (tileEntity instanceof TileEntityFurnace)
|
||||
{
|
||||
TileEntityFurnace furnaceTile = (TileEntityFurnace) tileEntity;
|
||||
int burnTime = TileEntityFurnace.getItemBurnTime(furnaceTile.getStackInSlot(1));
|
||||
|
||||
if (burnTime > 0)
|
||||
{
|
||||
boolean doBlockStateUpdate = false;
|
||||
|
||||
if (furnaceTile.furnaceBurnTime == 0)
|
||||
{
|
||||
furnaceTile.decrStackSize(1, 1);
|
||||
furnaceTile.furnaceBurnTime = burnTime;
|
||||
doBlockStateUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
furnaceTile.furnaceBurnTime--;
|
||||
}
|
||||
|
||||
if (doBlockStateUpdate)
|
||||
{
|
||||
BlockFurnace.updateFurnaceBlockState(furnaceTile.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
this.transfer(ResonantInduction.POWER_PER_COAL / 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transfer(float transferEnergy)
|
||||
{
|
||||
System.out.println(transferEnergy);
|
||||
this.energy += transferEnergy;
|
||||
this.doTransfer = true;
|
||||
}
|
||||
|
||||
public float getEnergyStored()
|
||||
{
|
||||
return this.energy;
|
||||
}
|
||||
|
||||
public int getRange()
|
||||
{
|
||||
return 5;
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
TeslaGrid.getInstance().unregister(this);
|
||||
TeslaGrid.instance().unregister(this);
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue