Conflicts:
	src/resonantinduction/contractor/TileEntityEMContractor.java
	src/resonantinduction/model/ModelEMContractor.java
	src/resonantinduction/render/RenderEMContractor.java
This commit is contained in:
Aidan Brady 2013-08-03 22:35:23 -04:00
commit f8091d1b15
21 changed files with 865 additions and 28 deletions

View file

@ -6,6 +6,8 @@ itemGroup.resonantinduction=Resonant Induction
tile.resonantinduction\:tesla.name=Tesla Coil
tile.resonantinduction\:multimeter.name=Multimeter
tile.resonantinduction\:contractor.name=Electromagnetic Contractor
tile.resonantinduction\:battery.name=Modular Battery
## Items
item.resonantinduction\:quantumEntangler.name=Quantum Entangler
item.resonantinduction\:quantumEntangler.name=Quantum Entangler
item.resonantinduction\:capacitor.name=Capacitor Cell

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 B

View file

@ -1,6 +1,3 @@
/**
*
*/
package resonantinduction;
import net.minecraft.entity.player.EntityPlayer;
@ -14,6 +11,7 @@ import resonantinduction.multimeter.GuiMultimeter;
import resonantinduction.multimeter.TileEntityMultimeter;
import resonantinduction.render.BlockRenderingHandler;
import resonantinduction.render.RenderEMContractor;
import resonantinduction.render.RenderMultimeter;
import resonantinduction.render.RenderTesla;
import resonantinduction.tesla.TileEntityTesla;
import cpw.mods.fml.client.FMLClientHandler;
@ -37,6 +35,7 @@ public class ClientProxy extends CommonProxy
RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultimeter.class, new RenderMultimeter());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor());
}

View file

@ -9,11 +9,15 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.ShapedOreRecipe;
import resonantinduction.battery.BlockBattery;
import resonantinduction.battery.ItemCapacitor;
import resonantinduction.battery.TileEntityBattery;
import resonantinduction.contractor.BlockEMContractor;
import resonantinduction.contractor.ItemBlockContractor;
import resonantinduction.contractor.TileEntityEMContractor;
import resonantinduction.entangler.ItemQuantumEntangler;
import resonantinduction.multimeter.BlockMultimeter;
import resonantinduction.multimeter.ItemBlockMultimeter;
import resonantinduction.multimeter.TileEntityMultimeter;
import resonantinduction.tesla.BlockTesla;
import resonantinduction.tesla.TileEntityTesla;
@ -106,24 +110,26 @@ public class ResonantInduction
// Items
public static Item itemQuantumEntangler;
public static Item itemCapacitor;
// Blocks
public static Block blockTesla;
public static Block blockMultimeter;
public static Block blockEMContractor;
public static Block blockBattery;
@EventHandler
public void preInit(FMLPreInitializationEvent evt)
{
LOGGER.setParent(FMLLog.getLogger());
NetworkRegistry.instance().registerGuiHandler(this, this.proxy);
NetworkRegistry.instance().registerGuiHandler(this, ResonantInduction.proxy);
CONFIGURATION.load();
// Config
POWER_PER_COAL = (float) CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Coal Wattage", POWER_PER_COAL).getDouble(POWER_PER_COAL);
SOUND_FXS = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Tesla Sound FXs", SOUND_FXS).getBoolean(SOUND_FXS);
TileEntityEMContractor.ACCELERATION = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEntityEMContractor.ACCELERATION).getDouble(TileEntityEMContractor.ACCELERATION);
TileEntityEMContractor.MAX_REACH = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Reach", TileEntityEMContractor.MAX_REACH).getInt(TileEntityEMContractor.MAX_REACH);
TileEntityEMContractor.MAX_SPEED = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Speed", TileEntityEMContractor.MAX_SPEED).getDouble(TileEntityEMContractor.MAX_SPEED);
@ -131,23 +137,29 @@ public class ResonantInduction
// Items
itemQuantumEntangler = new ItemQuantumEntangler(getNextItemID());
itemCapacitor = new ItemCapacitor(getNextItemID());
GameRegistry.registerItem(itemQuantumEntangler, itemQuantumEntangler.getUnlocalizedName());
GameRegistry.registerItem(itemCapacitor, itemCapacitor.getUnlocalizedName());
// Blocks
blockTesla = new BlockTesla(getNextBlockID());
blockMultimeter = new BlockMultimeter(getNextBlockID());
blockEMContractor = new BlockEMContractor(getNextBlockID());
blockBattery = new BlockBattery(getNextBlockID());
CONFIGURATION.save();
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
GameRegistry.registerBlock(blockMultimeter, blockMultimeter.getUnlocalizedName());
GameRegistry.registerBlock(blockMultimeter, ItemBlockMultimeter.class, blockMultimeter.getUnlocalizedName());
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerBlock(blockBattery, blockBattery.getUnlocalizedName());
// Tiles
GameRegistry.registerTileEntity(TileEntityTesla.class, blockTesla.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityMultimeter.class, blockMultimeter.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
ResonantInduction.proxy.registerRenderers();

View file

@ -0,0 +1,15 @@
/**
*
*/
package resonantinduction.api;
/**
* @author Calclavia
*
*/
public interface IBattery
{
public float getEnergyStored();
public float getMaxEnergyStored();
}

View file

@ -3,7 +3,13 @@
*/
package resonantinduction.base;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
/**
* @author Calclavia
@ -12,6 +18,7 @@ import net.minecraft.tileentity.TileEntity;
public class TileEntityBase extends TileEntity
{
protected long ticks = 0;
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
public void initiate()
{
@ -28,5 +35,9 @@ public class TileEntityBase extends TileEntity
this.initiate();
}
for (EntityPlayer player : this.playersUsing)
{
PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) player);
}
}
}

View file

@ -135,7 +135,7 @@ public class Vector3
return new Vector3(this.x + offset.x, this.y + offset.y, this.z + offset.z);
}
public Vector3 translate(int offset)
public Vector3 translate(double offset)
{
return new Vector3(this.x + offset, this.y + offset, this.z + offset);
}

View file

@ -0,0 +1,23 @@
/**
*
*/
package resonantinduction.battery;
import java.util.HashSet;
import java.util.Set;
/**
* Multiblock battery controller
*
* @author Calclavia
*
*/
public class BatteryController
{
public Set<TileEntityBattery> connectedBlocks = new HashSet<TileEntityBattery>();
public void update()
{
}
}

View file

@ -0,0 +1,81 @@
/**
*
*/
package resonantinduction.battery;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import resonantinduction.base.BlockBase;
import resonantinduction.multimeter.TileEntityMultimeter;
/**
* A block that detects power.
*
* @author Calclavia
*
*/
public class BlockBattery extends BlockBase implements ITileEntityProvider
{
private Icon machineIcon;
public BlockBattery(int id)
{
super("battery", id, Material.iron);
}
@Override
public Icon getIcon(int side, int metadata)
{
if (side == metadata)
{
return this.blockIcon;
}
return this.machineIcon;
}
@Override
public void registerIcons(IconRegister iconRegister)
{
super.registerIcons(iconRegister);
this.machineIcon = iconRegister.registerIcon(ResonantInduction.PREFIX + "machine");
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9)
{
if (entityPlayer.isSneaking())
{
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.ROTATION_MATRIX[world.getBlockMetadata(x, y, z)][side], 3);
}
else
{
}
return true;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityBattery();
}
}

View file

@ -0,0 +1,23 @@
/**
*
*/
package resonantinduction.battery;
import resonantinduction.base.ItemBase;
/**
* Stores power.
*
* @author Calclavia
*
*/
public class ItemCapacitor extends ItemBase
{
public ItemCapacitor(int id)
{
super("capacitor", id);
this.setMaxStackSize(1);
this.setMaxDamage(1000);
}
}

View file

@ -0,0 +1,180 @@
/**
*
*/
package resonantinduction.battery;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import resonantinduction.api.IBattery;
import resonantinduction.base.TileEntityBase;
/**
* A modular battery with no GUI.
*
* @author Calclavia
*/
public class TileEntityBattery extends TileEntityBase implements IInventory
{
private ItemStack[] inventory = new ItemStack[4 * 4];
private byte[] sideStatus = new byte[] { 0, 0, 0, 0, 0, 0 };
// TODO: Multiblock power storage.
private BatteryController controller;
@Override
public void updateEntity()
{
}
public float getMaxEnergyStored()
{
float max = 0;
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack itemStack = this.getStackInSlot(i);
if (itemStack != null)
{
if (itemStack.getItem() instanceof IBattery)
{
max += ((IBattery) itemStack.getItem()).getMaxEnergyStored();
}
}
}
return max;
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.inventory.length;
}
/**
* Returns the stack in slot i
*/
public ItemStack getStackInSlot(int par1)
{
return this.inventory[par1];
}
/**
* Removes from an inventory slot (first arg) up to a specified number (second arg) of items and
* returns them in a new stack.
*/
public ItemStack decrStackSize(int par1, int par2)
{
if (this.inventory[par1] != null)
{
ItemStack itemstack;
if (this.inventory[par1].stackSize <= par2)
{
itemstack = this.inventory[par1];
this.inventory[par1] = null;
return itemstack;
}
else
{
itemstack = this.inventory[par1].splitStack(par2);
if (this.inventory[par1].stackSize == 0)
{
this.inventory[par1] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
/**
* When some containers are closed they call this on each slot, then drop whatever it returns as
* an EntityItem - like when you close a workbench GUI.
*/
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.inventory[par1] != null)
{
ItemStack itemstack = this.inventory[par1];
this.inventory[par1] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor
* sections).
*/
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
this.inventory[par1] = par2ItemStack;
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{
par2ItemStack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public String getInvName()
{
return this.getBlockType().getLocalizedName();
}
@Override
public boolean isInvNameLocalized()
{
return true;
}
@Override
public int getInventoryStackLimit()
{
return 0;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
// TODO Auto-generated method stub
return false;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.inventory.IInventory#openChest()
*/
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return false;
}
}

View file

@ -85,12 +85,12 @@ public class FXElectricBolt extends EntityFX
this.segments.add(new BoltSegment(this.start, this.end));
this.recalculate();
double offsetRatio = this.boltLength * this.complexity;
this.split(2, offsetRatio / 8, 0.7f, 0.1f, 20);
this.split(2, offsetRatio / 12, 0.5f, 0.1f, 25);
this.split(2, offsetRatio / 24, 0.5f, 0.1f, 28);
this.split(2, offsetRatio / 32, 0.5f, 0.1f, 30);
this.split(2, offsetRatio / 48, 0, 0, 0);
this.split(2, offsetRatio / 64, 0, 0, 0);
this.split(2, offsetRatio / 10, 0.7f, 0.1f, 20);
this.split(2, offsetRatio / 15, 0.5f, 0.1f, 25);
this.split(2, offsetRatio / 25, 0.5f, 0.1f, 28);
this.split(2, offsetRatio / 38, 0.5f, 0.1f, 30);
this.split(2, offsetRatio / 55, 0, 0, 0);
this.split(2, offsetRatio / 70, 0, 0, 0);
this.recalculate();
@ -154,7 +154,7 @@ public class FXElectricBolt extends EntityFX
*/
for (int i = 1; i < splitAmount; i++)
{
Vector3 newOffset = segment.difference.getPerpendicular().rotate(this.rand.nextFloat() * 180, segment.difference).scale((this.rand.nextFloat() - 0.5F) * offset);
Vector3 newOffset = segment.difference.getPerpendicular().rotate(this.rand.nextFloat() * 360, segment.difference).scale((this.rand.nextFloat() - 0.5F) * offset);
Vector3 basePoint = startPoint.clone().translate(subSegment.clone().scale(i));
newPoints[i] = new BoltPoint(basePoint, newOffset);
@ -172,7 +172,7 @@ public class FXElectricBolt extends EntityFX
if ((i != 0) && (this.rand.nextFloat() < splitChance))
{
Vector3 splitrot = next.difference.xCrossProduct().rotate(this.rand.nextFloat() * 180, next.difference);
Vector3 splitrot = next.difference.xCrossProduct().rotate(this.rand.nextFloat() * 360, next.difference);
Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).scale(splitLength);
this.maxSplitID += 1;
this.parentIDMap.put(this.maxSplitID, next.splitID);

View file

@ -225,14 +225,14 @@ public class ModelEMContractor extends ModelBase
public void render(float f5, boolean rotate)
{
if(rotate)
if (rotate)
{
Coil1.rotateAngleY = (float)Math.toRadians(Math.toDegrees(Coil1.rotateAngleY)+3 < 360 ? Math.toDegrees(Coil1.rotateAngleY)+3 : 0);
coil2.rotateAngleY = (float)Math.toRadians(Math.toDegrees(coil2.rotateAngleY)+3 < 360 ? Math.toDegrees(coil2.rotateAngleY)+3 : 0);
coil3.rotateAngleY = (float)Math.toRadians(Math.toDegrees(coil3.rotateAngleY)+3 < 360 ? Math.toDegrees(coil3.rotateAngleY)+3 : 0);
coil4.rotateAngleY = (float)Math.toRadians(Math.toDegrees(coil4.rotateAngleY)+3 < 360 ? Math.toDegrees(coil4.rotateAngleY)+3 : 0);
}
frame1.render(f5);
frame2.render(f5);
frame3.render(f5);

View file

@ -5,9 +5,16 @@ package resonantinduction.multimeter;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import resonantinduction.base.BlockBase;
@ -19,18 +26,104 @@ import resonantinduction.base.BlockBase;
*/
public class BlockMultimeter extends BlockBase implements ITileEntityProvider
{
private Icon machineIcon;
public BlockMultimeter(int id)
{
super("multimeter", id, Material.iron);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
public static int determineOrientation(World par0World, int par1, int par2, int par3, EntityLivingBase par4EntityLivingBase)
{
entityPlayer.openGui(ResonantInduction.INSTNACE, 0, world, x, y, z);
if (MathHelper.abs((float) par4EntityLivingBase.posX - par1) < 2.0F && MathHelper.abs((float) par4EntityLivingBase.posZ - par3) < 2.0F)
{
double d0 = par4EntityLivingBase.posY + 1.82D - par4EntityLivingBase.yOffset;
if (d0 - par2 > 2.0D)
{
return 1;
}
if (par2 - d0 > 0.0D)
{
return 0;
}
}
int l = MathHelper.floor_double(par4EntityLivingBase.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
int l = determineOrientation(world, x, y, z, par5EntityLivingBase);
world.setBlockMetadataWithNotify(x, y, z, l, 2);
}
@Override
public Icon getIcon(int side, int metadata)
{
if (side == metadata)
{
return this.blockIcon;
}
return this.machineIcon;
}
@Override
public void registerIcons(IconRegister iconRegister)
{
super.registerIcons(iconRegister);
this.machineIcon = iconRegister.registerIcon(ResonantInduction.PREFIX + "machine");
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9)
{
if (entityPlayer.isSneaking())
{
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.ROTATION_MATRIX[world.getBlockMetadata(x, y, z)][side], 3);
}
else
{
entityPlayer.openGui(ResonantInduction.INSTNACE, 0, world, x, y, z);
}
return true;
}
@Override
public int isProvidingStrongPower(IBlockAccess blockAccess, int x, int y, int z, int par5)
{
return this.isProvidingWeakPower(blockAccess, x, y, z, par5);
}
@Override
public int isProvidingWeakPower(IBlockAccess blockAccess, int x, int y, int z, int par5)
{
TileEntity tile = blockAccess.getBlockTileEntity(x, y, z);
if (tile instanceof TileEntityMultimeter)
{
return ((TileEntityMultimeter) tile).redstoneOn ? 14 : 0;
}
return 0;
}
@Override
public boolean canProvidePower()
{
return true;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World world)
{

View file

@ -15,9 +15,11 @@ import net.minecraft.inventory.Slot;
public class ContainerMultimeter extends Container
{
private final int yDisplacement = 51;
private TileEntityMultimeter tileEntity;
public ContainerMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tileEntity)
{
this.tileEntity = tileEntity;
int i;
for (i = 0; i < 3; ++i)
@ -32,6 +34,15 @@ public class ContainerMultimeter extends Container
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142 + yDisplacement));
}
this.tileEntity.playersUsing.add(inventoryPlayer.player);
}
@Override
public void onContainerClosed(EntityPlayer entityPlayer)
{
this.tileEntity.playersUsing.remove(entityPlayer);
super.onContainerClosed(entityPlayer);
}
@Override

View file

@ -3,12 +3,15 @@
*/
package resonantinduction.multimeter;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -22,11 +25,12 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiMultimeter extends GuiContainer
{
private static final ResourceLocation TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.GUI_DIRECTORY + "gui_base.png");
private static final ResourceLocation TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.GUI_DIRECTORY + "gui_multimeter.png");
TileEntityMultimeter tileEntity;
private int containerWidth;
private int containerHeight;
private GuiTextField textFieldLimit;
public GuiMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tileEntity)
{
@ -35,12 +39,50 @@ public class GuiMultimeter extends GuiContainer
this.ySize = 217;
}
@Override
public void initGui()
{
super.initGui();
this.buttonList.add(new GuiButton(0, this.width / 2 + 20, this.height / 2 - 30, 50, 20, "Toggle"));
this.textFieldLimit = new GuiTextField(fontRenderer, 35, 82, 65, 12);
this.textFieldLimit.setMaxStringLength(8);
this.textFieldLimit.setText("" + this.tileEntity.getLimit());
}
@Override
protected void keyTyped(char par1, int par2)
{
super.keyTyped(par1, par2);
this.textFieldLimit.textboxKeyTyped(par1, par2);
try
{
PacketHandler.sendTileEntityPacketToServer(this.tileEntity, (byte) 3, Float.parseFloat(this.textFieldLimit.getText()));
}
catch (Exception e)
{
}
}
@Override
protected void mouseClicked(int par1, int par2, int par3)
{
super.mouseClicked(par1, par2, par3);
this.textFieldLimit.mouseClicked(par1 - this.containerWidth, par2 - this.containerHeight, par3);
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
String s = this.tileEntity.getBlockType().getLocalizedName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString("Energy: " + this.tileEntity.getDetectedEnergy(), 9, 15, 4210752);
this.fontRenderer.drawString("Energy: " + Math.round(this.tileEntity.getDetectedEnergy()) + " J", 35, 32, 4210752);
this.fontRenderer.drawString("Average Energy: " + Math.round(this.tileEntity.getAverageDetectedEnergy()) + " J", 35, 20, 4210752);
this.fontRenderer.drawString("Output Redstone If... ", 35, 46, 4210752);
this.fontRenderer.drawString(this.tileEntity.getMode().display, 35, 65, 4210752);
this.fontRenderer.drawString("KiloJoules", 35, 100, 4210752);
this.textFieldLimit.drawTextBox();
}
@Override
@ -52,6 +94,19 @@ public class GuiMultimeter extends GuiContainer
this.mc.renderEngine.func_110577_a(TEXTURE);
GL11.glColor4f(1, 1, 1, 1);
this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize);
/*
* if (this.tileEntity.getMode() != DetectMode.NONE) { int length = (int)
* (Math.abs(this.tileEntity.getDetectedEnergy() - this.tileEntity.getLimit()) /
* this.tileEntity.getLimit()) * 110; this.drawTexturedModalRect(this.containerWidth + 13,
* this.containerHeight + 128 - length, 176, 0, 30, length); }
*/
}
@Override
protected void actionPerformed(GuiButton button)
{
PacketHandler.sendTileEntityPacketToServer(this.tileEntity, (byte) 2);
}
}

View file

@ -0,0 +1,37 @@
/**
*
*/
package resonantinduction.multimeter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* ItemBlock for the Multimeter
*
* @author Calclavia
*
*/
public class ItemBlockMultimeter extends ItemBlock
{
public ItemBlockMultimeter(int par1)
{
super(par1);
}
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
{
if (par2EntityPlayer.isSneaking())
{
if (!world.isRemote)
{
par2EntityPlayer.addChatMessage("Energy: " + TileEntityMultimeter.getDetectedEnergy(world.getBlockTileEntity(x, y, z)) + " J");
}
return true;
}
return super.onItemUse(par1ItemStack, par2EntityPlayer, world, x, y, z, par7, par8, par9, par10);
}
}

View file

@ -3,21 +3,194 @@
*/
package resonantinduction.multimeter;
import java.util.ArrayList;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction;
import resonantinduction.base.IPacketReceiver;
import resonantinduction.base.TileEntityBase;
import resonantinduction.tesla.TileEntityTesla;
import com.google.common.io.ByteArrayDataInput;
/**
* @author Calclavia
*
*/
public class TileEntityMultimeter extends TileEntityBase
public class TileEntityMultimeter extends TileEntityBase implements IPacketReceiver
{
public float getDetectedEnergy()
public enum DetectMode
{
NONE("None"), LESS_THAN("Less Than"), LESS_THAN_EQUAL("Less Than or Equal"),
EQUAL("Equal"), GREATER_THAN("Greater Than or Equal"), GREATER_THAN_EQUAL("Greater Than");
public String display;
private DetectMode(String display)
{
this.display = display;
}
}
private DetectMode detectMode = DetectMode.NONE;
private float energyLimit;
private float detectedEnergy;
private float detectedAverageEnergy;
public boolean redstoneOn;
@Override
public void updateEntity()
{
super.updateEntity();
if (this.ticks % 20 == 0)
{
float prevDetectedEnergy = this.detectedEnergy;
this.detectedEnergy = this.doGetDetectedEnergy();
this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2;
boolean outputRedstone = false;
switch (detectMode)
{
default:
break;
case EQUAL:
outputRedstone = this.detectedEnergy == this.energyLimit;
break;
case GREATER_THAN:
outputRedstone = this.detectedEnergy > this.energyLimit;
break;
case GREATER_THAN_EQUAL:
outputRedstone = this.detectedEnergy >= this.energyLimit;
break;
case LESS_THAN:
outputRedstone = this.detectedEnergy < this.energyLimit;
break;
case LESS_THAN_EQUAL:
outputRedstone = this.detectedEnergy <= this.energyLimit;
break;
}
if (outputRedstone != this.redstoneOn)
{
this.redstoneOn = outputRedstone;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, ResonantInduction.blockMultimeter.blockID);
}
/*
* if (prevDetectedEnergy != this.detectedEnergy) {
* this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); }
*/
}
}
@Override
public Packet getDescriptionPacket()
{
return PacketHandler.getTileEntityPacket(this, (byte) 1, (byte) this.detectMode.ordinal(), this.energyLimit);
}
@Override
public void handle(ByteArrayDataInput input)
{
try
{
switch (input.readByte())
{
default:
this.detectMode = DetectMode.values()[input.readByte()];
this.energyLimit = input.readFloat();
break;
case 2:
this.toggleMode();
break;
case 3:
this.energyLimit = input.readFloat();
break;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
return null;
}
public float doGetDetectedEnergy()
{
ForgeDirection direction = ForgeDirection.getOrientation(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord));
ForgeDirection opp = direction.getOpposite();
TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.xCoord + opp.offsetX, this.yCoord + opp.offsetY, this.zCoord + opp.offsetZ);
return getDetectedEnergy(tileEntity);
}
public static float getDetectedEnergy(TileEntity tileEntity)
{
// TODO: Universal Compatiblity in the future.
if (tileEntity instanceof TileEntityTesla)
{
return ((TileEntityTesla) tileEntity).getEnergyStored();
}
return 0;
}
public boolean canUpdate()
public float getDetectedEnergy()
{
return false;
return this.detectedEnergy;
}
public float getAverageDetectedEnergy()
{
return this.detectedAverageEnergy;
}
public void toggleMode()
{
this.detectMode = DetectMode.values()[(this.detectMode.ordinal() + 1) % DetectMode.values().length];
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.detectMode = DetectMode.values()[nbt.getInteger("detectMode")];
this.energyLimit = nbt.getFloat("energyLimit");
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("detectMode", this.detectMode.ordinal());
nbt.setFloat("energyLimit", this.energyLimit);
}
public DetectMode getMode()
{
return this.detectMode;
}
public float getLimit()
{
return this.energyLimit;
}
}

View file

@ -0,0 +1,122 @@
package resonantinduction.render;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import resonantinduction.multimeter.TileEntityMultimeter;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Class used to render text onto the multimeter block.
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class RenderMultimeter extends TileEntitySpecialRenderer
{
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float var8)
{
TileEntityMultimeter tileEntity = (TileEntityMultimeter) t;
ForgeDirection direction = ForgeDirection.getOrientation(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
/**
* Render from side 2 to 6. This means render all sides excluding top and bottom.
*/
for (int side = 0; side < 6; side++)
{
if (direction.ordinal() != side)
{
GL11.glPushMatrix();
GL11.glPolygonOffset(-10, -10);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
float dx = 1F / 16;
float dz = 1F / 16;
float displayWidth = 1 - 2F / 16;
float displayHeight = 1 - 2F / 16;
GL11.glTranslatef((float) x, (float) y, (float) z);
switch (side)
{
case 1:
break;
case 0:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(180, 1, 0, 0);
GL11.glRotatef(180, 0, 1, 0);
break;
case 3:
GL11.glTranslatef(0, 1, 0);
GL11.glRotatef(0, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
case 2:
GL11.glTranslatef(1, 1, 1);
GL11.glRotatef(180, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
case 5:
GL11.glTranslatef(0, 1, 1);
GL11.glRotatef(90, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
case 4:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(-90, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
}
GL11.glTranslatef(dx + displayWidth / 2, 1F, dz + displayHeight / 2);
GL11.glRotatef(-90, 1, 0, 0);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
FontRenderer fontRenderer = this.getFontRenderer();
String joules = Math.round(tileEntity.getDetectedEnergy()) + " J";
int stringWidth = Math.max(fontRenderer.getStringWidth(joules), 0);
// maxWidth += 8;
int lineHeight = fontRenderer.FONT_HEIGHT + 2;
int requiredHeight = lineHeight * 1;
/**
* Create an average scale.
*/
float scaleX = displayWidth / stringWidth;
float scaleY = displayHeight / requiredHeight;
float scale = (float) (Math.min(scaleX, scaleY) * 0.8);
GL11.glScalef(scale, -scale, scale);
GL11.glDepthMask(false);
int realHeight = (int) Math.floor(displayHeight / scale);
int realWidth = (int) Math.floor(displayWidth / scale);
int offsetY = (realHeight - requiredHeight) / 2;
int offsetX = (realWidth - stringWidth) / 2;
GL11.glDisable(GL11.GL_LIGHTING);
fontRenderer.drawString(joules, offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 0 * lineHeight, 1);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDepthMask(true);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
GL11.glPopMatrix();
}
}
}
}

View file

@ -339,7 +339,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
public int getRange()
{
return Math.min(5 * (this.getHeight() - 1), 50);
return Math.min(4 * (this.getHeight() - 1), 50);
}
public void updatePositionStatus()