diff --git a/resources/assets/enderio/lang/en_US.lang b/resources/assets/enderio/lang/en_US.lang index 7c2c85e5..495f90d9 100644 --- a/resources/assets/enderio/lang/en_US.lang +++ b/resources/assets/enderio/lang/en_US.lang @@ -368,6 +368,12 @@ enderio.darksteel.upgrade.glider.tooltip.detailed.line1=Enables gliding enderio.darksteel.upgrade.glider.enabled=Glider Active enderio.darksteel.upgrade.glider.disabled=Glider Disabled +enderio.darksteel.upgrade.sound.name=Sound Locator +enderio.darksteel.upgrade.sound.tooltip.detailed.line1=Displays the location of +enderio.darksteel.upgrade.sound.tooltip.detailed.line2=nearby sounds +enderio.darksteel.upgrade.sound.enabled=Sound Locator Active +enderio.darksteel.upgrade.sound.disabled=Sound Locator Disabled + item.itemGliderWing.name=Glider Wing item.itemGliderWings.name=Glider Wings diff --git a/resources/assets/enderio/textures/gui/widgets.png b/resources/assets/enderio/textures/gui/widgets.png index 258f1f6a..56ac72a6 100644 Binary files a/resources/assets/enderio/textures/gui/widgets.png and b/resources/assets/enderio/textures/gui/widgets.png differ diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 41491f96..c05e5247 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -160,6 +160,19 @@ public final class Config { public static int darkSteelAxePowerUsePerDamagePointMultiHarvest = 1500; public static float darkSteelAxeEffeciencyBoostWhenPowered = 2; public static float darkSteelAxeSpeedPenaltyMultiHarvest = 8; + + public static int darkSteelUpgradeVibrantCost = 20; + public static int darkSteelUpgradePowerOneCost = 10; + public static int darkSteelUpgradePowerTwoCost = 20; + public static int darkSteelUpgradePowerThreeCost = 30; + + public static int darkSteelGliderCost = 15; + public static double darkSteelGliderHorizontalSpeed = 0.03; + public static double darkSteelGliderVerticalSpeed = -0.05; + public static double darkSteelGliderVerticalSpeedSprinting = -0.15; + + public static int darkSteelSoundLocatorCost = 10; + public static int darkSteelSoundLocatorRange = 40; public static int hootchPowerPerCycle = 6; public static int hootchPowerTotalBurnTime = 6000; @@ -181,16 +194,6 @@ public final class Config { public static boolean addFurnaceFuelTootip = true; public static boolean addDurabilityTootip = true; - public static int darkSteelUpgradeVibrantCost = 20; - public static int darkSteelUpgradePowerOneCost = 10; - public static int darkSteelUpgradePowerTwoCost = 20; - public static int darkSteelUpgradePowerThreeCost = 30; - - public static int darkSteelGliderCost = 15; - public static double darkSteelGliderHorizontalSpeed = 0.03; - public static double darkSteelGliderVerticalSpeed = -0.05; - public static double darkSteelGliderVerticalSpeedSprinting = -0.15; - public static float farmContinuousEnergyUse = 4; public static float farmActionEnergyUse = 50; public static int farmDefaultSize = 3; @@ -220,6 +223,8 @@ public final class Config { public static double vacuumChestRange = 6; + + public static void load(FMLPreInitializationEvent event) { FMLCommonHandler.instance().bus().register(new Config()); @@ -451,6 +456,11 @@ public final class Config { darkSteelGliderVerticalSpeedSprinting = config.get(sectionDarkSteel.name, "darkSteelGliderVerticalSpeedSprinting", darkSteelGliderVerticalSpeedSprinting, "Rate of altitude loss when sprinting and gliding.").getDouble(darkSteelGliderVerticalSpeedSprinting); + darkSteelSoundLocatorCost = config.get(sectionDarkSteel.name, "darkSteelSoundLocatorCost", darkSteelSoundLocatorCost, + "Number of levels required for the 'Sound Locator' upgrade.").getInt(darkSteelSoundLocatorCost); + darkSteelSoundLocatorRange = config.get(sectionDarkSteel.name, "darkSteelSoundLocatorRange", darkSteelSoundLocatorRange, + "Range of the 'Sound Locator' upgrade.").getInt(darkSteelSoundLocatorRange); + darkSteelSwordSkullLootingModifier = (float) config.get(sectionDarkSteel.name, "darkSteelSwordSkullLootingModifier", darkSteelSwordSkullLootingModifier, "The chance per looting level that a skull will be dropped when using a powered dark steel sword (0 = no chance, 1 = 100% chance)").getDouble( darkSteelSwordSkullLootingModifier); diff --git a/src/main/java/crazypants/enderio/gui/IconEIO.java b/src/main/java/crazypants/enderio/gui/IconEIO.java index d87c7e66..462e8bc2 100644 --- a/src/main/java/crazypants/enderio/gui/IconEIO.java +++ b/src/main/java/crazypants/enderio/gui/IconEIO.java @@ -76,22 +76,21 @@ public final class IconEIO { public static final IconEIO LOOP = new IconEIO(217, 236, 20, 20); public static final IconEIO LOOP_OFF = new IconEIO(236, 236, 20, 20); - + public static final IconEIO ROUND_ROBIN = new IconEIO(86, 236, 20, 20); public static final IconEIO ROUND_ROBIN_OFF = new IconEIO(106, 236, 20, 20); public static final IconEIO IO_CONFIG_UP = new IconEIO(80, 116, 24, 24); - public static final IconEIO IO_CONFIG_DOWN = new IconEIO(104, 116, 24, 24); + public static final IconEIO IO_CONFIG_DOWN = new IconEIO(104, 116, 24, 24); - public static final IconEIO IO_WHATSIT = new IconEIO(192, 148, 13,13); + public static final IconEIO IO_WHATSIT = new IconEIO(192, 148, 13, 13); - public static final IconEIO RECIPE = new IconEIO(128, 116, 24,24); - - public static final IconEIO ADD_BUT = new IconEIO(139, 246, 10,10); - public static final IconEIO MINUS_BUT = new IconEIO(129, 246, 10,10); - + public static final IconEIO RECIPE = new IconEIO(128, 116, 24, 24); + public static final IconEIO ADD_BUT = new IconEIO(139, 246, 10, 10); + public static final IconEIO MINUS_BUT = new IconEIO(129, 246, 10, 10); + public static final IconEIO SOUND = new IconEIO(209, 172, 22, 22); private static final int TEX_SIZE = 256; private static final double PIX_SIZE = 1d / TEX_SIZE; @@ -131,16 +130,27 @@ public final class IconEIO { } public void renderIcon(double x, double y, double width, double height, double zLevel, boolean doDraw) { + renderIcon(x, y, width, height, zLevel, doDraw, false); + } + + public void renderIcon(double x, double y, double width, double height, double zLevel, boolean doDraw, boolean flipY) { Tessellator tessellator = Tessellator.instance; if(doDraw) { RenderUtil.bindTexture(TEXTURE); tessellator.startDrawingQuads(); } - tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV); - tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV); - tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV); - tessellator.addVertexWithUV(x, y + 0, zLevel, minU, minV); + if(flipY) { + tessellator.addVertexWithUV(x, y + height, zLevel, minU, minV); + tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, minV); + tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, maxV); + tessellator.addVertexWithUV(x, y + 0, zLevel, minU, maxV); + } else { + tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV); + tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV); + tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV); + tessellator.addVertexWithUV(x, y + 0, zLevel, minU, minV); + } if(doDraw) { tessellator.draw(); } diff --git a/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java b/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java index 6b23b873..248f912b 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java +++ b/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java @@ -145,6 +145,15 @@ public class DarkSteelController { } return true; } + + public boolean isSoundDetectorUpgradeEquipped(EntityClientPlayerMP player) { + ItemStack helmet = player.getEquipmentInSlot(4); + SoundDetectorUpgrade upgrade = SoundDetectorUpgrade.loadFromItem(helmet); + if(upgrade == null) { + return false; + } + return true; + } private void updateSword(EntityPlayer player) { if(ItemDarkSteelSword.isEquipped(player)) { diff --git a/src/main/java/crazypants/enderio/item/darksteel/DarkSteelRecipeManager.java b/src/main/java/crazypants/enderio/item/darksteel/DarkSteelRecipeManager.java index 205330b7..ab83e00f 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/DarkSteelRecipeManager.java +++ b/src/main/java/crazypants/enderio/item/darksteel/DarkSteelRecipeManager.java @@ -35,6 +35,7 @@ public class DarkSteelRecipeManager { upgrades.add(SpeedUpgrade.SPEED_TWO); upgrades.add(SpeedUpgrade.SPEED_THREE); upgrades.add(GliderUpgrade.INSTANCE); + upgrades.add(SoundDetectorUpgrade.INSTANCE); } @SubscribeEvent diff --git a/src/main/java/crazypants/enderio/item/darksteel/KeyTracker.java b/src/main/java/crazypants/enderio/item/darksteel/KeyTracker.java index 51e4ff02..5bc6742c 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/KeyTracker.java +++ b/src/main/java/crazypants/enderio/item/darksteel/KeyTracker.java @@ -20,18 +20,45 @@ public class KeyTracker { FMLCommonHandler.instance().bus().register(instance); } - private KeyBinding glideKey; - private boolean wasGlideKeyPressed = false; - + private KeyBinding glideKey; private boolean isGlideActive = false; + private KeyBinding soundDetectorKey; + private boolean isSoundDectorActive = false; + public KeyTracker() { glideKey = new KeyBinding("Glider Toggle", Keyboard.KEY_G, "Dark Steel Armor"); - ClientRegistry.registerKeyBinding(glideKey); + ClientRegistry.registerKeyBinding(glideKey); + soundDetectorKey = new KeyBinding("Sound Locator", Keyboard.KEY_L, "Dark Steel Armor"); + ClientRegistry.registerKeyBinding(soundDetectorKey); } @SubscribeEvent public void onKeyInput(KeyInputEvent event) { + handleGlide(); + handleSoundDetector(); + } + + private void handleSoundDetector() { + if(!DarkSteelController.instance.isSoundDetectorUpgradeEquipped(Minecraft.getMinecraft().thePlayer)) { + SoundDetector.instance.enabled = false; + return; + } + if(soundDetectorKey.getIsKeyPressed()) { + isSoundDectorActive = !isSoundDectorActive; + String message; + if(isSoundDectorActive) { + message = Lang.localize("darksteel.upgrade.sound.enabled"); + } else { + message = Lang.localize("darksteel.upgrade.sound.disabled"); + } + Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new ChatComponentTranslation(message)); + SoundDetector.instance.enabled = isSoundDectorActive; + } + + } + + private void handleGlide() { if(!DarkSteelController.instance.isGliderUpgradeEquipped(Minecraft.getMinecraft().thePlayer)) { return; } diff --git a/src/main/java/crazypants/enderio/item/darksteel/SoundDetector.java b/src/main/java/crazypants/enderio/item/darksteel/SoundDetector.java index 8e935030..50c46a78 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/SoundDetector.java +++ b/src/main/java/crazypants/enderio/item/darksteel/SoundDetector.java @@ -16,9 +16,11 @@ import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; +import net.minecraft.util.Vec3; import net.minecraftforge.client.event.sound.PlaySoundEvent17; import net.minecraftforge.client.event.sound.PlaySoundSourceEvent; import net.minecraftforge.client.event.sound.SoundEvent; @@ -30,6 +32,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import crazypants.enderio.config.Config; import crazypants.render.BoundingBox; import crazypants.render.CubeRenderer; import crazypants.render.IconUtil; @@ -53,13 +56,24 @@ public class SoundDetector { boolean enabled = false; + double maxRangeSq = Config.darkSteelSoundLocatorRange * Config.darkSteelSoundLocatorRange; + @SubscribeEvent public void onSound(PlaySoundAtEntityEvent evt) { if(enabled && evt.entity != null && evt.entity != Minecraft.getMinecraft().thePlayer) { synchronized (soundQueue) { - soundQueue.add(new SoundSource(evt.entity)); + soundQueue.add(new SoundSource(evt.entity, evt.volume)); } - } + } + } + + @SubscribeEvent + public void onSound(PlaySoundSourceEvent evt) { + if(enabled) { + synchronized (soundQueue) { + soundQueue.add(new SoundSource(evt.sound.getXPosF(),evt.sound.getYPosF(),evt.sound.getZPosF(), evt.sound.getVolume())); + } + } } @SideOnly(Side.CLIENT) @@ -74,31 +88,38 @@ public class SoundDetector { sounds.addAll(soundQueue); soundQueue.clear(); } - + if(mc.thePlayer == null || mc.thePlayer.worldObj == null) { return; } - + Vector3d eye = Util.getEyePositionEio(mc.thePlayer); for(SoundSource ss : sounds) { - mc.thePlayer.worldObj.spawnEntityInWorld(new SoundEntity(mc.thePlayer.worldObj, ss.pos)); + if(ss.pos.distanceSquared(eye) <= maxRangeSq) { + mc.thePlayer.worldObj.spawnEntityInWorld(new SoundEntity(mc.thePlayer.worldObj, ss.pos, ss.volume)); + } } sounds.clear(); } private static class SoundSource { - - int expiresTicks; + Vector3d pos; + float volume; - public SoundSource(Entity ent) { + public SoundSource(Entity ent, float volume) { AxisAlignedBB bb = ent.boundingBox; if(bb != null) { pos = new Vector3d(bb.minX + (bb.maxX - bb.minX)/2, bb.minY + (bb.maxY - bb.minY)/2,bb.minZ + (bb.maxZ - bb.minZ)/2); } else { pos = new Vector3d(ent.posX, ent.posY,ent.posZ); - } - expiresTicks = 40; + } + this.volume = volume; + } + + public SoundSource(double x, double y, double z, float volume) { + pos = new Vector3d(x,y,z); + this.volume = volume; } } diff --git a/src/main/java/crazypants/enderio/item/darksteel/SoundDetectorUpgrade.java b/src/main/java/crazypants/enderio/item/darksteel/SoundDetectorUpgrade.java new file mode 100644 index 00000000..c2b92f9f --- /dev/null +++ b/src/main/java/crazypants/enderio/item/darksteel/SoundDetectorUpgrade.java @@ -0,0 +1,52 @@ +package crazypants.enderio.item.darksteel; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import crazypants.enderio.EnderIO; +import crazypants.enderio.config.Config; + +public class SoundDetectorUpgrade extends AbstractUpgrade { + + private static String UPGRADE_NAME = "soundDetector"; + + public static final SoundDetectorUpgrade INSTANCE = new SoundDetectorUpgrade(); + + public static SoundDetectorUpgrade loadFromItem(ItemStack stack) { + if(stack == null) { + return null; + } + if(stack.stackTagCompound == null) { + return null; + } + if(!stack.stackTagCompound.hasKey(KEY_UPGRADE_PREFIX + UPGRADE_NAME)) { + return null; + } + return new SoundDetectorUpgrade((NBTTagCompound) stack.stackTagCompound.getTag(KEY_UPGRADE_PREFIX + UPGRADE_NAME)); + } + + + public SoundDetectorUpgrade(NBTTagCompound tag) { + super(UPGRADE_NAME, tag); + } + + public SoundDetectorUpgrade() { + super(UPGRADE_NAME, "enderio.darksteel.upgrade.sound", new ItemStack(Blocks.noteblock), Config.darkSteelSoundLocatorCost); + } + + @Override + public boolean canAddToItem(ItemStack stack) { + if(stack == null || stack.getItem() != EnderIO.itemDarkSteelHelmet) { + return false; + } + SoundDetectorUpgrade up = loadFromItem(stack); + if(up == null) { + return true; + } + return false; + } + + @Override + public void writeUpgradeToNBT(NBTTagCompound upgradeRoot) { + } +} \ No newline at end of file diff --git a/src/main/java/crazypants/enderio/item/darksteel/SoundEntity.java b/src/main/java/crazypants/enderio/item/darksteel/SoundEntity.java index 2436fb0f..801fade7 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/SoundEntity.java +++ b/src/main/java/crazypants/enderio/item/darksteel/SoundEntity.java @@ -9,10 +9,12 @@ import net.minecraft.world.World; public class SoundEntity extends Entity { int lifeSpan = 20; + float volume; - public SoundEntity(World world, Vector3d pos) { + public SoundEntity(World world, Vector3d pos, float volume) { super(world); setPosition(pos.x, pos.y, pos.z); + this.volume = volume; } @Override diff --git a/src/main/java/crazypants/enderio/item/darksteel/SoundRenderer.java b/src/main/java/crazypants/enderio/item/darksteel/SoundRenderer.java index 5cdd1956..74c1e885 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/SoundRenderer.java +++ b/src/main/java/crazypants/enderio/item/darksteel/SoundRenderer.java @@ -2,6 +2,7 @@ package crazypants.enderio.item.darksteel; import org.lwjgl.opengl.GL11; +import crazypants.enderio.gui.IconEIO; import crazypants.render.BoundingBox; import crazypants.render.CubeRenderer; import crazypants.render.IconUtil; @@ -22,12 +23,19 @@ public class SoundRenderer extends RenderEntity { public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float p_76986_9_) { + SoundEntity se = ((SoundEntity) entity); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_BLEND); - GL11.glColor4f(1, 1, 1, 0.5f); + + //float alpha = Math.min(1, se.volume) * 0.5f; + float alpha = 0.5f; + + GL11.glColor4f(1, 1, 1, alpha); - float scale = ((SoundEntity) entity).lifeSpan / 20f; + float scale = se.lifeSpan / 20f; EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; GL11.glPushMatrix(); @@ -35,27 +43,9 @@ public class SoundRenderer extends RenderEntity { GL11.glRotatef(-player.rotationYaw, 0.0F, 1.0F, 0.0F); GL11.glRotatef(player.rotationPitch, 1.0F, 0.0F, 0.0F); - GL11.glPushMatrix(); - GL11.glRotatef(-90, 1, 0, 0); + double size = 0.5 * se.lifeSpan / 20f; - RenderUtil.bindBlockTexture(); - IIcon tex = IconUtil.whiteTexture; - double size = 0.25; - - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(-size, 0, size, tex.getMinU(), tex.getMinV()); - tessellator.addVertexWithUV(-size, 0, -size, tex.getMinU(), tex.getMaxV()); - tessellator.addVertexWithUV(size, 0, -size, tex.getMaxU(), tex.getMaxV()); - tessellator.addVertexWithUV(size, 0, size, tex.getMaxU(), tex.getMinV()); - - tessellator.addVertexWithUV(-size, 0, size, tex.getMinU(), tex.getMinV()); - tessellator.addVertexWithUV(size, 0, size, tex.getMaxU(), tex.getMinV()); - tessellator.addVertexWithUV(size, 0, -size, tex.getMaxU(), tex.getMaxV()); - tessellator.addVertexWithUV(-size, 0, -size, tex.getMinU(), tex.getMaxV()); - tessellator.draw(); - - GL11.glPopMatrix(); + IconEIO.SOUND.renderIcon(-size/2, -size/2, size,size,0,true,true); GL11.glPopAttrib(); GL11.glPopMatrix();