diff --git a/README.md b/README.md index 75a3acbd..b3bbb366 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,4 @@ In order to compile the source code into binary form, you must have a working Mi 5. Install it into Minecraft just like any other Forge mod. ### License -"Resonant Induction" is under the Calclavia Mod License (http://calclavia.com/license/cl). +"Resonant Induction" is under the Educational Public License (http://calclavia.com/license/rpl). diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 0791949c..414371fd 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -197,9 +197,26 @@ public class ResonantInduction /** * Recipes */ - /** by Jyzarc */ - GameRegistry.addRecipe(new ShapedOreRecipe(blockTesla, "EEE", " C ", " I ", 'E', Item.eyeOfEnder, 'C', Item.redstone, 'I', Block.blockIron)); + /** Capacitor **/ + GameRegistry.addRecipe(new ShapedOreRecipe(itemCapacitor, "RRR", "RIR", "RRR", 'R', Item.redstone, 'I', Item.ingotIron)); + /** Linker **/ + GameRegistry.addRecipe(new ShapedOreRecipe(itemLinker, " E ", "GCG", " E ", 'E', Item.eyeOfEnder, 'C', itemCapacitor, 'G', Item.ingotGold)); + + /** Quantum Entangler **/ + GameRegistry.addRecipe(new ShapedOreRecipe(itemQuantumEntangler, "EEE", "ILI", "EEE", 'E', Item.eyeOfEnder, 'L', itemLinker, 'I', Item.ingotIron)); + + /** Tesla - by Jyzarc */ + GameRegistry.addRecipe(new ShapedOreRecipe(blockTesla, "EEE", " C ", " I ", 'E', Item.eyeOfEnder, 'C', itemCapacitor, 'I', Block.blockIron)); + + /** Multimeter */ + GameRegistry.addRecipe(new ShapedOreRecipe(blockMultimeter, "RRR", "ICI", "III", 'R', Item.redstone, 'C', itemCapacitor, 'I', Item.ingotIron)); + + /** Multimeter */ + GameRegistry.addRecipe(new ShapedOreRecipe(blockBattery, "III", "IRI", "III", 'R', Block.blockRedstone, 'I', Item.ingotIron)); + + /** EM Contractor */ + GameRegistry.addRecipe(new ShapedOreRecipe(blockEMContractor, " I ", "GCG", "WWW", 'W', Block.wood, 'C', itemCapacitor, 'G', Item.ingotGold, 'I', Item.ingotIron)); } public static int loadLanguages(String languagePath, String[] languageSupported) diff --git a/src/resonantinduction/base/Vector3.java b/src/resonantinduction/base/Vector3.java index 8a3d6f82..2434386b 100644 --- a/src/resonantinduction/base/Vector3.java +++ b/src/resonantinduction/base/Vector3.java @@ -248,7 +248,7 @@ public class Vector3 { MovingObjectPosition pickedEntity = null; Vec3 startingPosition = this.toVec3(); - Vec3 look = target.normalize().toVec3(); + Vec3 look = target.clone().difference(this).normalize().toVec3(); double reachDistance = this.distance(target); Vec3 reachPoint = Vec3.createVectorHelper(startingPosition.xCoord + look.xCoord * reachDistance, startingPosition.yCoord + look.yCoord * reachDistance, startingPosition.zCoord + look.zCoord * reachDistance); diff --git a/src/resonantinduction/battery/ItemCapacitor.java b/src/resonantinduction/battery/ItemCapacitor.java index cb1883d6..214a40dd 100644 --- a/src/resonantinduction/battery/ItemCapacitor.java +++ b/src/resonantinduction/battery/ItemCapacitor.java @@ -3,6 +3,10 @@ */ package resonantinduction.battery; +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import resonantinduction.api.IBattery; @@ -23,6 +27,13 @@ public class ItemCapacitor extends ItemBase implements IBattery this.setMaxDamage(1000); } + @Override + public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + double energyStored = this.getEnergyStored(itemStack); + par3List.add("Energy: " + energyStored + " J"); + } + @Override public void setEnergyStored(ItemStack itemStack, float amount) { @@ -31,6 +42,7 @@ public class ItemCapacitor extends ItemBase implements IBattery itemStack.setTagCompound(new NBTTagCompound()); } itemStack.getTagCompound().setFloat("energyStored", amount); + itemStack.setItemDamage((int) (amount / this.getMaxEnergyStored())); } @Override @@ -48,4 +60,16 @@ public class ItemCapacitor extends ItemBase implements IBattery { return 100; } + + @Override + public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) + { + ItemStack chargedStack = new ItemStack(par1, 1, 0); + this.setEnergyStored(chargedStack, this.getMaxEnergyStored()); + par3List.add(chargedStack); + ItemStack unchargedStack = new ItemStack(par1, 1, 0); + this.setEnergyStored(unchargedStack, 0); + par3List.add(unchargedStack); + } + } diff --git a/src/resonantinduction/render/RenderBattery.java b/src/resonantinduction/render/RenderBattery.java index 78c533a4..6be695a6 100644 --- a/src/resonantinduction/render/RenderBattery.java +++ b/src/resonantinduction/render/RenderBattery.java @@ -3,13 +3,27 @@ */ package resonantinduction.render; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Icon; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.ForgeDirection; import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; +import resonantinduction.base.Vector3; import resonantinduction.model.ModelBattery; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -23,16 +37,184 @@ public class RenderBattery extends TileEntitySpecialRenderer { public static final ResourceLocation TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "battery.png"); public static final ModelBattery MODEL = new ModelBattery(); + private EntityItem fakeBattery; + private Random random = new Random(); + protected RenderManager renderManager; @Override public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) { + if (this.fakeBattery == null) + { + this.fakeBattery = new EntityItem(t.worldObj, 0, 0, 0, new ItemStack(ResonantInduction.itemCapacitor)); + this.fakeBattery.age = 10; + } + + if (this.renderManager == null) + { + this.renderManager = RenderManager.instance; + } + GL11.glPushMatrix(); GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); this.func_110628_a(TEXTURE); MODEL.render(0.0625f); GL11.glPopMatrix(); + + int renderAmount = 16; + + itemRender: + for (int i = 2; i < 6; i++) + { + ForgeDirection direction = ForgeDirection.getOrientation(i); + Block block = Block.blocksList[new Vector3(t).translate(new Vector3(direction)).getBlockID(t.worldObj)]; + if (block == null || (block != null && block.isOpaqueCube())) + { + for (int slot = 0; slot < 4; slot++) + { + GL11.glPushMatrix(); + GL11.glTranslatef((float) x + 0.5f, (float) y + 0.7f, (float) z + 0.5f); + + float translateX = 0; + float translateY = 0; + + switch (slot) + { + case 0: + translateX = 0.25f; + break; + case 1: + translateX = 0.25f; + translateY = -0.5f; + break; + case 2: + translateX = -0.25f; + translateY = -0.5f; + break; + case 3: + translateX = -0.25f; + break; + } + + switch (direction) + { + case NORTH: + GL11.glTranslatef(-0.5f, 0, 0); + GL11.glTranslatef(0, translateY, translateX); + GL11.glRotatef(90, 0, 1, 0); + break; + case SOUTH: + GL11.glTranslatef(0, 0, -0.5f); + GL11.glTranslatef(translateX, translateY, 0); + break; + case WEST: + GL11.glTranslatef(0.5f, 0, 0); + GL11.glTranslatef(0, translateY, translateX); + GL11.glRotatef(90, 0, 1, 0); + break; + case EAST: + GL11.glTranslatef(0, 0, 0.5f); + GL11.glTranslatef(translateX, translateY, 0); + break; + } + + GL11.glScalef(0.5f, 0.5f, 0.5f); + this.renderItemSimple(this.fakeBattery); + GL11.glPopMatrix(); + + if (renderAmount-- <= 0) + { + break itemRender; + } + } + } + } } + public void renderItemSimple(EntityItem entityItem) + { + Tessellator tessellator = Tessellator.instance; + ItemStack itemStack = entityItem.getEntityItem(); + + for (int k = 0; k < itemStack.getItem().getRenderPasses(itemStack.getItemDamage()); ++k) + { + Icon icon = itemStack.getItem().getIcon(itemStack, k); + + if (icon == null) + { + TextureManager texturemanager = Minecraft.getMinecraft().func_110434_K(); + ResourceLocation resourcelocation = texturemanager.func_130087_a(entityItem.getEntityItem().getItemSpriteNumber()); + icon = ((TextureMap) texturemanager.func_110581_b(resourcelocation)).func_110572_b("missingno"); + } + + float f4 = ((Icon) icon).getMinU(); + float f5 = ((Icon) icon).getMaxU(); + float f6 = ((Icon) icon).getMinV(); + float f7 = ((Icon) icon).getMaxV(); + float f8 = 1.0F; + float f9 = 0.5F; + float f10 = 0.25F; + float f11; + + GL11.glPushMatrix(); + + float f12 = 0.0625F; + f11 = 0.021875F; + ItemStack itemstack = entityItem.getEntityItem(); + int j = itemstack.stackSize; + byte b0 = getMiniItemCount(itemstack); + + GL11.glTranslatef(-f9, -f10, -((f12 + f11) * (float) b0 / 2.0F)); + + for (int kj = 0; kj < b0; ++kj) + { + // Makes items offset when in 3D, like when in 2D, looks much better. Considered a + // vanilla bug... + if (kj > 0) + { + float x = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + float y = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + float z = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + GL11.glTranslatef(x, y, f12 + f11); + } + else + { + GL11.glTranslatef(0f, 0f, f12 + f11); + } + + if (itemstack.getItemSpriteNumber() == 0) + { + this.func_110776_a(TextureMap.field_110575_b); + } + else + { + this.func_110776_a(TextureMap.field_110576_c); + } + + GL11.glColor4f(1, 1, 1, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, f5, f6, f4, f7, ((Icon) icon).getOriginX(), ((Icon) icon).getOriginY(), f12); + } + + GL11.glPopMatrix(); + } + + } + + protected void func_110776_a(ResourceLocation par1ResourceLocation) + { + this.renderManager.renderEngine.func_110577_a(par1ResourceLocation); + } + + public byte getMiniItemCount(ItemStack stack) + { + byte ret = 1; + if (stack.stackSize > 1) + ret = 2; + if (stack.stackSize > 15) + ret = 3; + if (stack.stackSize > 31) + ret = 4; + return ret; + } } diff --git a/src/resonantinduction/tesla/BlockTesla.java b/src/resonantinduction/tesla/BlockTesla.java index 6ea9848f..78301fe4 100644 --- a/src/resonantinduction/tesla/BlockTesla.java +++ b/src/resonantinduction/tesla/BlockTesla.java @@ -53,16 +53,22 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider { entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1); } + return true; } else if (entityPlayer.getCurrentEquippedItem().itemID == Item.redstone.itemID) { - tileEntity.toggleEntityAttack(); + boolean status = tileEntity.toggleEntityAttack(); if (!entityPlayer.capabilities.isCreativeMode) { entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1); } + + if (!world.isRemote) + { + entityPlayer.addChatMessage("Toggled entity attack to: " + status); + } return true; } else if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemCoordLink)