diff --git a/mods/eln/Eln.java b/mods/eln/Eln.java index 0766c8c63..bdd15efe2 100644 --- a/mods/eln/Eln.java +++ b/mods/eln/Eln.java @@ -1176,7 +1176,7 @@ void registerBattery(int id) { double stdU = LVU; double stdP = LVP / 4; double stdHalfLife = Utils.minecraftDay * 2; - double stdEfficiency = 1.0 - 4.0 / 50.0; + double stdEfficiency = 1.0 - 2.0 / 50.0; double condoEfficiency = 1.0 - 2.0 / 50.0; batteryVoltageFunctionTable = voltageFunction; diff --git a/mods/eln/PacketHandler.java b/mods/eln/PacketHandler.java index d317ea860..de22c7670 100644 --- a/mods/eln/PacketHandler.java +++ b/mods/eln/PacketHandler.java @@ -23,6 +23,7 @@ import mods.eln.node.NodeBlockEntity; import mods.eln.node.NodeManager; import mods.eln.sound.SoundClient; +import mods.eln.sound.SoundParam; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.entity.player.EntityPlayer; @@ -120,16 +121,8 @@ void packetPlaySound(DataInputStream stream, NetworkManager manager, if (stream.readByte() != clientPlayer.dimension) return; - SoundClient.play( - clientPlayer.worldObj, - stream.readInt() / 8.0, - stream.readInt() / 8.0, - stream.readInt() / 8.0, - stream.readUTF(), - stream.readFloat(), - stream.readFloat(), - stream.readFloat(), - stream.readFloat()); + + SoundClient.play(SoundParam.fromStream(stream,clientPlayer.worldObj)); } catch (IOException e) { // TODO Auto-generated catch block diff --git a/mods/eln/electricalalarm/ElectricalAlarmSlowProcess.java b/mods/eln/electricalalarm/ElectricalAlarmSlowProcess.java index 3f9415705..3c5ebe6dc 100644 --- a/mods/eln/electricalalarm/ElectricalAlarmSlowProcess.java +++ b/mods/eln/electricalalarm/ElectricalAlarmSlowProcess.java @@ -3,6 +3,8 @@ import mods.eln.Eln; import mods.eln.misc.Coordonate; import mods.eln.sim.IProcess; +import mods.eln.sound.SoundParam; +import mods.eln.sound.SoundServer; public class ElectricalAlarmSlowProcess implements IProcess { @@ -27,7 +29,7 @@ public void process(double time) { if(soundTimeTimeout == 0) { float speed = 1f; Coordonate coord = element.sixNode.coordonate; - coord.world().playSoundEffect(coord.x, coord.y, coord.z, element.descriptor.soundName, element.descriptor.soundLevel, speed); + SoundServer.play(new SoundParam(element.descriptor.soundName,coord).setVolume(1F, 1.0F).longRange()); soundTimeTimeout = element.descriptor.soundTime; } } diff --git a/mods/eln/electricalbreaker/ElectricalBreakerElement.java b/mods/eln/electricalbreaker/ElectricalBreakerElement.java index 52f4214b8..fd267975f 100644 --- a/mods/eln/electricalbreaker/ElectricalBreakerElement.java +++ b/mods/eln/electricalbreaker/ElectricalBreakerElement.java @@ -36,6 +36,8 @@ import mods.eln.sim.ITemperatureWatchdogDescriptor; import mods.eln.sim.IVoltageWatchdogDescriptor; import mods.eln.sim.ThermalLoad; +import mods.eln.sound.SoundParam; +import mods.eln.sound.SoundServer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; @@ -145,7 +147,7 @@ public void networkSerialize(DataOutputStream stream) { public void setSwitchState(boolean state) { if(state == switchState) return; - playSoundEffect("random.click", 0.3F, 0.6F); + SoundServer.play(new SoundParam("random.click",this.getCoordonate()).setVolume(0.3F, 0.6f).smallRange()); switchState = state; refreshSwitchResistor(); needPublish(); diff --git a/mods/eln/electricalgatesource/ElectricalGateSourceElement.java b/mods/eln/electricalgatesource/ElectricalGateSourceElement.java index e2567f8a8..3549fbc35 100644 --- a/mods/eln/electricalgatesource/ElectricalGateSourceElement.java +++ b/mods/eln/electricalgatesource/ElectricalGateSourceElement.java @@ -38,6 +38,8 @@ import mods.eln.sim.ITemperatureWatchdogDescriptor; import mods.eln.sim.IVoltageWatchdogDescriptor; import mods.eln.sim.ThermalLoad; +import mods.eln.sound.SoundParam; +import mods.eln.sound.SoundServer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; @@ -145,7 +147,7 @@ public boolean onBlockActivated(EntityPlayer entityPlayer, Direction side, float } else if(!Utils.playerHasMeter(entityPlayer) && descriptor.onOffOnly) { outputGateProcess.state(!outputGateProcess.getOutputOnOff()); - playSoundEffect("random.click", 0.3F, 0.6F); + SoundServer.play(new SoundParam("random.click",this.getCoordonate()).setVolume(0.3F, 0.6F).smallRange()); needPublish(); return true; } diff --git a/mods/eln/electricalrelay/ElectricalRelayDescriptor.java b/mods/eln/electricalrelay/ElectricalRelayDescriptor.java index f92c6a363..7f7024545 100644 --- a/mods/eln/electricalrelay/ElectricalRelayDescriptor.java +++ b/mods/eln/electricalrelay/ElectricalRelayDescriptor.java @@ -102,6 +102,7 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) { } void draw(float factor) { + //UtilsClient.disableBlend(); UtilsClient.disableCulling(); GL11.glScalef(0.5f, 0.5f, 0.5f); if(main != null) main.draw(); diff --git a/mods/eln/electricalrelay/ElectricalRelayElement.java b/mods/eln/electricalrelay/ElectricalRelayElement.java index f393fdfbc..20f47255c 100644 --- a/mods/eln/electricalrelay/ElectricalRelayElement.java +++ b/mods/eln/electricalrelay/ElectricalRelayElement.java @@ -37,6 +37,8 @@ import mods.eln.sim.ITemperatureWatchdogDescriptor; import mods.eln.sim.IVoltageWatchdogDescriptor; import mods.eln.sim.ThermalLoad; +import mods.eln.sound.SoundParam; +import mods.eln.sound.SoundServer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; @@ -134,7 +136,7 @@ public void setSwitchState(boolean state) { if(state == switchState) return; switchState = state; refreshSwitchResistor(); - playSoundEffect("random.click", 0.1F, 2.0F); + SoundServer.play(new SoundParam("random.click",this.getCoordonate()).setVolume(0.1F, 2.0F).smallRange()); needPublish(); } diff --git a/mods/eln/electricalswitch/ElectricalSwitchElement.java b/mods/eln/electricalswitch/ElectricalSwitchElement.java index 4e916c10c..f73ec4071 100644 --- a/mods/eln/electricalswitch/ElectricalSwitchElement.java +++ b/mods/eln/electricalswitch/ElectricalSwitchElement.java @@ -32,6 +32,7 @@ import mods.eln.sim.ITemperatureWatchdogDescriptor; import mods.eln.sim.IVoltageWatchdogDescriptor; import mods.eln.sim.ThermalLoad; +import mods.eln.sound.SoundParam; import mods.eln.sound.SoundServer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -174,7 +175,7 @@ else if(Eln.multiMeterElement.checkSameItemStack(entityPlayer.getCurrentEquipped else { setSwitchState(! switchState); //playSoundEffect("random.click", 0.3F, 0.6F); - SoundServer.playFromCoord(getCoordonate(),"random.click", 0.3F, 0.6F, 1, 7); + SoundServer.play(new SoundParam("random.click",this.getCoordonate()).setVolume(0.3F, 0.6f).smallRange()); return true; } //front = LRDU.fromInt((front.toInt()+1)&3); diff --git a/mods/eln/misc/Utils.java b/mods/eln/misc/Utils.java index 0943510bd..d775b7740 100644 --- a/mods/eln/misc/Utils.java +++ b/mods/eln/misc/Utils.java @@ -1109,7 +1109,9 @@ public static float traceRay(World w, double posX, double posY, double posZ, dou Block block = Blocks.air; if (w.blockExists(xInt + posXint, yInt + posYint, zInt + posZint)) - w.getBlock(xInt + posXint, yInt + posYint, zInt + posZint); + block = w.getBlock(xInt + posXint, yInt + posYint, zInt + posZint); + + float dToStack; if (d + dBest < rangeMax) diff --git a/mods/eln/misc/UtilsClient.java b/mods/eln/misc/UtilsClient.java index a5b56f3ee..b02766c3b 100644 --- a/mods/eln/misc/UtilsClient.java +++ b/mods/eln/misc/UtilsClient.java @@ -24,6 +24,7 @@ import net.minecraftforge.client.IItemRenderer.ItemRenderType; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; public class UtilsClient { @@ -163,6 +164,54 @@ public static void enableTexture() { GL11.glEnable(GL11.GL_TEXTURE_2D); } + public static void disableLight() { + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + lightmapTexUnitTextureEnable = GL11.glGetBoolean(GL11.GL_TEXTURE_2D); + if (lightmapTexUnitTextureEnable) + GL11.glDisable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + GL11.glDisable(GL11.GL_LIGHTING); + } + + public static void enableLight() { + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + if (lightmapTexUnitTextureEnable) + GL11.glEnable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + GL11.glEnable(GL11.GL_LIGHTING); + } + + public static void enableBlend() { + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glDepthMask(false); + +/* + Utils.println(GL11.glGetInteger(GL14.GL_BLEND_SRC_RGB) + " " + + GL11.glGetInteger(GL14.GL_BLEND_SRC_ALPHA) + " " + + GL11.glGetInteger(GL14.GL_BLEND_DST_RGB) + " " + + GL11.glGetInteger(GL14.GL_BLEND_DST_ALPHA) + " " + + GL11.glIsEnabled(GL11.GL_BLEND));*/ + + //Utils.println(GL11.glGetInteger(GL11.GL_BLEND_SRC) + " " + GL11.glGetInteger(GL11.GL_BLEND_DST) + " " + GL11.glIsEnabled(GL11.GL_BLEND)); + /* GL11.glEnable(2977); + GL11.glEnable(3042);*/ + // OpenGlHelper.glBlendFunc(770, 770, 771, 771); + } + + public static void disableBlend() { + // TODO Auto-generated method stub + GL11.glDepthMask(true); + //GL11.glDisable(GL11.GL_BLEND); + //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + // Utils.println(GL11.glGetInteger(GL11.GL_BLEND_SRC) + " " + GL11.glGetInteger(GL11.GL_BLEND_DST) + " " + GL11.glIsEnabled(GL11.GL_BLEND)); + //GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR); + //GL11.glBlendFunc(1, 1); + //GL11.glDisable(3042); + + //OpenGlHelper.glBlendFunc(1, 1, 1, 1); + } + public static void drawIcon(ItemRenderType type) { if (type == ItemRenderType.INVENTORY) { @@ -222,8 +271,6 @@ public static void drawIcon(ItemRenderType type, ResourceLocation icon) { drawIcon(type); } - - /*public static void drawIcon(ItemRenderType type, Icon icon) { drawIcon(type, icon.getIconName()); }*/ @@ -269,79 +316,50 @@ public static void bindTexture(ResourceLocation ressource) static boolean lightmapTexUnitTextureEnable; - public static void disableLight() { - // TODO Auto-generated method stub - OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); - lightmapTexUnitTextureEnable = GL11.glGetBoolean(GL11.GL_TEXTURE_2D); - if (lightmapTexUnitTextureEnable) - GL11.glDisable(GL11.GL_TEXTURE_2D); - OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); - GL11.glDisable(GL11.GL_LIGHTING); - } - - public static void enableLight() { - // TODO Auto-generated method stub - OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); - if (lightmapTexUnitTextureEnable) - GL11.glEnable(GL11.GL_TEXTURE_2D); - OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); - GL11.glEnable(GL11.GL_LIGHTING); - } - - public static void enableBlend() { - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glDepthMask(false); - - } - - public static void disableBlend() { - // TODO Auto-generated method stub - GL11.glDepthMask(true); - GL11.glDisable(GL11.GL_BLEND); - } - - public static void ledOnOffColor(boolean on) { - if(! on) + if (!on) GL11.glColor3f(0.7f, 0f, 0f); else GL11.glColor3f(0f, 0.7f, 0f); } + public static Color ledOnOffColorC(boolean on) { - if(! on) + if (!on) return new Color(0.7f, 0f, 0f); else return new Color(0f, 0.7f, 0f); } - + public static void drawLight(Obj3DPart part) { - if(part == null) return; + if (part == null) + return; disableLight(); enableBlend(); - + part.draw(); - + enableLight(); disableBlend(); - + } - + public static void drawLightNoBind(Obj3DPart part) { - if(part == null) return; + if (part == null) + return; disableLight(); enableBlend(); - + part.drawNoBind(); - + enableLight(); - disableBlend(); + disableBlend(); } - public static void drawGuiBackground(ResourceLocation ressource,GuiScreen guiScreen,int xSize,int ySize) { + + public static void drawGuiBackground(ResourceLocation ressource, GuiScreen guiScreen, int xSize, int ySize) { bindTexture(ressource); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int x = (guiScreen.width - xSize) / 2; @@ -349,90 +367,94 @@ public static void drawGuiBackground(ResourceLocation ressource,GuiScreen guiScr guiScreen.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); } - public static void drawLight(Obj3DPart part,float angle,float x,float y,float z) + public static void drawLight(Obj3DPart part, float angle, float x, float y, float z) { - if(part == null) return; + if (part == null) + return; disableLight(); enableBlend(); - + part.draw(angle, x, y, z); enableLight(); disableBlend(); - + } + public static void glDefaultColor() { - GL11.glColor4f(1f,1f, 1f, 1f); + GL11.glColor4f(1f, 1f, 1f, 1f); } - - - static public void drawEntityItem(EntityItem entityItem,double x, double y , double z,float roty,float scale) - { - if(entityItem == null) return; - + static public void drawEntityItem(EntityItem entityItem, double x, double y, double z, float roty, float scale) + { + if (entityItem == null) + return; entityItem.hoverStart = 0.0f; entityItem.rotationYaw = 0.0f; entityItem.motionX = 0.0; entityItem.motionY = 0.0; - entityItem.motionZ =0.0; - + entityItem.motionZ = 0.0; + Render var10 = null; var10 = RenderManager.instance.getEntityRenderObject(entityItem); GL11.glPushMatrix(); - GL11.glTranslatef((float)x, (float)y, (float)z); - GL11.glRotatef(roty, 0, 1, 0); - GL11.glScalef(scale, scale, scale); - var10.doRender(entityItem,0, 0, 0, 0, 0); - GL11.glPopMatrix(); - + GL11.glTranslatef((float) x, (float) y, (float) z); + GL11.glRotatef(roty, 0, 1, 0); + GL11.glScalef(scale, scale, scale); + var10.doRender(entityItem, 0, 0, 0, 0, 0); + GL11.glPopMatrix(); } - + protected static RenderItem itemRendererr; - - static RenderItem getItemRender(){ - if(itemRendererr == null){ + + static RenderItem getItemRender() { + if (itemRendererr == null) { itemRendererr = new RenderItem(); } - + return itemRendererr; } - + static Minecraft mc() { return Minecraft.getMinecraft(); } + public static void guiScale() { GL11.glScalef(16f, 16f, 1f); - + + } + + public static void drawItemStack(ItemStack par1ItemStack, int x, int y, String par4Str, boolean gui) + { + RenderItem itemRenderer = getItemRender(); + + // GL11.glTranslatef(0.0F, 0.0F, 32.0F); + + itemRenderer.zLevel = 400.0F; + FontRenderer font = null; + if (par1ItemStack != null) + font = par1ItemStack.getItem().getFontRenderer(par1ItemStack); + if (font == null) + font = mc().fontRenderer; + itemRenderer.renderItemAndEffectIntoGUI(font, mc().getTextureManager(), par1ItemStack, x, y); + itemRenderer.renderItemOverlayIntoGUI(font, mc().getTextureManager(), par1ItemStack, x, y, par4Str); + + itemRenderer.zLevel = 0.0F; + + if (gui) { + GL11.glDisable(GL11.GL_LIGHTING); + } } - public static void drawItemStack(ItemStack par1ItemStack, int x, int y, String par4Str,boolean gui) - { - RenderItem itemRenderer = getItemRender(); - - // GL11.glTranslatef(0.0F, 0.0F, 32.0F); - - itemRenderer.zLevel = 400.0F; - FontRenderer font = null; - if (par1ItemStack != null) font = par1ItemStack.getItem().getFontRenderer(par1ItemStack); - if (font == null) font = mc().fontRenderer; - itemRenderer.renderItemAndEffectIntoGUI(font, mc().getTextureManager(), par1ItemStack, x, y); - itemRenderer.renderItemOverlayIntoGUI(font, mc().getTextureManager(), par1ItemStack, x, y, par4Str); - - itemRenderer.zLevel = 0.0F; - - if(gui){ - GL11.glDisable(GL11.GL_LIGHTING); - } - } public static double clientDistanceTo(Entity e) { - if(e == null) return 100000000.0; + if (e == null) + return 100000000.0; Entity c = Minecraft.getMinecraft().thePlayer; - double x = (c.posX-e.posX),y = (c.posY-e.posY),z = (c.posZ-e.posZ); - return Math.sqrt(x*x+y*y+z*z); + double x = (c.posX - e.posX), y = (c.posY - e.posY), z = (c.posZ - e.posZ); + return Math.sqrt(x * x + y * y + z * z); } public static void disableDepthTest() { @@ -441,8 +463,7 @@ public static void disableDepthTest() { public static void enableDepthTest() { GL11.glEnable(GL11.GL_DEPTH_TEST); - - } + } } diff --git a/mods/eln/node/SixNodeElement.java b/mods/eln/node/SixNodeElement.java index ef14ed594..fce8184ee 100644 --- a/mods/eln/node/SixNodeElement.java +++ b/mods/eln/node/SixNodeElement.java @@ -22,6 +22,7 @@ import mods.eln.sim.IProcess; import mods.eln.sim.ThermalConnection; import mods.eln.sim.ThermalLoad; +import mods.eln.sound.SoundServer; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -59,10 +60,7 @@ protected void inventoryChanged() { } - public void playSoundEffect(String sournd,float strengh,float pitch){ - Coordonate c = getCoordonate(); - c.world().playSoundEffect((double)c.x + 0.5D, (double)c.y + 0.5D, (double)c.z + 0.5D, sournd,strengh, pitch); - } + public Coordonate getCoordonate(){ return sixNode.coordonate; } diff --git a/mods/eln/sound/SoundClient.java b/mods/eln/sound/SoundClient.java index 6b2990e33..f42f7ea07 100644 --- a/mods/eln/sound/SoundClient.java +++ b/mods/eln/sound/SoundClient.java @@ -13,39 +13,39 @@ import net.minecraft.world.World; public class SoundClient { - public static void playFromBlock(World world,int x, int y, int z, String track, float volume, float pitch,float rangeNominal,float rangeMax){ + /*public static void playFromBlock(World world,int x, int y, int z, String track, float volume, float pitch,float rangeNominal,float rangeMax){ play(world, x+0.5, y+0.5, z+0.5, track, volume, pitch, rangeNominal, rangeMax); - } - + }*/ - public static void play(World world,double x, double y, double z, String track, float volume, float pitch,float rangeNominal,float rangeMax){ + public static void play(SoundParam p){ +// public static void play(World world,double x, double y, double z, String track, float volume, float pitch,float rangeNominal,float rangeMax){ EntityPlayer player = Minecraft.getMinecraft().thePlayer; - if(world.provider.dimensionId != player.dimension) return; - double distance = Math.sqrt(Math.pow(x-player.posX, 2) + Math.pow(y-player.posY, 2) + Math.pow(z-player.posZ, 2)); - if(distance >= rangeMax) return; + if(p.world.provider.dimensionId != player.dimension) return; + double distance = Math.sqrt(Math.pow(p.x-player.posX, 2) + Math.pow(p.y-player.posY, 2) + Math.pow(p.z-player.posZ, 2)); + if(distance >= p.rangeMax) return; float distanceFactor = 1; - if(distance > rangeNominal){ - distanceFactor = (float) ((rangeMax - distance)/(rangeMax-rangeNominal)); + if(distance > p.rangeNominal){ + distanceFactor = (float) ((p.rangeMax - distance)/(p.rangeMax-p.rangeNominal)); } - float blockFactor = Utils.traceRay(world, player.posX, player.posY, player.posZ, x, y, z,new Utils.TraceRayWeightOpaque()); + float blockFactor = Utils.traceRay(p.world, player.posX, player.posY, player.posZ, p.x, p.y, p.z,new Utils.TraceRayWeightOpaque())*p.blockFactor; - int trackCount = SoundLoader.getTrackCount(track); + int trackCount = SoundLoader.getTrackCount(p.track); if(trackCount == 1){ - volume -= blockFactor*0.2f; - volume *= distanceFactor; - if(volume <= 0) return; - world.playSound(player.posX + (x-player.posX)/distance, player.posY + (y-player.posY)/distance, player.posZ + (z-player.posZ)/distance, track, volume, pitch, false); + p.volume -= blockFactor*0.2f; + p.volume *= distanceFactor; + if(p.volume <= 0) return; + p.world.playSound(player.posX + (p.x-player.posX)/distance, player.posY + (p.y-player.posY)/distance, player.posZ + (p.z-player.posZ)/distance, p.track,p. volume, p.pitch, false); }else{ for(int idx = 0;idx < trackCount;idx++){ - float bandVolume = volume; + float bandVolume = p.volume; bandVolume *= distanceFactor; - float normalizedBlockFactor = blockFactor*0.5f; + float normalizedBlockFactor = blockFactor; bandVolume -= ((trackCount-1-idx)/(trackCount-1f)+0.2)*normalizedBlockFactor; Utils.print(bandVolume + " "); - world.playSound(player.posX + (x-player.posX)/distance, player.posY + (y-player.posY)/distance, player.posZ + (z-player.posZ)/distance, track + "_" + idx + "x", bandVolume, pitch, false); + p.world.playSound(player.posX + (p.x-player.posX)/distance, player.posY + (p.y-player.posY)/distance, player.posZ + (p.z-player.posZ)/distance, p.track + "_" + idx + "x", bandVolume, p.pitch, false); } Utils.println(""); } diff --git a/mods/eln/sound/SoundServer.java b/mods/eln/sound/SoundServer.java index e82c7ebd3..cab688a09 100644 --- a/mods/eln/sound/SoundServer.java +++ b/mods/eln/sound/SoundServer.java @@ -20,15 +20,19 @@ import net.minecraft.world.World; public class SoundServer { - public static void playFromBlock(World world,int x, int y, int z, String track, float volume, float pitch,float rangeNominal,float rangeMax){ - play(world, x+0.5, y+0.5, z+0.5, track, volume, pitch, rangeNominal, rangeMax); + /*public static void playFromBlock(World world,int x, int y, int z, String track, float volume, float pitch,float rangeNominal,float rangeMax){ + play(world, x+0.5, y+0.5, z+0.5, track, volume, pitch, rangeNominal, rangeMax,1); } public static void playFromCoord(Coordonate c, String track, float volume, float pitch,float rangeNominal,float rangeMax){ - play(c.world(), c.x+0.5, c.y+0.5, c.z+0.5, track, volume, pitch, rangeNominal, rangeMax); + play(c.world(), c.x+0.5, c.y+0.5, c.z+0.5, track, volume, pitch, rangeNominal, rangeMax,1); } + public static void playFromCoord(Coordonate c, String track, float volume, float pitch,float rangeNominal,float rangeMax,float blockFactor){ + play(c.world(), c.x+0.5, c.y+0.5, c.z+0.5, track, volume, pitch, rangeNominal, rangeMax,blockFactor); + }*/ - public static void play(World world,double x, double y, double z, String track, float volume, float pitch,float rangeNominal,float rangeMax){ + + public static void play(SoundParam p){ ByteArrayOutputStream bos = new ByteArrayOutputStream(64); DataOutputStream stream = new DataOutputStream(bos); @@ -37,20 +41,11 @@ public static void play(World world,double x, double y, double z, String track, stream.writeByte(Eln.packetPlaySound); - stream.writeByte(world.provider.dimensionId); - stream.writeInt((int)(x*8)); - stream.writeInt((int)(y*8)); - stream.writeInt((int)(z*8)); - - - stream.writeUTF(track); - stream.writeFloat(volume); - stream.writeFloat(pitch); - stream.writeFloat(rangeNominal); - stream.writeFloat(rangeMax); + stream.writeByte(p.world.provider.dimensionId); + - + p.writeTo(stream); MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); @@ -58,7 +53,7 @@ public static void play(World world,double x, double y, double z, String track, for (Object obj : server.getConfigurationManager().playerEntityList) { EntityPlayerMP player = (EntityPlayerMP) obj; - if(player.dimension == world.provider.dimensionId && player.getDistance(x, y, z) < rangeMax + 2); + if(player.dimension == p.world.provider.dimensionId && player.getDistance(p.x, p.y, p.z) < p.rangeMax + 2); Utils.sendPacketToClient(bos,player); } } catch (IOException e) { diff --git a/mods/eln/turbine/TurbineInOutProcess.java b/mods/eln/turbine/TurbineInOutProcess.java index d725c8593..831977b31 100644 --- a/mods/eln/turbine/TurbineInOutProcess.java +++ b/mods/eln/turbine/TurbineInOutProcess.java @@ -6,6 +6,7 @@ import mods.eln.sim.IProcess; import mods.eln.sim.PhysicalConstant; import mods.eln.sim.ThermalLoad; +import mods.eln.sound.SoundParam; import mods.eln.sound.SoundServer; @@ -60,7 +61,7 @@ public void process(double time) { soundTimerCounter += time; if (soundTimerCounter >= soundTimeOut && deltaT > 40) { float factor = (float)(deltaT / turbine.descriptor.nominalDeltaT); - SoundServer.playFromCoord(turbine.coordonate(), descriptor.soundName, descriptor.nominalVolume * (0.1f * factor), 0.9f + 0.2f * factor, 10, 25); + SoundServer.play(new SoundParam(descriptor.soundName,turbine.coordonate()).setVolume(descriptor.nominalVolume * (0.1f * factor), 0.9f + 0.2f * factor).mediumRange()); soundTimerCounter = 0; } diff --git a/mods/eln/waterturbine/WaterTurbineRender.java b/mods/eln/waterturbine/WaterTurbineRender.java index 9a0c71f39..321f177ea 100644 --- a/mods/eln/waterturbine/WaterTurbineRender.java +++ b/mods/eln/waterturbine/WaterTurbineRender.java @@ -13,6 +13,7 @@ import mods.eln.node.TransparentNodeElementRender; import mods.eln.node.TransparentNodeEntity; import mods.eln.sound.SoundClient; +import mods.eln.sound.SoundParam; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; @@ -57,9 +58,9 @@ public void draw() { // if (Math.signum((alpha % 45) - 40f) != Math.signum((alphaN_1 % 45) - 40f) && soundPlaying == false) { if ((int)(alpha/45) != (int)(alphaN_1/45) && soundPlaying == false) { Coordonate coord = coordonate(); - tileEntity.getWorldObj().playSound(coord.x, coord.y, coord.z, descriptor.soundName, - descriptor.nominalVolume * (0.007f + 0.2f * (float) powerFactorFilter.get() * (float) powerFactorFilter.get()), - 1.1f, false); + SoundClient.play(new SoundParam(descriptor.soundName, tileEntity) + .setVolume(descriptor.nominalVolume * (0.007f + 0.2f * (float) powerFactorFilter.get() * (float) powerFactorFilter.get()), + 1.1f)); //SoundClient.playFromBlock(tileEntity.worldObj,coord.x, coord.y, coord.z, descriptor.soundName,1,1,5,15); soundPlaying = true; } else diff --git a/mods/eln/windturbine/WindTurbineRender.java b/mods/eln/windturbine/WindTurbineRender.java index dd6e19d5c..e7eb84616 100644 --- a/mods/eln/windturbine/WindTurbineRender.java +++ b/mods/eln/windturbine/WindTurbineRender.java @@ -11,6 +11,8 @@ import mods.eln.node.TransparentNodeElementInventory; import mods.eln.node.TransparentNodeElementRender; import mods.eln.node.TransparentNodeEntity; +import mods.eln.sound.SoundClient; +import mods.eln.sound.SoundParam; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; @@ -38,9 +40,10 @@ public void draw() { if (alpha % 120 > 45 && alphaN_1 % 120 <= 45 && soundPlaying == false) { Coordonate coord = coordonate(); - tileEntity.getWorldObj().playSound(coord.x, coord.y, coord.z, descriptor.soundName, - descriptor.nominalVolume * (0.007f + 1f * (float)powerFactorFilter.get() * (float)powerFactorFilter.get()), - 1f + (float)Math.sqrt(powerFactorFilter.get()) / 1.3f, false); + SoundClient.play(new SoundParam(descriptor.soundName, tileEntity) + .setVolume(descriptor.nominalVolume * (0.007f + 1f * (float)powerFactorFilter.get() * (float)powerFactorFilter.get()), + 1f + (float)Math.sqrt(powerFactorFilter.get()) / 1.3f)); + soundPlaying = true; } else { soundPlaying = false;