From 37d9200af28f1f4b5c6b10ed4328877235bbf41f Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 21:16:59 -0400 Subject: [PATCH] Added multimeter detection mechanism --- .../textures/gui/gui_multimeter.png | Bin 0 -> 6115 bytes .../base/TileEntityBase.java | 11 ++ src/resonantinduction/fx/FXElectricBolt.java | 16 +- .../multimeter/BlockMultimeter.java | 98 +++++++++- .../multimeter/ContainerMultimeter.java | 11 ++ .../multimeter/GuiMultimeter.java | 59 +++++- .../multimeter/TileEntityMultimeter.java | 169 +++++++++++++++++- .../tesla/TileEntityTesla.java | 2 +- 8 files changed, 348 insertions(+), 18 deletions(-) create mode 100644 resources/assets/resonantinduction/textures/gui/gui_multimeter.png diff --git a/resources/assets/resonantinduction/textures/gui/gui_multimeter.png b/resources/assets/resonantinduction/textures/gui/gui_multimeter.png new file mode 100644 index 0000000000000000000000000000000000000000..d7719119c5f36ed093cb9a89f1dbb7cbd13ff9c7 GIT binary patch literal 6115 zcma)81yqz>w>~p;BORhc<48(LcXtU$hoppn3?VRpgaT3u3`ip}NGK&eh=kH0T_PYQ z@JR@gclhqT|N8Fz*Inz*TJJjV+H>CL?EO5?-s?Qm*Ht4UW+DavkZGtZ8v+2qzCr*Y zK6bJ6DRsgwMBeJ=z5tMSTs@Ev$?n?#5bL=rDe3FGc=>txx_EiRG?bKJ-acMVt`8po z5HOQ%mVd|s~sv7`ikdov*AS4BX z2C-4M0B$g_?PX^V08deXMs?3r`q%AB$~8EaDb#!EMh*#;a0^1dM+By({5N<8HRx~C zh}l8yGUfR{2BH}6go{vo+wTV;FPRow?f!YdAbI8BpxBFgavQ$QcKk~=d;8^!)uD24 zc>tFDLPsum1!|a(Qus)ZivrFaTo-GSyvIjzPVXt?>pd_13%=rB~Z`htGrrhe{9KCe>zQ}uuBfBUHs@-HE!O483 zRt`A7wYVwG{4n2-0N88x>iEh-h=X*ATpB`L?#i93<#7U}lSaxT0IZcc_>I5R$n_8c zpqv*DuU23_=w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=0L>`# z;(#MBlnP8;;zx#)(?)I9Qks?YM2f$KJS2)kX1ML|@1N+z!_k`gXqs}(!UVEE-s)?V zU}|@#c~|yvxn^gbXy6I;*rF{lGGu4!ox{n`y$9z@iD50F%zquL<_*bRS~kr2kYp zUOo3U!~J9&e6mq8zI(Jm2n7;NKC90c0@qk1BY=G6!jpZS1XcFG-*cYqX-I}+gVw>@ zq9MmiF@9L7EVE@pGIg=`E!Rrt-{_*ZDPqSKzuAuxz7E(xk}w@E_jMrc2ML}ouWCcb z(F>r*mKZyziI8aYy2MY{6206B9r1Z(wX=8@mbA9z7g8K`<7WPaXgJxeIV92X@p9tf zm)lkA)6ThXghMxgnVDHqv%9~)ziE5R>^6FG>lfUXEhl(K0%}VI@t(9oY>d9q3R=&P z5ewPfTkW&(T*GoE`FNA23M!}r@jm{`PGeN&Xs%`>cx@@2|c9@cdLg5|hrN$lHnjWgn$BrPqi_WgTBsoI)l zf9!XGB^Po~+cW6T?!CSD_wLdy)xwGpU+AW0g2dY( z=kvakZU3xifkWTngMY*S&+PvhhRD-nt3r|*T#NPp{X{C``W1YRSIl$y%aUuDW4tLc z_`>j@=WIS3rThP&;GZD>V1^R-VMjLTrKAmaaUN=j{M=}#0<#q;V52npFZwVq=De>Z zp)s{J^fQ0#Ol;2*|E3Gy#LLyWVY~Y70L>M{{|EfP!cZjtl^~1-aKY`LfBXd{jPbg^ z=EDX5`;=+2%U^vw^Yi`vrlzJFmav{{$mZGeqeVS0TeoU(+*kdJ9La$~jd5n+xBTJ8 ys(a`4|3{#IC-5J&|0}uwX_kKr%VYT&4Z{bmW#jYlK3gLI`_oX-RjyRDjrb2|=&Q~E literal 0 HcmV?d00001 diff --git a/src/resonantinduction/base/TileEntityBase.java b/src/resonantinduction/base/TileEntityBase.java index 53d7787e..0a09c75a 100644 --- a/src/resonantinduction/base/TileEntityBase.java +++ b/src/resonantinduction/base/TileEntityBase.java @@ -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 playersUsing = new HashSet(); 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); + } } } diff --git a/src/resonantinduction/fx/FXElectricBolt.java b/src/resonantinduction/fx/FXElectricBolt.java index 7a368689..c8c87146 100644 --- a/src/resonantinduction/fx/FXElectricBolt.java +++ b/src/resonantinduction/fx/FXElectricBolt.java @@ -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); diff --git a/src/resonantinduction/multimeter/BlockMultimeter.java b/src/resonantinduction/multimeter/BlockMultimeter.java index 51efe8d4..4434b3fd 100644 --- a/src/resonantinduction/multimeter/BlockMultimeter.java +++ b/src/resonantinduction/multimeter/BlockMultimeter.java @@ -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,103 @@ 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 - (float) par1) < 2.0F && MathHelper.abs((float) par4EntityLivingBase.posZ - (float) par3) < 2.0F) + { + double d0 = par4EntityLivingBase.posY + 1.82D - (double) par4EntityLivingBase.yOffset; + + if (d0 - (double) par2 > 2.0D) + { + return 1; + } + + if ((double) par2 - d0 > 0.0D) + { + return 0; + } + } + + int l = MathHelper.floor_double((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); + } + + 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 false; + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + @Override public TileEntity createNewTileEntity(World world) { diff --git a/src/resonantinduction/multimeter/ContainerMultimeter.java b/src/resonantinduction/multimeter/ContainerMultimeter.java index df3e66bd..1a24ef17 100644 --- a/src/resonantinduction/multimeter/ContainerMultimeter.java +++ b/src/resonantinduction/multimeter/ContainerMultimeter.java @@ -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 diff --git a/src/resonantinduction/multimeter/GuiMultimeter.java b/src/resonantinduction/multimeter/GuiMultimeter.java index cd6ae138..ec07f9a7 100644 --- a/src/resonantinduction/multimeter/GuiMultimeter.java +++ b/src/resonantinduction/multimeter/GuiMultimeter.java @@ -3,13 +3,17 @@ */ 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 resonantinduction.multimeter.TileEntityMultimeter.DetectMode; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -22,11 +26,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 +40,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) 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 +95,18 @@ 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); } } diff --git a/src/resonantinduction/multimeter/TileEntityMultimeter.java b/src/resonantinduction/multimeter/TileEntityMultimeter.java index 250eccb7..ac64cac3 100644 --- a/src/resonantinduction/multimeter/TileEntityMultimeter.java +++ b/src/resonantinduction/multimeter/TileEntityMultimeter.java @@ -3,21 +3,182 @@ */ 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) + { + 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); + } + } + } + + @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); + + // 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; + } + } diff --git a/src/resonantinduction/tesla/TileEntityTesla.java b/src/resonantinduction/tesla/TileEntityTesla.java index 6572586d..49df6c62 100644 --- a/src/resonantinduction/tesla/TileEntityTesla.java +++ b/src/resonantinduction/tesla/TileEntityTesla.java @@ -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()