From 37d9200af28f1f4b5c6b10ed4328877235bbf41f Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 21:16:59 -0400 Subject: [PATCH 1/6] 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_=wRT*;9u{+o9iGsvlV-)$noi;BBdg+Bl5bB?X9;FiagN+)huvZfv@r` zA{Yag=u~fV{*NXf$Ys1KPV5MCI(S;biEtHq390Q^XJR4t&&}9h5YnTfj#)d@ajD`s zV4q`Y4A``iMb(82pBuwW)LHgqe4r9Bma0w3QoZ0##94HUn$XMe_XaXwN$ZpvOU0R< zsuqw8JNgM_Cer0)4g1tG$;6B0uML;GP|PICD)k6r))@$dKRp!W@9tE5cbAta)uHbl z+gsA|Zl>ycZ*iKR9XbrXL*P<{t6+%4a1n|yyBiAXX4+=DQ|hI#>l`B2W{AXzaGn}` z}z@INM(SQPHu{cOJtpZkmj% zl&d1E_zyDfD3}yx8qSyI8($Mmysuc1UvF4t5K~Gm@;FmsAd*f)>rF+$t1%`QdY2>D zs&&7nYxA#e=%x>wj`nS+t*5W!93V)^qG=<0Vx4&yvls{%oEZ@eRTI9i5a{e{)9I93-K$>S6r`{;R42G=wkE&n#5$^q|Z39%-SfVQq@G*Xt|8& zYg)MpI$M9sh}p=wOsX^n?Of_*ELRk2e*O&Kyi>bVPpQZt@14zZOE-+ffw3llm(`uD zJo<6C=qIjs1Jh6Z;msN6EX{E;=(2nXC1Fir(;CD5mrim7%NdW3U;F72t?`tk?}t8L zpxM3k{T6evh<2mU150;wT6&sUxq7)lx!P8%Smky}c5$mpv-xQ_xk8U7wMU37w9NCO3{q7mlkYs8Yncc3UoU zEPHf&bQf~rbFp%1>1^ukWE$!;7T+qC(w5Th8R#D<7??nbX2}Rm-dW39%bLtuY_Po_ zaG$rnwEn{bjrS|}i_LfHTRfxgOPIegGr4b7qgs(&!8y@f(Ohz^q)|6jw>)RUxwHCL z{pb3!2FB{uDg4>WdXM@LJ7;@(=Z3Dz&YjfO)R3l-gmW1JvY2V|a+donp}w^~G?Mou z7cvK5@5qI89i(jtIGYVo4owL!*Hic1`sA8zlr^U2Oz+(28@V4F_e?9Ik3U_OKa070 zzPEKn)9>(+)l$&tVRlwc*2nGA*{U6}9oL*3!oI_uy-ME4}u3KXla1cl~t(dHCc!NM6+3nKH{+9L0U6x&z7GJotU~bbdj%ny^=+o=; z%CU)BR0?Cibi53@904UrPKYzkvv7rQ3+U-_&=c177jlxb4}QO&-d2duYgC|BNQ|h6 zSna4_b?N@?AG$s(-W&BjUl4PaUokl=3sVMKqA3OZW}%YU5MxvZNMmGVS>+$sD>&f0)M| z8Oc_m$du%yM~Y}xoz!~gP3Ip@{(WyBM7_W0@{DT`xbceMvwKa_TRd|<;(Ep6b>sUy zlW>Cf&JRqT+6SI}kw`1gxjnGmU-M-)N&NM0?&UVsN2;Zi`Zv*9rhF`BKU&|qNxYYS z6gW$~OpA9r`X2sU=?~BA;U439<=dv|m7%R%K|1c?)*W9WI_e$hw9lSb(#+DQ(}qp)%mu76$9R2dN6o#gEi3=j=s4sw>a_7=fiK5` zJPn=xBc0rnY@Wwn{1*8+K5Nl(bT0e3ZPo;0qBHI^{@_&OwB|^z@)>&LIPKKKszTS} z(RL5cD9$+nJ9+(Ny#EIKmYUDjP+b*(q5qxA~WF`r(yT7x0D+jJ@91$%Z z-5`^k@sAIFyF@T{)1SqeMZirlb1zdh%P8~I!rr1uuU~d#VsjzrOl|fi#cL61^FYmg zbaSJP8bTj0?D*;|K7x#OaJW8xY?5;JbGjz$qH}aKg^r&7 z@!pC?VRPtxiO_wyU!SNC@QXic3AC=H{QMY2g5J7MvV+c4eL(0Vj6#JTC5Ekk*$t~o z<<=XulS?hSp*ZX!QXno!E1CVmKK{O$nV`l+deg)>+OUduRfUyAA)BG@XK|JglsC!H@aamb zo`{@W*!kiDxdZL|YD!Z|!09dw$e#Wbe%x#ogcm$BH}@Jpvg0spQV9LbKqvv-&q!Zh_GvOx}l)V|J7OvXuO|MmV15l_N)7!;VV zXWdeVbDT@fQ)6bsK0@?qx{9m17*=O9g3ryEdnf&?a^Ka}ew%z%yHxq2*$n#H8}tth zc%01G3hJAfG`r#anb|oM{yl^qeQ3UkY}TgAnx-a4hPGEVEQSV;O?tJT`wt8al~-=@ z)$K0??{2T-^<4NJtQ)Y%1o_R%HRKF}mno90rQ{0ZbX5vaTLLtC^vjno#Z_{@ryQF8 z{K#sU8{DdDuj~!wOHsQS;->}~79gf|^3f1xEhSYDjYFoAAbr;cH|l3SPe*Kz*9#N< zc3Y1;%d)-N{-~0WkhBmdamf6I!EwuUnw3M8&W;P7&xIH0o6}@+0xo*s)q0pV_*$Z7 zW25b%?edE?%h@Q(`MuCA_E8^aKspqVHkxE?H?xM`BKJ; zUO~VRhhr{zlz0jZ5EwH{oipgR2v1W4xZsW;eFU+_q@fH%+$gsYqYX(KBFsxV@Q9zh zN!G0)4+W^w@q4(HnX0B^x)}UsfZY(20f&gDz!BpcUV>10d}*uRd1Iy)W@s}O&WEXc zFr$nxpQU(avbIUtWM@Gp-bp7p9e!#73Y%@d`ppMG3{pqptG&53za0?s$*^ zjpqgl!4~Y`EyVV+eDi)n^CrWpn-_5b7mOV^7U-5-IQ1JBonNX0Y$6Y?&&rawq~Ex9 zF9x;-qr^7B!lg<+PKwi*Lf#{fs~z&(xC5npM6#OV__VKaU?52Ye7K$I%HUu@qipzj zxdWR;$2dQ3}@6Lom*&CE5~C)F2)teJ(Kz zVj9Md0fz3<8<4BhS?XfKE4xb#f&^WkUa?g^j2q*dQ1}5ICiO>Qb#s9DWD)ndp_2ojlp6yTu?w$blFOpT!9f zpRIJzID)BexDmI&oo^}d5L4oomtVQB+@4RUKo^lILQ7b7mk?{^JR2HG<21Ln2FfXY z3M`xaalk_c^CQ>@!VT)5s>o}%x(n5NoiIG+!-MJ(aDk*}3UCtZu2KU@qJY?If0H7F z7BotYzF_}RkF}n`(>z9DRI{p3eFwzhrK2Sw+m(!UqR>DQ9xQ>RW7`-yhvpl$#Ro-56OF}ebefinb4 zGuEzDK*+7rDh-Wenj%IBunyOTWUAVT=~yuJTbab4(2C<+!}i5;JS8~JNO*f46)5G zKnp1|A|zd>E5`bv;}kO75J>qz2FmGa>?Eme~J-F|J_q5v&Y#DXd-w!qqF={Dl=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() From 50fe6c44d00d5cded1a27e7965df7682e4fddab7 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 21:27:12 -0400 Subject: [PATCH 2/6] Added lightning to EM Contractor --- src/resonantinduction/base/Vector3.java | 2 +- .../contractor/TileEntityEMContractor.java | 518 +++++++++--------- 2 files changed, 266 insertions(+), 254 deletions(-) diff --git a/src/resonantinduction/base/Vector3.java b/src/resonantinduction/base/Vector3.java index 956740e9..35c9d434 100644 --- a/src/resonantinduction/base/Vector3.java +++ b/src/resonantinduction/base/Vector3.java @@ -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); } diff --git a/src/resonantinduction/contractor/TileEntityEMContractor.java b/src/resonantinduction/contractor/TileEntityEMContractor.java index a33a97c3..d33ec6c6 100644 --- a/src/resonantinduction/contractor/TileEntityEMContractor.java +++ b/src/resonantinduction/contractor/TileEntityEMContractor.java @@ -13,17 +13,20 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.ForgeDirection; import resonantinduction.PacketHandler; +import resonantinduction.ResonantInduction; import resonantinduction.api.ITesla; import resonantinduction.base.IPacketReceiver; +import resonantinduction.base.TileEntityBase; +import resonantinduction.base.Vector3; import com.google.common.io.ByteArrayDataInput; /** * * @author AidanBrady - * + * */ -public class TileEntityEMContractor extends TileEntity implements IPacketReceiver, ITesla +public class TileEntityEMContractor extends TileEntityBase implements IPacketReceiver, ITesla { public static int MAX_REACH = 40; public static int PUSH_DELAY = 5; @@ -34,7 +37,7 @@ public class TileEntityEMContractor extends TileEntity implements IPacketReceive private ForgeDirection facing = ForgeDirection.UP; public int pushDelay; - + public float energyStored; public AxisAlignedBB operationBounds; @@ -48,167 +51,171 @@ public class TileEntityEMContractor extends TileEntity implements IPacketReceive @Override public void updateEntity() { - pushDelay = Math.max(0, pushDelay - 1); + super.updateEntity(); + this.pushDelay = Math.max(0, pushDelay - 1); - if (isLatched() && canFunction()) + if (canFunction()) { - TileEntity inventoryTile = getLatched(); - IInventory inventory = (IInventory) inventoryTile; - - if (!suck && pushDelay == 0) + if (isLatched()) { - if (!(inventoryTile instanceof ISidedInventory)) + TileEntity inventoryTile = getLatched(); + IInventory inventory = (IInventory) inventoryTile; + + if (!suck && pushDelay == 0) { - for (int i = inventory.getSizeInventory() - 1; i >= 0; i--) + if (!(inventoryTile instanceof ISidedInventory)) { - if (inventory.getStackInSlot(i) != null) + for (int i = inventory.getSizeInventory() - 1; i >= 0; i--) { - ItemStack toSend = inventory.getStackInSlot(i).copy(); - toSend.stackSize = 1; - - EntityItem item = getItemWithPosition(toSend); - - if (!worldObj.isRemote) + if (inventory.getStackInSlot(i) != null) { - worldObj.spawnEntityInWorld(item); - } - - inventory.decrStackSize(i, 1); - pushDelay = PUSH_DELAY; - - break; - } - } - } - else - { - ISidedInventory sidedInventory = (ISidedInventory) inventoryTile; - int[] slots = sidedInventory.getAccessibleSlotsFromSide(facing.ordinal()); - - if (slots != null) - { - for (int get = slots.length - 1; get >= 0; get--) - { - int slotID = slots[get]; - - if (sidedInventory.getStackInSlot(slotID) != null) - { - ItemStack toSend = sidedInventory.getStackInSlot(slotID); + ItemStack toSend = inventory.getStackInSlot(i).copy(); toSend.stackSize = 1; - if (sidedInventory.canExtractItem(slotID, toSend, facing.ordinal())) + EntityItem item = getItemWithPosition(toSend); + + if (!worldObj.isRemote) { - EntityItem item = getItemWithPosition(toSend); - - if (!worldObj.isRemote) - { - worldObj.spawnEntityInWorld(item); - } - - sidedInventory.decrStackSize(slotID, 1); - pushDelay = PUSH_DELAY; - - break; + worldObj.spawnEntityInWorld(item); } + + inventory.decrStackSize(i, 1); + pushDelay = PUSH_DELAY; + + break; } } } - } - } - else if (suck) - { - if (suckBounds != null) - { - List list = worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds); - - for (EntityItem item : list) + else { - ItemStack itemStack = item.getEntityItem(); + ISidedInventory sidedInventory = (ISidedInventory) inventoryTile; + int[] slots = sidedInventory.getAccessibleSlotsFromSide(facing.ordinal()); - if (!(inventoryTile instanceof ISidedInventory)) + if (slots != null) { - for (int i = 0; i <= inventory.getSizeInventory() - 1; i++) - { - if (inventory.isItemValidForSlot(i, itemStack)) - { - ItemStack inSlot = inventory.getStackInSlot(i); - - if (inSlot == null) - { - inventory.setInventorySlotContents(i, itemStack); - item.setDead(); - break; - } - else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) - { - if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) - { - ItemStack toSet = itemStack.copy(); - toSet.stackSize += inSlot.stackSize; - - inventory.setInventorySlotContents(i, toSet); - item.setDead(); - break; - } - else - { - int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); - - ItemStack toSet = itemStack.copy(); - toSet.stackSize = inSlot.getMaxStackSize(); - - ItemStack remains = itemStack.copy(); - remains.stackSize = rejects; - - inventory.setInventorySlotContents(i, toSet); - item.setEntityItemStack(remains); - } - } - } - } - } - else - { - ISidedInventory sidedInventory = (ISidedInventory) inventoryTile; - int[] slots = sidedInventory.getAccessibleSlotsFromSide(facing.ordinal()); - - for (int get = 0; get <= slots.length - 1; get++) + for (int get = slots.length - 1; get >= 0; get--) { int slotID = slots[get]; - if (sidedInventory.isItemValidForSlot(slotID, itemStack) && sidedInventory.canInsertItem(slotID, itemStack, facing.ordinal())) + if (sidedInventory.getStackInSlot(slotID) != null) { - ItemStack inSlot = inventory.getStackInSlot(slotID); + ItemStack toSend = sidedInventory.getStackInSlot(slotID); + toSend.stackSize = 1; - if (inSlot == null) + if (sidedInventory.canExtractItem(slotID, toSend, facing.ordinal())) { - inventory.setInventorySlotContents(slotID, itemStack); - item.setDead(); + EntityItem item = getItemWithPosition(toSend); + + if (!worldObj.isRemote) + { + worldObj.spawnEntityInWorld(item); + } + + sidedInventory.decrStackSize(slotID, 1); + pushDelay = PUSH_DELAY; + break; } - else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) - { - if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) - { - ItemStack toSet = itemStack.copy(); - toSet.stackSize += inSlot.stackSize; + } + } + } + } + } + else if (suck) + { + if (suckBounds != null) + { + List list = worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds); - inventory.setInventorySlotContents(slotID, toSet); + for (EntityItem item : list) + { + ItemStack itemStack = item.getEntityItem(); + + if (!(inventoryTile instanceof ISidedInventory)) + { + for (int i = 0; i <= inventory.getSizeInventory() - 1; i++) + { + if (inventory.isItemValidForSlot(i, itemStack)) + { + ItemStack inSlot = inventory.getStackInSlot(i); + + if (inSlot == null) + { + inventory.setInventorySlotContents(i, itemStack); item.setDead(); break; } - else + else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) { - int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); + if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) + { + ItemStack toSet = itemStack.copy(); + toSet.stackSize += inSlot.stackSize; - ItemStack toSet = itemStack.copy(); - toSet.stackSize = inSlot.getMaxStackSize(); + inventory.setInventorySlotContents(i, toSet); + item.setDead(); + break; + } + else + { + int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); - ItemStack remains = itemStack.copy(); - remains.stackSize = rejects; + ItemStack toSet = itemStack.copy(); + toSet.stackSize = inSlot.getMaxStackSize(); - inventory.setInventorySlotContents(slotID, toSet); - item.setEntityItemStack(remains); + ItemStack remains = itemStack.copy(); + remains.stackSize = rejects; + + inventory.setInventorySlotContents(i, toSet); + item.setEntityItemStack(remains); + } + } + } + } + } + else + { + ISidedInventory sidedInventory = (ISidedInventory) inventoryTile; + int[] slots = sidedInventory.getAccessibleSlotsFromSide(facing.ordinal()); + + for (int get = 0; get <= slots.length - 1; get++) + { + int slotID = slots[get]; + + if (sidedInventory.isItemValidForSlot(slotID, itemStack) && sidedInventory.canInsertItem(slotID, itemStack, facing.ordinal())) + { + ItemStack inSlot = inventory.getStackInSlot(slotID); + + if (inSlot == null) + { + inventory.setInventorySlotContents(slotID, itemStack); + item.setDead(); + break; + } + else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) + { + if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) + { + ItemStack toSet = itemStack.copy(); + toSet.stackSize += inSlot.stackSize; + + inventory.setInventorySlotContents(slotID, toSet); + item.setDead(); + break; + } + else + { + int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); + + ItemStack toSet = itemStack.copy(); + toSet.stackSize = inSlot.getMaxStackSize(); + + ItemStack remains = itemStack.copy(); + remains.stackSize = rejects; + + inventory.setInventorySlotContents(slotID, toSet); + item.setEntityItemStack(remains); + } } } } @@ -217,142 +224,147 @@ public class TileEntityEMContractor extends TileEntity implements IPacketReceive } } } - } - if (operationBounds != null && canFunction()) - { - List list = worldObj.getEntitiesWithinAABB(Entity.class, operationBounds); - - energyStored -= ENERGY_USAGE; - - for (Entity entity : list) + if (operationBounds != null) { - if (entity instanceof EntityItem) + List list = worldObj.getEntitiesWithinAABB(Entity.class, operationBounds); + + energyStored -= ENERGY_USAGE; + + for (Entity entity : list) { - EntityItem entityItem = (EntityItem) entity; - - switch (facing) + if (entity instanceof EntityItem) { - case DOWN: - if (!worldObj.isRemote) - { - entityItem.setPosition(xCoord + 0.5, entityItem.posY, zCoord + 0.5); - } + EntityItem entityItem = (EntityItem) entity; - entityItem.motionX = 0; - entityItem.motionZ = 0; + if (this.worldObj.isRemote && this.ticks % 5 == 0) + { + ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(entityItem)); + } - if (!suck) - { - entityItem.motionY = Math.max(-MAX_SPEED, entityItem.motionY - ACCELERATION); - } - else - { - entityItem.motionY = Math.min((MAX_SPEED * 4), entityItem.motionY + (ACCELERATION * 5)); - } + switch (facing) + { + case DOWN: + if (!worldObj.isRemote) + { + entityItem.setPosition(xCoord + 0.5, entityItem.posY, zCoord + 0.5); + } - entityItem.isAirBorne = true; - break; - case UP: - if (!worldObj.isRemote) - { - entityItem.setPosition(xCoord + 0.5, entityItem.posY, zCoord + 0.5); - } + entityItem.motionX = 0; + entityItem.motionZ = 0; - entityItem.motionX = 0; - entityItem.motionZ = 0; + if (!suck) + { + entityItem.motionY = Math.max(-MAX_SPEED, entityItem.motionY - ACCELERATION); + } + else + { + entityItem.motionY = Math.min((MAX_SPEED * 4), entityItem.motionY + (ACCELERATION * 5)); + } - if (!suck) - { - entityItem.motionY = Math.min((MAX_SPEED * 4), entityItem.motionY + (ACCELERATION * 5)); - } - else - { - entityItem.motionY = Math.max(-MAX_SPEED, entityItem.motionY - ACCELERATION); - } + entityItem.isAirBorne = true; + break; + case UP: + if (!worldObj.isRemote) + { + entityItem.setPosition(xCoord + 0.5, entityItem.posY, zCoord + 0.5); + } - entityItem.isAirBorne = true; - break; - case NORTH: - if (!worldObj.isRemote) - { - entityItem.setPosition(xCoord + 0.5, yCoord + 0.5, entityItem.posZ); - } + entityItem.motionX = 0; + entityItem.motionZ = 0; - entityItem.motionX = 0; - entityItem.motionY = 0; + if (!suck) + { + entityItem.motionY = Math.min((MAX_SPEED * 4), entityItem.motionY + (ACCELERATION * 5)); + } + else + { + entityItem.motionY = Math.max(-MAX_SPEED, entityItem.motionY - ACCELERATION); + } - if (!suck) - { - entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ - ACCELERATION); - } - else - { - entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ + ACCELERATION); - } + entityItem.isAirBorne = true; + break; + case NORTH: + if (!worldObj.isRemote) + { + entityItem.setPosition(xCoord + 0.5, yCoord + 0.5, entityItem.posZ); + } - entityItem.isAirBorne = true; - break; - case SOUTH: - if (!worldObj.isRemote) - { - entityItem.setPosition(xCoord + 0.5, yCoord + 0.5, entityItem.posZ); - } + entityItem.motionX = 0; + entityItem.motionY = 0; - entityItem.motionX = 0; - entityItem.motionY = 0; + if (!suck) + { + entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ - ACCELERATION); + } + else + { + entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ + ACCELERATION); + } - if (!suck) - { - entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ + ACCELERATION); - } - else - { - entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ - ACCELERATION); - } + entityItem.isAirBorne = true; + break; + case SOUTH: + if (!worldObj.isRemote) + { + entityItem.setPosition(xCoord + 0.5, yCoord + 0.5, entityItem.posZ); + } - entityItem.isAirBorne = true; - break; - case WEST: - if (!worldObj.isRemote) - { - entityItem.setPosition(entityItem.posX, yCoord + 0.5, zCoord + 0.5); - } + entityItem.motionX = 0; + entityItem.motionY = 0; - entityItem.motionY = 0; - entityItem.motionZ = 0; + if (!suck) + { + entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ + ACCELERATION); + } + else + { + entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ - ACCELERATION); + } - if (!suck) - { - entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX - ACCELERATION); - } - else - { - entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX + ACCELERATION); - } + entityItem.isAirBorne = true; + break; + case WEST: + if (!worldObj.isRemote) + { + entityItem.setPosition(entityItem.posX, yCoord + 0.5, zCoord + 0.5); + } - entityItem.isAirBorne = true; - break; - case EAST: - if (!worldObj.isRemote) - { - entityItem.setPosition(entityItem.posX, yCoord + 0.5, zCoord + 0.5); - } + entityItem.motionY = 0; + entityItem.motionZ = 0; - entityItem.motionY = 0; - entityItem.motionZ = 0; + if (!suck) + { + entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX - ACCELERATION); + } + else + { + entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX + ACCELERATION); + } - if (!suck) - { - entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX + ACCELERATION); - } - else - { - entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX - ACCELERATION); - } + entityItem.isAirBorne = true; + break; + case EAST: + if (!worldObj.isRemote) + { + entityItem.setPosition(entityItem.posX, yCoord + 0.5, zCoord + 0.5); + } - entityItem.isAirBorne = true; - break; + entityItem.motionY = 0; + entityItem.motionZ = 0; + + if (!suck) + { + entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX + ACCELERATION); + } + else + { + entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX - ACCELERATION); + } + + entityItem.isAirBorne = true; + break; + } } } } @@ -471,10 +483,10 @@ public class TileEntityEMContractor extends TileEntity implements IPacketReceive updateBounds(); } - + public boolean canFunction() { - return worldObj.getBlockPowerInput(xCoord, yCoord, zCoord) > 0; + return !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord); } @Override @@ -519,20 +531,20 @@ public class TileEntityEMContractor extends TileEntity implements IPacketReceive } @Override - public float transfer(float transferEnergy, boolean doTransfer) + public float transfer(float transferEnergy, boolean doTransfer) { - float energyToUse = Math.min(transferEnergy, ENERGY_USAGE-energyStored); - - if(doTransfer) + float energyToUse = Math.min(transferEnergy, ENERGY_USAGE - energyStored); + + if (doTransfer) { energyStored += energyToUse; } - + return energyToUse; } @Override - public boolean canReceive(TileEntity transferTile) + public boolean canReceive(TileEntity transferTile) { return true; } From f77f7387b733c1b94cfe3465c27aa1e8f9219787 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 21:38:12 -0400 Subject: [PATCH 3/6] Added block rendering for multimeter --- src/resonantinduction/ClientProxy.java | 5 +- src/resonantinduction/ResonantInduction.java | 4 +- .../model/ModelEMContractor.java | 6 +- .../multimeter/BlockMultimeter.java | 11 +- .../multimeter/GuiMultimeter.java | 14 +- .../render/RenderEMContractor.java | 2 +- .../render/RenderMultimeter.java | 122 ++++++++++++++++++ 7 files changed, 143 insertions(+), 21 deletions(-) create mode 100644 src/resonantinduction/render/RenderMultimeter.java diff --git a/src/resonantinduction/ClientProxy.java b/src/resonantinduction/ClientProxy.java index 89f25e70..fd342465 100644 --- a/src/resonantinduction/ClientProxy.java +++ b/src/resonantinduction/ClientProxy.java @@ -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()); } diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index b6dacc3e..5a0df48e 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -116,14 +116,14 @@ public class ResonantInduction 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); diff --git a/src/resonantinduction/model/ModelEMContractor.java b/src/resonantinduction/model/ModelEMContractor.java index 41fe2727..a52f9058 100644 --- a/src/resonantinduction/model/ModelEMContractor.java +++ b/src/resonantinduction/model/ModelEMContractor.java @@ -225,11 +225,11 @@ public class ModelEMContractor extends ModelBase public void render(float f5, boolean rotate) { - if(rotate) + if (rotate) { - teslapole.rotateAngleY = (float)Math.toRadians(Math.toDegrees(teslapole.rotateAngleY)+4 < 360 ? Math.toDegrees(teslapole.rotateAngleY)+4 : 0); + teslapole.rotateAngleY = (float) Math.toRadians(Math.toDegrees(teslapole.rotateAngleY) + 4 < 360 ? Math.toDegrees(teslapole.rotateAngleY) + 4 : 0); } - + frame1.render(f5); frame2.render(f5); frame3.render(f5); diff --git a/src/resonantinduction/multimeter/BlockMultimeter.java b/src/resonantinduction/multimeter/BlockMultimeter.java index 4434b3fd..0f8e3fa6 100644 --- a/src/resonantinduction/multimeter/BlockMultimeter.java +++ b/src/resonantinduction/multimeter/BlockMultimeter.java @@ -35,22 +35,22 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider public static int determineOrientation(World par0World, int par1, int par2, int par3, EntityLivingBase par4EntityLivingBase) { - if (MathHelper.abs((float) par4EntityLivingBase.posX - (float) par1) < 2.0F && MathHelper.abs((float) par4EntityLivingBase.posZ - (float) par3) < 2.0F) + if (MathHelper.abs((float) par4EntityLivingBase.posX - par1) < 2.0F && MathHelper.abs((float) par4EntityLivingBase.posZ - par3) < 2.0F) { - double d0 = par4EntityLivingBase.posY + 1.82D - (double) par4EntityLivingBase.yOffset; + double d0 = par4EntityLivingBase.posY + 1.82D - par4EntityLivingBase.yOffset; - if (d0 - (double) par2 > 2.0D) + if (d0 - par2 > 2.0D) { return 1; } - if ((double) par2 - d0 > 0.0D) + if (par2 - d0 > 0.0D) { return 0; } } - int l = MathHelper.floor_double((double) (par4EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + 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))); } @@ -61,6 +61,7 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider world.setBlockMetadataWithNotify(x, y, z, l, 2); } + @Override public Icon getIcon(int side, int metadata) { if (side == metadata) diff --git a/src/resonantinduction/multimeter/GuiMultimeter.java b/src/resonantinduction/multimeter/GuiMultimeter.java index ec07f9a7..1904d9fb 100644 --- a/src/resonantinduction/multimeter/GuiMultimeter.java +++ b/src/resonantinduction/multimeter/GuiMultimeter.java @@ -13,7 +13,6 @@ 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; @@ -58,7 +57,7 @@ public class GuiMultimeter extends GuiContainer try { - PacketHandler.sendTileEntityPacketToServer(this.tileEntity, (byte) 3, (float) Float.parseFloat(this.textFieldLimit.getText())); + PacketHandler.sendTileEntityPacketToServer(this.tileEntity, (byte) 3, Float.parseFloat(this.textFieldLimit.getText())); } catch (Exception e) { @@ -96,11 +95,12 @@ public class GuiMultimeter extends GuiContainer 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); - }*/ + /* + * 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 diff --git a/src/resonantinduction/render/RenderEMContractor.java b/src/resonantinduction/render/RenderEMContractor.java index 5b538d23..77817494 100644 --- a/src/resonantinduction/render/RenderEMContractor.java +++ b/src/resonantinduction/render/RenderEMContractor.java @@ -58,7 +58,7 @@ public class RenderEMContractor extends TileEntitySpecialRenderer { this.func_110628_a(TEXTURE_PUSH); } - + MODEL.render(0.0625f, true); GL11.glPopMatrix(); diff --git a/src/resonantinduction/render/RenderMultimeter.java b/src/resonantinduction/render/RenderMultimeter.java new file mode 100644 index 00000000..03361a22 --- /dev/null +++ b/src/resonantinduction/render/RenderMultimeter.java @@ -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(); + } + } + } +} \ No newline at end of file From 7eaf73341b49ee7ec0121a32baa0331c53f34c1c Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 22:00:43 -0400 Subject: [PATCH 4/6] Added handheld multimeter reading feature --- src/resonantinduction/ResonantInduction.java | 3 +- .../multimeter/ItemBlockMultimeter.java | 37 +++++++++++++++++++ .../multimeter/TileEntityMultimeter.java | 6 +++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/resonantinduction/multimeter/ItemBlockMultimeter.java diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 5a0df48e..98c66726 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -14,6 +14,7 @@ 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; @@ -141,7 +142,7 @@ public class ResonantInduction 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()); // Tiles diff --git a/src/resonantinduction/multimeter/ItemBlockMultimeter.java b/src/resonantinduction/multimeter/ItemBlockMultimeter.java new file mode 100644 index 00000000..fa76cbef --- /dev/null +++ b/src/resonantinduction/multimeter/ItemBlockMultimeter.java @@ -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); + } +} diff --git a/src/resonantinduction/multimeter/TileEntityMultimeter.java b/src/resonantinduction/multimeter/TileEntityMultimeter.java index ac64cac3..57c6dab0 100644 --- a/src/resonantinduction/multimeter/TileEntityMultimeter.java +++ b/src/resonantinduction/multimeter/TileEntityMultimeter.java @@ -126,11 +126,17 @@ public class TileEntityMultimeter extends TileEntityBase implements IPacketRecei 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; } From ee2dc8024866f077cc3a44228de95b5a07d39d9e Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 22:14:47 -0400 Subject: [PATCH 5/6] Added modular battery --- .../languages/en_US.properties | 1 + src/resonantinduction/ResonantInduction.java | 6 + .../battery/BatteryController.java | 23 +++ .../battery/BlockBattery.java | 81 +++++++++ .../battery/TileEntityBattery.java | 167 ++++++++++++++++++ .../multimeter/BlockMultimeter.java | 2 +- .../multimeter/TileEntityMultimeter.java | 6 + 7 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 src/resonantinduction/battery/BatteryController.java create mode 100644 src/resonantinduction/battery/BlockBattery.java create mode 100644 src/resonantinduction/battery/TileEntityBattery.java diff --git a/resources/assets/resonantinduction/languages/en_US.properties b/resources/assets/resonantinduction/languages/en_US.properties index b7706359..aef4675f 100755 --- a/resources/assets/resonantinduction/languages/en_US.properties +++ b/resources/assets/resonantinduction/languages/en_US.properties @@ -6,6 +6,7 @@ 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 \ No newline at end of file diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 98c66726..06f63da0 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -9,6 +9,8 @@ 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.TileEntityBattery; import resonantinduction.contractor.BlockEMContractor; import resonantinduction.contractor.ItemBlockContractor; import resonantinduction.contractor.TileEntityEMContractor; @@ -112,6 +114,7 @@ public class ResonantInduction public static Block blockTesla; public static Block blockMultimeter; public static Block blockEMContractor; + public static Block blockBattery; @EventHandler public void preInit(FMLPreInitializationEvent evt) @@ -138,17 +141,20 @@ public class ResonantInduction 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, 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(); diff --git a/src/resonantinduction/battery/BatteryController.java b/src/resonantinduction/battery/BatteryController.java new file mode 100644 index 00000000..4eebb9e3 --- /dev/null +++ b/src/resonantinduction/battery/BatteryController.java @@ -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 connectedBlocks = new HashSet(); + + public void update() + { + + } +} diff --git a/src/resonantinduction/battery/BlockBattery.java b/src/resonantinduction/battery/BlockBattery.java new file mode 100644 index 00000000..2b20ad1c --- /dev/null +++ b/src/resonantinduction/battery/BlockBattery.java @@ -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(); + } +} diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java new file mode 100644 index 00000000..c4b7f13e --- /dev/null +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -0,0 +1,167 @@ +/** + * + */ +package resonantinduction.battery; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +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() + { + + + + return 0; + } + + /** + * 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; + } +} diff --git a/src/resonantinduction/multimeter/BlockMultimeter.java b/src/resonantinduction/multimeter/BlockMultimeter.java index 0f8e3fa6..48cb2c6e 100644 --- a/src/resonantinduction/multimeter/BlockMultimeter.java +++ b/src/resonantinduction/multimeter/BlockMultimeter.java @@ -115,7 +115,7 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider @Override public boolean canProvidePower() { - return false; + return true; } @Override diff --git a/src/resonantinduction/multimeter/TileEntityMultimeter.java b/src/resonantinduction/multimeter/TileEntityMultimeter.java index 57c6dab0..cf9f0ebe 100644 --- a/src/resonantinduction/multimeter/TileEntityMultimeter.java +++ b/src/resonantinduction/multimeter/TileEntityMultimeter.java @@ -49,6 +49,7 @@ public class TileEntityMultimeter extends TileEntityBase implements IPacketRecei if (this.ticks % 20 == 0) { + float prevDetectedEnergy = this.detectedEnergy; this.detectedEnergy = this.doGetDetectedEnergy(); this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2; @@ -80,6 +81,11 @@ public class TileEntityMultimeter extends TileEntityBase implements IPacketRecei 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); } + */ } } From f6ab9e1f9b9828d729c5145407d32ce29d5d1c4b Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 22:23:06 -0400 Subject: [PATCH 6/6] Added capacitor --- .../languages/en_US.properties | 3 ++- .../textures/items/capacitor.png | Bin 0 -> 930 bytes src/resonantinduction/ResonantInduction.java | 5 ++++ src/resonantinduction/api/IBattery.java | 15 ++++++++++++ .../battery/ItemCapacitor.java | 23 ++++++++++++++++++ .../battery/TileEntityBattery.java | 23 ++++++++++++++---- 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 resources/assets/resonantinduction/textures/items/capacitor.png create mode 100644 src/resonantinduction/api/IBattery.java create mode 100644 src/resonantinduction/battery/ItemCapacitor.java diff --git a/resources/assets/resonantinduction/languages/en_US.properties b/resources/assets/resonantinduction/languages/en_US.properties index aef4675f..cdeeb1a7 100755 --- a/resources/assets/resonantinduction/languages/en_US.properties +++ b/resources/assets/resonantinduction/languages/en_US.properties @@ -9,4 +9,5 @@ tile.resonantinduction\:contractor.name=Electromagnetic Contractor tile.resonantinduction\:battery.name=Modular Battery ## Items -item.resonantinduction\:quantumEntangler.name=Quantum Entangler \ No newline at end of file +item.resonantinduction\:quantumEntangler.name=Quantum Entangler +item.resonantinduction\:capacitor.name=Capacitor Cell diff --git a/resources/assets/resonantinduction/textures/items/capacitor.png b/resources/assets/resonantinduction/textures/items/capacitor.png new file mode 100644 index 0000000000000000000000000000000000000000..181019ec3d217a17833cf7cfe74e0d185fa849b8 GIT binary patch literal 930 zcmV;T16}-yP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0009KNklJEN`OJoqz#X9fNr1q?G^8M>0SyH4$+RX}Zcb8~~Mt1BVV zEV$T7J3BZ$JVd=-$LZ-Q8jXgQL{ke$V0wC5013>{ zSwIpDs&Q~|;G6&zSXfwi0FD>&*7F@kq<|OQUtpw9(9t~xBb3K$*H>%Z?(VLrqDx$@ z0-;byJm*I5KE+`~i+KMz0VC5e-(xVo70}@d!k9Wi*VrPA>>pW6D_Wv}-|x4i@AUpO z0UCJK6EII+N2l)>j2~5#koo&m4R73G^SvwtXhE%3bFKghL?V#~3w~GdaV!HPSw+{V zdE(q(eDJ4COGMUtddeqAh$T5zeX87mGz~Zf-g!FfcHHk&zKmAel@G z34#%vN>CA!ASphxJFc&ef5 zA<&W}bi3W~csv*$9>(P4q~$+lCjo-;nF^@y1XW-OvKcv6fEM)i^?~I`8{+Y}rNZMx zRNo4YOxEM$V;mhFIVaHD+Y6V=1uDU042Q!=rBXsdRRr@vslkzXLJJ&!3*_EzHXcQS zJ%QE0&Zrs_i4gR0kPxduC%>)#1*-Gi-QD5x@>1Igl`VF!X4)&6QsMmk93;`~RGhoG zxR8plb9!3}SeM6kT}pL#MyK<(EN}|a^xnxy)3dh4KO+hRF|D0aga7~l07*qoM6N<$ Ef`)ID3jhEB literal 0 HcmV?d00001 diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 06f63da0..93fae1de 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -10,6 +10,7 @@ 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; @@ -109,6 +110,7 @@ public class ResonantInduction // Items public static Item itemQuantumEntangler; + public static Item itemCapacitor; // Blocks public static Block blockTesla; @@ -135,7 +137,10 @@ 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()); diff --git a/src/resonantinduction/api/IBattery.java b/src/resonantinduction/api/IBattery.java new file mode 100644 index 00000000..714324f3 --- /dev/null +++ b/src/resonantinduction/api/IBattery.java @@ -0,0 +1,15 @@ +/** + * + */ +package resonantinduction.api; + +/** + * @author Calclavia + * + */ +public interface IBattery +{ + public float getEnergyStored(); + + public float getMaxEnergyStored(); +} diff --git a/src/resonantinduction/battery/ItemCapacitor.java b/src/resonantinduction/battery/ItemCapacitor.java new file mode 100644 index 00000000..04ed4ae0 --- /dev/null +++ b/src/resonantinduction/battery/ItemCapacitor.java @@ -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); + } + +} diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index c4b7f13e..ef14f874 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -6,6 +6,7 @@ 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; /** @@ -18,7 +19,7 @@ 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. + // TODO: Multiblock power storage. private BatteryController controller; @Override @@ -29,10 +30,22 @@ public class TileEntityBattery extends TileEntityBase implements IInventory public float getMaxEnergyStored() { - - - - return 0; + 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; } /**