mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
Fix #15; completely overhaul the sound system to mirror Minecraft usage
This commit is contained in:
1 parent
d2b905dcdc
commit
c78ae6dd1d
37 files changed
+632
-1419
No files matched your search
@@ -12,9 +12,7 @@ public class ClientPlayerTracker
|
||||
@SubscribeEvent
|
||||
public void onPlayerChangedDimension(PlayerChangedDimensionEvent event)
|
||||
{
|
||||
Mekanism.jetpackOn.remove(event.player.getName());
|
||||
Mekanism.gasmaskOn.remove(event.player.getName());
|
||||
Mekanism.flamethrowerActive.remove(event.player.getName());
|
||||
Mekanism.playerState.clearPlayer(event.player);
|
||||
Mekanism.freeRunnerOn.remove(event.player.getName());
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,22 @@
|
||||
package mekanism.client;
|
||||
|
||||
import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER;
|
||||
import static mekanism.client.sound.SoundHandler.Channel.GASMASK;
|
||||
import static mekanism.client.sound.SoundHandler.Channel.JETPACK;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import mekanism.api.IClientTicker;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.client.render.RenderTickHandler;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.CommonPlayerTickHandler;
|
||||
import mekanism.common.KeySync;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.config.MekanismConfig.client;
|
||||
import mekanism.common.config.MekanismConfig.general;
|
||||
import mekanism.common.frequency.Frequency;
|
||||
import mekanism.common.item.ItemConfigurator;
|
||||
import mekanism.common.item.*;
|
||||
import mekanism.common.item.ItemConfigurator.ConfiguratorMode;
|
||||
import mekanism.common.item.ItemFlamethrower;
|
||||
import mekanism.common.item.ItemFreeRunners;
|
||||
import mekanism.common.item.ItemGasMask;
|
||||
import mekanism.common.item.ItemJetpack;
|
||||
import mekanism.common.item.ItemJetpack.JetpackMode;
|
||||
import mekanism.common.item.ItemScubaTank;
|
||||
import mekanism.common.network.PacketFlamethrowerData;
|
||||
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerDataMessage;
|
||||
import mekanism.common.network.PacketFreeRunnerData;
|
||||
import mekanism.common.network.PacketItemStack.ItemStackMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackPacket;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterPacketType;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
|
||||
import mekanism.common.util.ListUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -62,7 +38,8 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Client-side tick handler for Mekanism. Used mainly for the update check upon startup.
|
||||
@@ -224,91 +201,12 @@ public class ClientTickHandler
|
||||
}
|
||||
}
|
||||
|
||||
if(Mekanism.flamethrowerActive.contains(mc.player.getName()) != isFlamethrowerOn(mc.player))
|
||||
{
|
||||
if(isFlamethrowerOn(mc.player))
|
||||
{
|
||||
Mekanism.flamethrowerActive.add(mc.player.getName());
|
||||
}
|
||||
else {
|
||||
Mekanism.flamethrowerActive.remove(mc.player.getName());
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new FlamethrowerDataMessage(PacketFlamethrowerData.FlamethrowerPacket.UPDATE, null, mc.player.getName(), isFlamethrowerOn(mc.player)));
|
||||
}
|
||||
// Update player's state for various items; this also automatically notifies server if something changed and
|
||||
// kicks off sounds as necessary
|
||||
Mekanism.playerState.setJetpackState(mc.player.getName(), isJetpackActive(mc.player));
|
||||
Mekanism.playerState.setGasmaskState(mc.player.getName(), isGasMaskOn(mc.player));
|
||||
Mekanism.playerState.setFlamethrowerState(mc.player.getName(), isFlamethrowerOn(mc.player));
|
||||
|
||||
if(Mekanism.jetpackOn.contains(mc.player.getName()) != isJetpackOn(mc.player))
|
||||
{
|
||||
if(isJetpackOn(mc.player))
|
||||
{
|
||||
Mekanism.jetpackOn.add(mc.player.getName());
|
||||
}
|
||||
else {
|
||||
Mekanism.jetpackOn.remove(mc.player.getName());
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new JetpackDataMessage(JetpackPacket.UPDATE, mc.player.getName(), isJetpackOn(mc.player)));
|
||||
}
|
||||
|
||||
if(Mekanism.gasmaskOn.contains(mc.player.getName()) != isGasMaskOn(mc.player))
|
||||
{
|
||||
if(isGasMaskOn(mc.player) && mc.currentScreen == null)
|
||||
{
|
||||
Mekanism.gasmaskOn.add(mc.player.getName());
|
||||
}
|
||||
else {
|
||||
Mekanism.gasmaskOn.remove(mc.player.getName());
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new ScubaTankDataMessage(ScubaTankPacket.UPDATE, mc.player.getName(), isGasMaskOn(mc.player)));
|
||||
}
|
||||
|
||||
if(client.enablePlayerSounds)
|
||||
{
|
||||
for(String username : Mekanism.jetpackOn)
|
||||
{
|
||||
EntityPlayer player = mc.world.getPlayerEntityByName(username);
|
||||
|
||||
if(player != null)
|
||||
{
|
||||
if(!SoundHandler.soundPlaying(player, JETPACK))
|
||||
{
|
||||
SoundHandler.addSound(player, JETPACK, client.replaceSoundsWhenResuming);
|
||||
}
|
||||
|
||||
SoundHandler.playSound(player, JETPACK);
|
||||
}
|
||||
}
|
||||
|
||||
for(String username : Mekanism.gasmaskOn)
|
||||
{
|
||||
EntityPlayer player = mc.world.getPlayerEntityByName(username);
|
||||
|
||||
if(player != null)
|
||||
{
|
||||
if(!SoundHandler.soundPlaying(player, GASMASK))
|
||||
{
|
||||
SoundHandler.addSound(player, GASMASK, client.replaceSoundsWhenResuming);
|
||||
}
|
||||
|
||||
SoundHandler.playSound(player, GASMASK);
|
||||
}
|
||||
}
|
||||
|
||||
for(EntityPlayer player : (List<EntityPlayer>)mc.world.playerEntities)
|
||||
{
|
||||
if(hasFlamethrower(player))
|
||||
{
|
||||
if(!SoundHandler.soundPlaying(player, FLAMETHROWER))
|
||||
{
|
||||
SoundHandler.addSound(player, FLAMETHROWER, client.replaceSoundsWhenResuming);
|
||||
}
|
||||
|
||||
SoundHandler.playSound(player, FLAMETHROWER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Iterator<Entry<EntityPlayer, TeleportData>> iter = portableTeleports.entrySet().iterator(); iter.hasNext();)
|
||||
{
|
||||
Entry<EntityPlayer, TeleportData> entry = iter.next();
|
||||
@@ -347,7 +245,7 @@ public class ClientTickHandler
|
||||
}
|
||||
}
|
||||
|
||||
if(isJetpackOn(mc.player))
|
||||
if(isJetpackActive(mc.player))
|
||||
{
|
||||
ItemJetpack jetpack = (ItemJetpack)chestStack.getItem();
|
||||
|
||||
@@ -471,11 +369,11 @@ public class ClientTickHandler
|
||||
tickingSet.removeIf(iClientTicker -> !iClientTicker.needsTicks());
|
||||
}
|
||||
|
||||
public static boolean isJetpackOn(EntityPlayer player)
|
||||
public static boolean isJetpackActive(EntityPlayer player)
|
||||
{
|
||||
if(player != mc.player)
|
||||
{
|
||||
return Mekanism.jetpackOn.contains(player.getName());
|
||||
return Mekanism.playerState.isJetpackOn(player);
|
||||
}
|
||||
|
||||
ItemStack stack = player.inventory.armorInventory.get(2);
|
||||
@@ -516,7 +414,7 @@ public class ClientTickHandler
|
||||
{
|
||||
if(player != mc.player)
|
||||
{
|
||||
return Mekanism.gasmaskOn.contains(player.getName());
|
||||
return Mekanism.playerState.isGasmaskOn(player);
|
||||
}
|
||||
|
||||
ItemStack tank = player.inventory.armorInventory.get(2);
|
||||
@@ -567,7 +465,7 @@ public class ClientTickHandler
|
||||
{
|
||||
if(player != mc.player)
|
||||
{
|
||||
return Mekanism.flamethrowerActive.contains(player.getName());
|
||||
return Mekanism.playerState.isFlamethrowerOn(player);
|
||||
}
|
||||
|
||||
if(hasFlamethrower(player))
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package mekanism.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.MekanismAPI.BoxBlacklistEvent;
|
||||
import mekanism.client.render.obj.TransmitterModel;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.IModule;
|
||||
import mekanism.common.content.boiler.SynchronizedBoilerData;
|
||||
@@ -17,6 +12,10 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MekanismClient extends Mekanism
|
||||
{
|
||||
public static Map<UUID, SecurityData> clientSecurityMap = new HashMap<>();
|
||||
@@ -48,9 +47,7 @@ public class MekanismClient extends Mekanism
|
||||
MekanismAPI.getBoxIgnore().clear();
|
||||
MinecraftForge.EVENT_BUS.post(new BoxBlacklistEvent());
|
||||
|
||||
Mekanism.jetpackOn.clear();
|
||||
Mekanism.gasmaskOn.clear();
|
||||
Mekanism.flamethrowerActive.clear();
|
||||
Mekanism.playerState.clear();
|
||||
Mekanism.activeVibrators.clear();
|
||||
Mekanism.freeRunnerOn.clear();
|
||||
|
||||
@@ -61,8 +58,6 @@ public class MekanismClient extends Mekanism
|
||||
module.resetClient();
|
||||
}
|
||||
|
||||
SoundHandler.soundMaps.clear();
|
||||
|
||||
Mekanism.proxy.loadConfiguration();
|
||||
|
||||
Mekanism.logger.info("Reloaded config.");
|
||||
|
||||
@@ -19,7 +19,6 @@ import mekanism.common.network.PacketFlamethrowerData;
|
||||
import mekanism.common.network.PacketFreeRunnerData;
|
||||
import mekanism.common.network.PacketItemStack.ItemStackMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackPacket;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
|
||||
import mekanism.common.util.LangUtils;
|
||||
@@ -119,7 +118,6 @@ public class MekanismKeyHandler extends MekKeyHandler
|
||||
int newChan = wt.getChannel(toolStack) < 9 ? wt.getChannel(toolStack) + 1 : 1;
|
||||
wt.setChannel(toolStack, newChan);
|
||||
Mekanism.packetHandler.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND, ListUtils.asArrayList(newChan)));
|
||||
SoundHandler.playSound(MekanismSounds.DING);
|
||||
}
|
||||
}
|
||||
else if(player.isSneaking() && item instanceof ItemFlamethrower)
|
||||
@@ -149,7 +147,7 @@ public class MekanismKeyHandler extends MekKeyHandler
|
||||
jetpack.incrementMode(chestStack);
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new JetpackDataMessage(JetpackPacket.MODE, null, player.isSneaking()));
|
||||
Mekanism.packetHandler.sendToServer(JetpackDataMessage.MODE_CHANGE(player.isSneaking()));
|
||||
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
|
||||
}
|
||||
else if(chestItem instanceof ItemScubaTank)
|
||||
@@ -157,7 +155,7 @@ public class MekanismKeyHandler extends MekKeyHandler
|
||||
ItemScubaTank scubaTank = (ItemScubaTank)chestItem;
|
||||
|
||||
scubaTank.toggleFlowing(chestStack);
|
||||
Mekanism.packetHandler.sendToServer(new ScubaTankDataMessage(ScubaTankPacket.MODE, null, false));
|
||||
Mekanism.packetHandler.sendToServer(ScubaTankDataMessage.MODE_CHANGE(false));
|
||||
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +77,11 @@ public class GuiFactory extends GuiMekanism
|
||||
|
||||
if(xAxis >= 8 && xAxis <= 168 && yAxis >= 78 && yAxis <= 83)
|
||||
{
|
||||
if(tileEntity.recipeType.getFuelType() == MachineFuelType.ADVANCED)
|
||||
if(tileEntity.getRecipeType().getFuelType() == MachineFuelType.ADVANCED)
|
||||
{
|
||||
drawHoveringText(tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas().getLocalizedName() + ": " + tileEntity.gasTank.getStored() : LangUtils.localize("gui.none"), xAxis, yAxis);
|
||||
}
|
||||
else if(tileEntity.recipeType == RecipeType.INFUSING)
|
||||
else if(tileEntity.getRecipeType() == RecipeType.INFUSING)
|
||||
{
|
||||
drawHoveringText(tileEntity.infuseStored.type != null ? tileEntity.infuseStored.type.getLocalizedName() + ": " + tileEntity.infuseStored.amount : LangUtils.localize("gui.empty"), xAxis, yAxis);
|
||||
}
|
||||
@@ -120,14 +120,14 @@ public class GuiFactory extends GuiMekanism
|
||||
drawTexturedModalRect(guiWidth + xPos, guiHeight + 33, 176, 52, 8, displayInt);
|
||||
}
|
||||
|
||||
if(tileEntity.recipeType.getFuelType() == MachineFuelType.ADVANCED)
|
||||
if(tileEntity.getRecipeType().getFuelType() == MachineFuelType.ADVANCED)
|
||||
{
|
||||
if(tileEntity.getScaledGasLevel(160) > 0)
|
||||
{
|
||||
displayGauge(8, 78, tileEntity.getScaledGasLevel(160), 5, tileEntity.gasTank.getGas().getGas().getSprite());
|
||||
}
|
||||
}
|
||||
else if(tileEntity.recipeType == RecipeType.INFUSING)
|
||||
else if(tileEntity.getRecipeType() == RecipeType.INFUSING)
|
||||
{
|
||||
if(tileEntity.getScaledInfuseLevel(160) > 0)
|
||||
{
|
||||
|
||||
@@ -130,81 +130,79 @@ public class RenderTickHandler
|
||||
}
|
||||
}
|
||||
|
||||
synchronized(Mekanism.jetpackOn)
|
||||
{
|
||||
for(String s : Mekanism.jetpackOn)
|
||||
{
|
||||
EntityPlayer p = mc.world.getPlayerEntityByName(s);
|
||||
// Traverse a copy of jetpack state and do animations
|
||||
// TODO: This means we're making a full copy of the state per render....might need to revisit
|
||||
for (String s : Mekanism.playerState.getActiveJetpacks()) {
|
||||
EntityPlayer p = mc.world.getPlayerEntityByName(s);
|
||||
|
||||
if(p == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Pos3D playerPos = new Pos3D(p).translate(0, 1.7, 0);
|
||||
|
||||
float random = (rand.nextFloat() - 0.5F) * 0.1F;
|
||||
|
||||
Pos3D vLeft = new Pos3D(-0.43, -0.55, -0.54).rotatePitch(p.isSneaking() ? 20 : 0).rotateYaw(p.renderYawOffset);
|
||||
Pos3D vRight = new Pos3D(0.43, -0.55, -0.54).rotatePitch(p.isSneaking() ? 20 : 0).rotateYaw(p.renderYawOffset);
|
||||
Pos3D vCenter = new Pos3D((rand.nextFloat() - 0.5F) * 0.4F, -0.86, -0.30).rotatePitch(p.isSneaking() ? 25 : 0).rotateYaw(p.renderYawOffset);
|
||||
|
||||
Pos3D rLeft = vLeft.scale(random);
|
||||
Pos3D rRight = vRight.scale(random);
|
||||
|
||||
Pos3D mLeft = vLeft.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
Pos3D mRight = vRight.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
Pos3D mCenter = vCenter.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
|
||||
mLeft = mLeft.translate(rLeft);
|
||||
mRight = mRight.translate(rRight);
|
||||
|
||||
Pos3D v = playerPos.translate(vLeft).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
spawnAndSetParticle(EnumParticleTypes.FLAME, world, v.x, v.y, v.z, mLeft.x, mLeft.y, mLeft.z);
|
||||
spawnAndSetParticle(EnumParticleTypes.SMOKE_NORMAL, world, v.x, v.y, v.z, mLeft.x, mLeft.y, mLeft.z);
|
||||
|
||||
v = playerPos.translate(vRight).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
spawnAndSetParticle(EnumParticleTypes.FLAME, world, v.x, v.y, v.z, mRight.x, mRight.y, mRight.z);
|
||||
spawnAndSetParticle(EnumParticleTypes.SMOKE_NORMAL, world, v.x, v.y, v.z, mRight.x, mRight.y, mRight.z);
|
||||
|
||||
v = playerPos.translate(vCenter).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
spawnAndSetParticle(EnumParticleTypes.FLAME, world, v.x, v.y, v.z, mCenter.x, mCenter.y, mCenter.z);
|
||||
spawnAndSetParticle(EnumParticleTypes.SMOKE_NORMAL, world, v.x, v.y, v.z, mCenter.x, mCenter.y, mCenter.z);
|
||||
if (p == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Pos3D playerPos = new Pos3D(p).translate(0, 1.7, 0);
|
||||
|
||||
float random = (rand.nextFloat() - 0.5F) * 0.1F;
|
||||
|
||||
Pos3D vLeft = new Pos3D(-0.43, -0.55, -0.54).rotatePitch(p.isSneaking() ? 20 : 0).rotateYaw(p.renderYawOffset);
|
||||
Pos3D vRight = new Pos3D(0.43, -0.55, -0.54).rotatePitch(p.isSneaking() ? 20 : 0).rotateYaw(p.renderYawOffset);
|
||||
Pos3D vCenter = new Pos3D((rand.nextFloat() - 0.5F) * 0.4F, -0.86, -0.30).rotatePitch(p.isSneaking() ? 25 : 0).rotateYaw(p.renderYawOffset);
|
||||
|
||||
Pos3D rLeft = vLeft.scale(random);
|
||||
Pos3D rRight = vRight.scale(random);
|
||||
|
||||
Pos3D mLeft = vLeft.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
Pos3D mRight = vRight.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
Pos3D mCenter = vCenter.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
|
||||
mLeft = mLeft.translate(rLeft);
|
||||
mRight = mRight.translate(rRight);
|
||||
|
||||
Pos3D v = playerPos.translate(vLeft).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
spawnAndSetParticle(EnumParticleTypes.FLAME, world, v.x, v.y, v.z, mLeft.x, mLeft.y, mLeft.z);
|
||||
spawnAndSetParticle(EnumParticleTypes.SMOKE_NORMAL, world, v.x, v.y, v.z, mLeft.x, mLeft.y, mLeft.z);
|
||||
|
||||
v = playerPos.translate(vRight).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
spawnAndSetParticle(EnumParticleTypes.FLAME, world, v.x, v.y, v.z, mRight.x, mRight.y, mRight.z);
|
||||
spawnAndSetParticle(EnumParticleTypes.SMOKE_NORMAL, world, v.x, v.y, v.z, mRight.x, mRight.y, mRight.z);
|
||||
|
||||
v = playerPos.translate(vCenter).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
spawnAndSetParticle(EnumParticleTypes.FLAME, world, v.x, v.y, v.z, mCenter.x, mCenter.y, mCenter.z);
|
||||
spawnAndSetParticle(EnumParticleTypes.SMOKE_NORMAL, world, v.x, v.y, v.z, mCenter.x, mCenter.y, mCenter.z);
|
||||
}
|
||||
|
||||
synchronized(Mekanism.gasmaskOn)
|
||||
{
|
||||
if(world.getWorldTime() % 4 == 0)
|
||||
{
|
||||
for(String s : Mekanism.gasmaskOn)
|
||||
{
|
||||
EntityPlayer p = mc.world.getPlayerEntityByName(s);
|
||||
|
||||
if(p == null || !p.isInWater())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Pos3D playerPos = new Pos3D(p).translate(0, 1.7, 0);
|
||||
|
||||
float xRand = (rand.nextFloat() - 0.5F) * 0.08F;
|
||||
float yRand = (rand.nextFloat() - 0.5F) * 0.05F;
|
||||
|
||||
Pos3D vec = new Pos3D(0.4, 0.4, 0.4).multiply(new Pos3D(p.getLook(1))).translate(0, -0.2, 0);
|
||||
Pos3D motion = vec.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
|
||||
Pos3D v = playerPos.translate(vec);
|
||||
spawnAndSetParticle(EnumParticleTypes.WATER_BUBBLE, world, v.x, v.y, v.z, motion.x, motion.y + 0.2, motion.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(world.getWorldTime() % 4 == 0)
|
||||
|
||||
// Traverse a copy of gasmask state and do animations
|
||||
// TODO: This means we're making a full copy of the state per render....might need to revisit
|
||||
if(world.getWorldTime() % 4 == 0)
|
||||
{
|
||||
for(String s : Mekanism.playerState.getActiveGasmasks())
|
||||
{
|
||||
EntityPlayer p = mc.world.getPlayerEntityByName(s);
|
||||
|
||||
if(p == null || !p.isInWater())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Pos3D playerPos = new Pos3D(p).translate(0, 1.7, 0);
|
||||
|
||||
float xRand = (rand.nextFloat() - 0.5F) * 0.08F;
|
||||
float yRand = (rand.nextFloat() - 0.5F) * 0.05F;
|
||||
|
||||
Pos3D vec = new Pos3D(0.4, 0.4, 0.4).multiply(new Pos3D(p.getLook(1))).translate(0, -0.2, 0);
|
||||
Pos3D motion = vec.scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ));
|
||||
|
||||
Pos3D v = playerPos.translate(vec);
|
||||
spawnAndSetParticle(EnumParticleTypes.WATER_BUBBLE, world, v.x, v.y, v.z, motion.x, motion.y + 0.2, motion.z);
|
||||
}
|
||||
}
|
||||
|
||||
// Traverse a copy of flamethrower state and do animations
|
||||
// TODO: This means we're making a full copy of the state per render....might need to revisit
|
||||
if(world.getWorldTime() % 4 == 0)
|
||||
{
|
||||
for(EntityPlayer p : world.playerEntities)
|
||||
{
|
||||
if(!Mekanism.flamethrowerActive.contains(p.getName()) && !p.isSwingInProgress && !p.inventory.getCurrentItem().isEmpty() && p.inventory.getCurrentItem().getItem() instanceof ItemFlamethrower)
|
||||
if(!Mekanism.playerState.isFlamethrowerOn(p) && !p.isSwingInProgress && !p.inventory.getCurrentItem().isEmpty() && p.inventory.getCurrentItem().getItem() instanceof ItemFlamethrower)
|
||||
{
|
||||
if(((ItemFlamethrower)p.inventory.getCurrentItem().getItem()).getGas(p.inventory.getCurrentItem()) != null)
|
||||
{
|
||||
|
||||
@@ -9,56 +9,41 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class FlamethrowerSound extends PlayerSound
|
||||
{
|
||||
public boolean inUse;
|
||||
private static ResourceLocation IDLE_SOUND = new ResourceLocation("mekanism", "item.flamethrower.idle");
|
||||
private static ResourceLocation ON_SOUND = new ResourceLocation("mekanism", "item.flamethrower.active");
|
||||
private static ResourceLocation OFF_SOUND = new ResourceLocation("mekanism", "item.flamethrower.active");
|
||||
|
||||
public ResourceLocation onSound;
|
||||
public ResourceLocation offSound;
|
||||
private boolean inUse;
|
||||
|
||||
public FlamethrowerSound(EntityPlayer player)
|
||||
{
|
||||
super(player, new ResourceLocation("mekanism", "item.flamethrower.idle"));
|
||||
super(player, IDLE_SOUND);
|
||||
|
||||
onSound = new ResourceLocation("mekanism", "item.flamethrower.active");
|
||||
offSound = new ResourceLocation("mekanism", "item.flamethrower.idle");
|
||||
inUse = ClientTickHandler.isFlamethrowerOn(player);
|
||||
soundLocation = inUse ? onSound : offSound;
|
||||
|
||||
setFadeIn(0);
|
||||
setFadeOut(0);
|
||||
|
||||
this.positionedSoundLocation = inUse ? ON_SOUND : OFF_SOUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDonePlaying()
|
||||
{
|
||||
return donePlaying;
|
||||
}
|
||||
public boolean shouldPlaySound() {
|
||||
boolean hasFlamethrower = ClientTickHandler.hasFlamethrower(player);
|
||||
boolean isFlamethrowerOn = ClientTickHandler.isFlamethrowerOn(player);
|
||||
|
||||
@Override
|
||||
public boolean shouldPlaySound()
|
||||
{
|
||||
if (!hasFlamethrower) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inUse != isFlamethrowerOn) {
|
||||
inUse = isFlamethrowerOn;
|
||||
this.positionedSoundLocation = inUse ? ON_SOUND : OFF_SOUND;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume()
|
||||
{
|
||||
return super.getVolume() * (inUse ? 2 : 1);
|
||||
}
|
||||
// @Override
|
||||
// public float getVolume()
|
||||
// {
|
||||
// return super.getVolume() * (inUse ? 2 : 1);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if(!ClientTickHandler.hasFlamethrower(player))
|
||||
{
|
||||
donePlaying = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(inUse != ClientTickHandler.isFlamethrowerOn(player))
|
||||
{
|
||||
inUse = ClientTickHandler.isFlamethrowerOn(player);
|
||||
soundLocation = inUse ? onSound : offSound;
|
||||
donePlaying = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,34 +4,24 @@ import mekanism.client.ClientTickHandler;
|
||||
import mekanism.common.item.ItemGasMask;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GasMaskSound extends PlayerSound
|
||||
{
|
||||
public GasMaskSound(EntityPlayer player)
|
||||
{
|
||||
super(player, new ResourceLocation("mekanism", "item.gasMask"));
|
||||
|
||||
setFadeIn(10);
|
||||
setFadeOut(5);
|
||||
}
|
||||
private static final ResourceLocation SOUND = new ResourceLocation("mekanism", "item.gasMask");
|
||||
|
||||
@Override
|
||||
public boolean isDonePlaying()
|
||||
{
|
||||
return donePlaying;
|
||||
public GasMaskSound(EntityPlayer player) {
|
||||
super(player, SOUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldPlaySound()
|
||||
{
|
||||
return hasGasMask(player) && ClientTickHandler.isGasMaskOn(player);
|
||||
}
|
||||
|
||||
private boolean hasGasMask(EntityPlayer player)
|
||||
{
|
||||
return !player.inventory.armorInventory.get(3).isEmpty() && player.inventory.armorInventory.get(3).getItem() instanceof ItemGasMask;
|
||||
boolean hasGasMask = !player.inventory.armorInventory.get(3).isEmpty() &&
|
||||
player.inventory.armorInventory.get(3).getItem() instanceof ItemGasMask;
|
||||
return hasGasMask && ClientTickHandler.isGasMaskOn(player);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package mekanism.client.sound;
|
||||
|
||||
import net.minecraft.client.audio.ITickableSound;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IResettableSound extends ITickableSound
|
||||
{
|
||||
void reset();
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package mekanism.client.sound;
|
||||
|
||||
import net.minecraft.client.audio.ISound.AttenuationType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public interface ISoundSource
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
ResourceLocation getSoundLocation();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
float getVolume();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
float getFrequency();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
Vec3d getSoundPosition();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
boolean shouldRepeat();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
int getRepeatDelay();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
AttenuationType getAttenuation();
|
||||
}
|
||||
@@ -1,37 +1,23 @@
|
||||
package mekanism.client.sound;
|
||||
|
||||
import mekanism.client.ClientTickHandler;
|
||||
import mekanism.common.item.ItemJetpack;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class JetpackSound extends PlayerSound
|
||||
{
|
||||
public JetpackSound(EntityPlayer player)
|
||||
{
|
||||
super(player, new ResourceLocation("mekanism", "item.jetpack"));
|
||||
|
||||
setFadeIn(10);
|
||||
setFadeOut(5);
|
||||
private static final ResourceLocation SOUND = new ResourceLocation("mekanism", "item.jetpack");
|
||||
|
||||
public JetpackSound(EntityPlayer player) {
|
||||
super(player, SOUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDonePlaying()
|
||||
{
|
||||
return donePlaying;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldPlaySound()
|
||||
{
|
||||
return hasJetpack(player) && ClientTickHandler.isJetpackOn(player);
|
||||
}
|
||||
|
||||
private boolean hasJetpack(EntityPlayer player)
|
||||
{
|
||||
return !player.inventory.armorInventory.get(2).isEmpty() && player.inventory.armorInventory.get(2).getItem() instanceof ItemJetpack;
|
||||
public boolean shouldPlaySound() {
|
||||
return ClientTickHandler.isJetpackActive(player);
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
package mekanism.client.sound;
|
||||
|
||||
import mekanism.common.config.MekanismConfig.client;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.Sound;
|
||||
import net.minecraft.client.audio.SoundEventAccessor;
|
||||
import net.minecraft.client.audio.SoundHandler;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Generic ISound class with lots of constructor functionality.
|
||||
* Required because - of course - Mojang has no generic that
|
||||
* lets you specify *any* arguments for this.
|
||||
*
|
||||
* Taken from CoFHLib
|
||||
*
|
||||
* @author skyboy
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class MekSound implements ISound
|
||||
{
|
||||
protected Sound sound;
|
||||
|
||||
protected SoundEventAccessor soundEvent;
|
||||
|
||||
protected AttenuationType attenuation;
|
||||
|
||||
protected ResourceLocation soundLocation;
|
||||
|
||||
protected float volume;
|
||||
|
||||
protected float pitch;
|
||||
|
||||
protected float x;
|
||||
|
||||
protected float y;
|
||||
|
||||
protected float z;
|
||||
|
||||
protected boolean repeat;
|
||||
|
||||
protected int repeatDelay;
|
||||
|
||||
public MekSound(String sound)
|
||||
{
|
||||
this(sound, 0);
|
||||
}
|
||||
|
||||
public MekSound(String sound, float volume)
|
||||
{
|
||||
this(sound, volume, 0);
|
||||
}
|
||||
|
||||
public MekSound(String sound, float volume, float pitch)
|
||||
{
|
||||
this(sound, volume, pitch, false, 0);
|
||||
}
|
||||
|
||||
public MekSound(String sound, float volume, float pitch, boolean repeat, int repeatDelay)
|
||||
{
|
||||
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
|
||||
}
|
||||
|
||||
public MekSound(String sound, float volume, float pitch, double x, double y, double z)
|
||||
{
|
||||
this(sound, volume, pitch, false, 0, x, y, z);
|
||||
}
|
||||
|
||||
public MekSound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
|
||||
{
|
||||
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
|
||||
}
|
||||
|
||||
public MekSound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
|
||||
{
|
||||
this(new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
|
||||
}
|
||||
|
||||
public MekSound(ResourceLocation sound)
|
||||
{
|
||||
this(sound, 0);
|
||||
}
|
||||
|
||||
public MekSound(ResourceLocation sound, float volume)
|
||||
{
|
||||
this(sound, volume, 0);
|
||||
}
|
||||
|
||||
public MekSound(ResourceLocation sound, float volume, float pitch)
|
||||
{
|
||||
this(sound, volume, pitch, false, 0);
|
||||
}
|
||||
|
||||
public MekSound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay)
|
||||
{
|
||||
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
|
||||
}
|
||||
|
||||
public MekSound(ResourceLocation sound, float volume, float pitch, double x, double y, double z)
|
||||
{
|
||||
this(sound, volume, pitch, false, 0, x, y, z);
|
||||
}
|
||||
|
||||
public MekSound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
|
||||
{
|
||||
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
|
||||
}
|
||||
|
||||
public MekSound(ResourceLocation resource, float v, float p, boolean rep, int delay, double xPos, double yPos, double zPos, AttenuationType att)
|
||||
{
|
||||
attenuation = att;
|
||||
soundLocation = resource;
|
||||
volume = v;
|
||||
pitch = p;
|
||||
x = (float)xPos;
|
||||
y = (float)yPos;
|
||||
z = (float)zPos;
|
||||
repeat = rep;
|
||||
repeatDelay = delay;
|
||||
}
|
||||
|
||||
public MekSound(MekSound other)
|
||||
{
|
||||
attenuation = other.attenuation;
|
||||
soundLocation = other.soundLocation;
|
||||
volume = other.volume;
|
||||
pitch = other.pitch;
|
||||
x = other.x;
|
||||
y = other.y;
|
||||
z = other.z;
|
||||
repeat = other.repeat;
|
||||
repeatDelay = other.repeatDelay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttenuationType getAttenuationType()
|
||||
{
|
||||
return attenuation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getSoundLocation()
|
||||
{
|
||||
return soundLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume()
|
||||
{
|
||||
return volume * client.baseSoundVolume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPitch()
|
||||
{
|
||||
return pitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getXPosF()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYPosF()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZPosF()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRepeat()
|
||||
{
|
||||
return repeat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRepeatDelay()
|
||||
{
|
||||
return repeatDelay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEventAccessor createAccessor(SoundHandler handler)
|
||||
{
|
||||
soundEvent = handler.getAccessor(soundLocation);
|
||||
|
||||
if(soundEvent == null)
|
||||
{
|
||||
sound = SoundHandler.MISSING_SOUND;
|
||||
}
|
||||
else {
|
||||
sound = soundEvent.cloneEntry();
|
||||
}
|
||||
|
||||
return soundEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundCategory getCategory()
|
||||
{
|
||||
return SoundCategory.BLOCKS;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,32 @@
|
||||
package mekanism.client.sound;
|
||||
|
||||
import net.minecraft.client.audio.ITickableSound;
|
||||
import net.minecraft.client.audio.MovingSound;
|
||||
import net.minecraft.client.audio.PositionedSound;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class PlayerSound extends MekSound implements IResettableSound
|
||||
public abstract class PlayerSound extends PositionedSound implements ITickableSound
|
||||
{
|
||||
public EntityPlayer player;
|
||||
protected EntityPlayer player;
|
||||
|
||||
boolean beginFadeOut;
|
||||
|
||||
boolean donePlaying = true;
|
||||
|
||||
int ticks = 0;
|
||||
|
||||
int fadeIn;
|
||||
|
||||
int fadeOut;
|
||||
|
||||
float baseVolume = 0.3F;
|
||||
private float fadeUpStep = 0.1f;
|
||||
private float fadeDownStep = 0.1f;
|
||||
|
||||
public PlayerSound(EntityPlayer p, ResourceLocation location)
|
||||
{
|
||||
super(location, 0.3F, 1, true, 0, (float)p.posX, (float)p.posY, (float)p.posZ, AttenuationType.LINEAR);
|
||||
player = p;
|
||||
private boolean donePlaying = false;
|
||||
|
||||
public PlayerSound(EntityPlayer player, ResourceLocation sound) {
|
||||
super(sound, SoundCategory.PLAYERS);
|
||||
this.player = player;
|
||||
|
||||
// N.B. the volume must be > 0 on first time it's processed by sound system or else it will not
|
||||
// get registered for tick events.
|
||||
this.volume = 0.1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,71 +47,32 @@ public abstract class PlayerSound extends MekSound implements IResettableSound
|
||||
return (float)player.posZ;
|
||||
}
|
||||
|
||||
public PlayerSound setFadeIn(int fade)
|
||||
{
|
||||
fadeIn = Math.max(0, fade);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerSound setFadeOut(int fade)
|
||||
{
|
||||
fadeOut = Math.max(0, fade);
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFadeInMultiplier()
|
||||
{
|
||||
return ticks >= fadeIn ? 1 : (ticks / (float)fadeIn);
|
||||
}
|
||||
|
||||
public float getFadeOutMultiplier()
|
||||
{
|
||||
return ticks >= fadeOut ? 0 : ((fadeOut - ticks) / (float)fadeOut);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if(!beginFadeOut)
|
||||
{
|
||||
if(ticks < fadeIn)
|
||||
{
|
||||
ticks++;
|
||||
}
|
||||
|
||||
if(!shouldPlaySound())
|
||||
{
|
||||
beginFadeOut = true;
|
||||
ticks = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ticks++;
|
||||
if (player.isDead) {
|
||||
this.donePlaying = true;
|
||||
this.volume = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
float multiplier = beginFadeOut ? getFadeOutMultiplier() : getFadeInMultiplier();
|
||||
volume = baseVolume * multiplier;
|
||||
|
||||
if(multiplier <= 0)
|
||||
{
|
||||
donePlaying = true;
|
||||
if (shouldPlaySound()) {
|
||||
if (volume < 1.0f) {
|
||||
// If we weren't max volume, start fading up
|
||||
volume = Math.max(1.0f, (volume + fadeUpStep));
|
||||
}
|
||||
} else {
|
||||
// Not yet fully muted, fade down
|
||||
if (volume > 0.0f) {
|
||||
volume = Math.max(0.0f, (volume - fadeDownStep));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDonePlaying()
|
||||
{
|
||||
public boolean isDonePlaying() {
|
||||
return donePlaying;
|
||||
}
|
||||
|
||||
public abstract boolean shouldPlaySound();
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
donePlaying = false;
|
||||
beginFadeOut = false;
|
||||
volume = baseVolume;
|
||||
ticks = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,136 +1,55 @@
|
||||
package mekanism.client.sound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.common.config.MekanismConfig.client;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.config.MekanismConfig;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.ITickableSound;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* SoundHandler - a class that handles all Sounds used by Mekanism.
|
||||
* Runs off of PaulsCode's SoundSystem through Minecraft.
|
||||
* @author AidanBrady rewritten by unpairedbracket
|
||||
*
|
||||
*/
|
||||
import java.util.IdentityHashMap;
|
||||
|
||||
// SoundHandler is the central point for sounds on Mek client side. Some sounds, such as hand-held items
|
||||
// are instantiated the first time user uses one and stays in memory (though muted) until the player
|
||||
// leaves the server. Block/tile-based sounds are periodically restarted while machine is active; this ensures
|
||||
// that thousands of idle machines aren't filling up memory with sounds that are rarely running.
|
||||
//
|
||||
// As of 1.12.2, this design closely mirrors that of Minecraft sounds and should be generally compatible with any
|
||||
// other mod that interacts with the sound system (such as mufflers)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundHandler
|
||||
{
|
||||
public static Map<String, Map<String, IResettableSound>> soundMaps = new HashMap<>();
|
||||
public class SoundHandler {
|
||||
private static IdentityHashMap<EntityPlayer, Boolean> jetpackSounds = new IdentityHashMap();
|
||||
private static IdentityHashMap<EntityPlayer, Boolean> gasmaskSounds = new IdentityHashMap<>();
|
||||
|
||||
public static Map<ISound, String> invPlayingSounds;
|
||||
public static void startSound(EntityPlayer player, String soundName) {
|
||||
ISound soundToPlay = null;
|
||||
|
||||
public static Minecraft mc = Minecraft.getMinecraft();
|
||||
if (soundName.equals("jetpack") && !jetpackSounds.containsKey(player)) {
|
||||
jetpackSounds.put(player, true);
|
||||
soundToPlay = new JetpackSound(player);
|
||||
}
|
||||
if (soundName.equals("gasmask") && !gasmaskSounds.containsKey(player)) {
|
||||
gasmaskSounds.put(player, true);
|
||||
soundToPlay = new GasMaskSound(player);
|
||||
}
|
||||
|
||||
public enum Channel
|
||||
{
|
||||
JETPACK("jetpack", JetpackSound.class),
|
||||
GASMASK("gasMask", GasMaskSound.class),
|
||||
FLAMETHROWER("flamethrower", FlamethrowerSound.class);
|
||||
if (soundToPlay != null) {
|
||||
Mekanism.logger.info("Starting sound object for {}: {}", player.getName(), soundName);
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(soundToPlay);
|
||||
}
|
||||
}
|
||||
|
||||
String channelName;
|
||||
Class<? extends PlayerSound> soundClass;
|
||||
public static void playSound(SoundEvent sound)
|
||||
{
|
||||
playSound(PositionedSoundRecord.getMasterRecord(sound, MekanismConfig.client.baseSoundVolume));
|
||||
}
|
||||
|
||||
Channel(String name, Class<? extends PlayerSound> clazz)
|
||||
{
|
||||
channelName = name;
|
||||
soundClass = clazz;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return channelName;
|
||||
}
|
||||
|
||||
public PlayerSound getNewSound(EntityPlayer player)
|
||||
{
|
||||
try {
|
||||
return soundClass.getDeclaredConstructor(EntityPlayer.class).newInstance(player);
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean soundPlaying(EntityPlayer player, Channel channel)
|
||||
{
|
||||
String name = player.getName();
|
||||
Map<String, IResettableSound> map = getMap(name);
|
||||
IResettableSound sound = map.get(channel.getName());
|
||||
|
||||
return !(sound == null || sound.isDonePlaying());
|
||||
}
|
||||
|
||||
public static void addSound(EntityPlayer player, Channel channel, boolean replace)
|
||||
{
|
||||
String name = player.getName();
|
||||
Map<String, IResettableSound> map = getMap(name);
|
||||
IResettableSound sound = map.get(channel.getName());
|
||||
|
||||
if(sound == null || replace)
|
||||
{
|
||||
PlayerSound newSound = channel.getNewSound(player);
|
||||
map.put(channel.getName(), newSound);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean playSound(EntityPlayer player, Channel channel)
|
||||
{
|
||||
String name = player.getName();
|
||||
Map<String, IResettableSound> map = getMap(name);
|
||||
IResettableSound sound = map.get(channel.getName());
|
||||
|
||||
if(sound != null)
|
||||
{
|
||||
if(canRestartSound(sound))
|
||||
{
|
||||
sound.reset();
|
||||
playSound(sound);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Map<String, IResettableSound> getMap(String name)
|
||||
{
|
||||
Map<String, IResettableSound> map = soundMaps.computeIfAbsent(name, k -> new HashMap<>());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static SoundManager getSoundManager()
|
||||
{
|
||||
return mc.getSoundHandler().sndManager;
|
||||
}
|
||||
|
||||
//Fudge required because sound thread gets behind and the biMap crashes when rapidly toggling sounds.
|
||||
public static Map<ISound, String> getSoundMap()
|
||||
{
|
||||
return mc.getSoundHandler().sndManager.invPlayingSounds;
|
||||
}
|
||||
|
||||
public static boolean canRestartSound(ITickableSound sound)
|
||||
{
|
||||
return sound.isDonePlaying() && !getSoundMap().containsKey(sound);
|
||||
}
|
||||
|
||||
public static void playSound(SoundEvent sound)
|
||||
{
|
||||
playSound(PositionedSoundRecord.getMasterRecord(sound, client.baseSoundVolume));
|
||||
}
|
||||
|
||||
public static void playSound(ISound sound)
|
||||
{
|
||||
mc.getSoundHandler().playSound(sound);
|
||||
}
|
||||
public static void playSound(ISound sound)
|
||||
{
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(sound);
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package mekanism.client.sound;
|
||||
|
||||
import mekanism.common.base.IHasSound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TileSound extends MekSound implements IResettableSound
|
||||
{
|
||||
IHasSound source;
|
||||
|
||||
boolean beginFadeOut;
|
||||
|
||||
boolean donePlaying = true;
|
||||
|
||||
int ticks = 0;
|
||||
|
||||
int fadeIn = 30;
|
||||
|
||||
int fadeOut = 10;
|
||||
|
||||
float baseVolume = 1.0F;
|
||||
|
||||
public TileSound(IHasSound source, ISoundSource values)
|
||||
{
|
||||
this(source, values.getSoundLocation(), values.getVolume(), values.getFrequency(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().x, values.getSoundPosition().y, values.getSoundPosition().z);
|
||||
}
|
||||
|
||||
public TileSound(IHasSound source, ISoundSource values, ResourceLocation location)
|
||||
{
|
||||
this(source, location, values.getVolume(), values.getFrequency(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().x, values.getSoundPosition().y, values.getSoundPosition().z);
|
||||
}
|
||||
|
||||
public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
|
||||
{
|
||||
this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
|
||||
}
|
||||
|
||||
public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
|
||||
{
|
||||
this(source, new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
|
||||
}
|
||||
|
||||
public TileSound(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
|
||||
{
|
||||
this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
|
||||
}
|
||||
|
||||
public TileSound(IHasSound soundSource, ResourceLocation resource, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
|
||||
{
|
||||
super(resource, volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
|
||||
|
||||
source = soundSource;
|
||||
soundLocation = resource;
|
||||
baseVolume = volume;
|
||||
}
|
||||
|
||||
public TileSound setFadeIn(int fade)
|
||||
{
|
||||
fadeIn = Math.min(0, fade);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TileSound setFadeOut(int fade)
|
||||
{
|
||||
fadeOut = Math.min(0, fade);
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFadeInMultiplier()
|
||||
{
|
||||
return ticks >= fadeIn ? 1 : (float)(ticks / (float)fadeIn);
|
||||
}
|
||||
|
||||
public float getFadeOutMultiplier()
|
||||
{
|
||||
return ticks >= fadeOut ? 0 : (float)((fadeOut - ticks) / (float)fadeOut);
|
||||
}
|
||||
|
||||
/* ITickableSound */
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if(source instanceof ISoundSource)
|
||||
{
|
||||
baseVolume = ((ISoundSource)source).getVolume();
|
||||
}
|
||||
|
||||
if(!beginFadeOut)
|
||||
{
|
||||
if(ticks < fadeIn)
|
||||
{
|
||||
ticks++;
|
||||
}
|
||||
|
||||
if(!(source.shouldPlaySound() && source.getSound().sound == this))
|
||||
{
|
||||
beginFadeOut = true;
|
||||
ticks = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ticks++;
|
||||
}
|
||||
|
||||
float multiplier = beginFadeOut ? getFadeOutMultiplier() : getFadeInMultiplier();
|
||||
volume = baseVolume * multiplier;
|
||||
|
||||
if(multiplier <= 0)
|
||||
{
|
||||
donePlaying = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDonePlaying()
|
||||
{
|
||||
return donePlaying;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
donePlaying = false;
|
||||
beginFadeOut = false;
|
||||
volume = baseVolume;
|
||||
ticks = 0;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class CommonPlayerTickHandler
|
||||
|
||||
public static boolean isFlamethrowerOn(EntityPlayer player)
|
||||
{
|
||||
if(Mekanism.flamethrowerActive.contains(player.getName()))
|
||||
if(Mekanism.playerState.isFlamethrowerOn(player))
|
||||
{
|
||||
if(!player.inventory.getCurrentItem().isEmpty() && player.inventory.getCurrentItem().getItem() instanceof ItemFlamethrower)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@ import mekanism.common.network.PacketBoxBlacklist.BoxBlacklistMessage;
|
||||
import mekanism.common.network.PacketConfigSync.ConfigSyncMessage;
|
||||
import mekanism.common.network.PacketFreeRunnerData;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackPacket;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
|
||||
import mekanism.common.network.PacketSecurityUpdate.SecurityPacket;
|
||||
@@ -30,8 +29,9 @@ public class CommonPlayerTracker
|
||||
{
|
||||
Mekanism.packetHandler.sendTo(new ConfigSyncMessage(), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(new BoxBlacklistMessage(), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(new JetpackDataMessage(JetpackPacket.FULL, null, false), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(new ScubaTankDataMessage(ScubaTankPacket.FULL, null, false), (EntityPlayerMP)event.player);
|
||||
// TODO: Coalesce all these sync events into a single message
|
||||
Mekanism.packetHandler.sendTo(JetpackDataMessage.FULL(Mekanism.playerState.getActiveJetpacks()), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(ScubaTankDataMessage.FULL(Mekanism.playerState.getActiveGasmasks()), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(new SecurityUpdateMessage(SecurityPacket.FULL, null, null), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(new PacketFreeRunnerData.FreeRunnerDataMessage(PacketFreeRunnerData.FreeRunnerPacket.FULL, null, false), (EntityPlayerMP)event.player);
|
||||
|
||||
@@ -42,24 +42,20 @@ public class CommonPlayerTracker
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogoutEvent(PlayerLoggedOutEvent event)
|
||||
{
|
||||
Mekanism.jetpackOn.remove(event.player.getName());
|
||||
Mekanism.gasmaskOn.remove(event.player.getName());
|
||||
Mekanism.flamethrowerActive.remove(event.player.getName());
|
||||
Mekanism.playerState.clearPlayer(event.player);
|
||||
Mekanism.freeRunnerOn.remove(event.player.getName());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerDimChangedEvent(PlayerChangedDimensionEvent event)
|
||||
{
|
||||
Mekanism.jetpackOn.remove(event.player.getName());
|
||||
Mekanism.gasmaskOn.remove(event.player.getName());
|
||||
Mekanism.flamethrowerActive.remove(event.player.getName());
|
||||
Mekanism.playerState.clearPlayer(event.player);
|
||||
Mekanism.freeRunnerOn.remove(event.player.getName());
|
||||
|
||||
if(!event.player.world.isRemote)
|
||||
{
|
||||
Mekanism.packetHandler.sendTo(new JetpackDataMessage(JetpackPacket.FULL, null, false), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(new ScubaTankDataMessage(ScubaTankPacket.FULL, null, false), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(JetpackDataMessage.FULL(Mekanism.playerState.getActiveJetpacks()), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(ScubaTankDataMessage.FULL(Mekanism.playerState.getActiveGasmasks()), (EntityPlayerMP)event.player);
|
||||
Mekanism.packetHandler.sendTo(new PacketFreeRunnerData.FreeRunnerDataMessage(PacketFreeRunnerData.FreeRunnerPacket.FULL, null, false), (EntityPlayerMP)event.player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
package mekanism.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.MekanismAPI;
|
||||
@@ -41,11 +32,7 @@ import mekanism.common.content.matrix.SynchronizedMatrixData;
|
||||
import mekanism.common.content.tank.SynchronizedTankData;
|
||||
import mekanism.common.content.transporter.PathfinderCache;
|
||||
import mekanism.common.content.transporter.TransporterManager;
|
||||
import mekanism.common.entity.EntityBabySkeleton;
|
||||
import mekanism.common.entity.EntityBalloon;
|
||||
import mekanism.common.entity.EntityFlame;
|
||||
import mekanism.common.entity.EntityObsidianTNT;
|
||||
import mekanism.common.entity.EntityRobit;
|
||||
import mekanism.common.entity.*;
|
||||
import mekanism.common.frequency.Frequency;
|
||||
import mekanism.common.frequency.FrequencyManager;
|
||||
import mekanism.common.integration.IMCHandler;
|
||||
@@ -64,32 +51,7 @@ import mekanism.common.recipe.inputs.ItemStackInput;
|
||||
import mekanism.common.recipe.machines.SmeltingRecipe;
|
||||
import mekanism.common.recipe.outputs.ItemStackOutput;
|
||||
import mekanism.common.security.SecurityFrequency;
|
||||
import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
|
||||
import mekanism.common.tile.TileEntityAmbientAccumulator;
|
||||
import mekanism.common.tile.TileEntityBoundingBlock;
|
||||
import mekanism.common.tile.TileEntityCardboardBox;
|
||||
import mekanism.common.tile.TileEntityChemicalInfuser;
|
||||
import mekanism.common.tile.TileEntityChemicalOxidizer;
|
||||
import mekanism.common.tile.TileEntityChemicalWasher;
|
||||
import mekanism.common.tile.TileEntityElectricPump;
|
||||
import mekanism.common.tile.TileEntityElectrolyticSeparator;
|
||||
import mekanism.common.tile.TileEntityFluidicPlenisher;
|
||||
import mekanism.common.tile.TileEntityFuelwoodHeater;
|
||||
import mekanism.common.tile.TileEntityGlowPanel;
|
||||
import mekanism.common.tile.TileEntityInductionCasing;
|
||||
import mekanism.common.tile.TileEntityInductionCell;
|
||||
import mekanism.common.tile.TileEntityInductionPort;
|
||||
import mekanism.common.tile.TileEntityInductionProvider;
|
||||
import mekanism.common.tile.TileEntityLaser;
|
||||
import mekanism.common.tile.TileEntityLaserAmplifier;
|
||||
import mekanism.common.tile.TileEntityLaserTractorBeam;
|
||||
import mekanism.common.tile.TileEntityOredictionificator;
|
||||
import mekanism.common.tile.TileEntityPressureDisperser;
|
||||
import mekanism.common.tile.TileEntityRotaryCondensentrator;
|
||||
import mekanism.common.tile.TileEntityStructuralGlass;
|
||||
import mekanism.common.tile.TileEntitySuperheatingElement;
|
||||
import mekanism.common.tile.TileEntityThermalEvaporationBlock;
|
||||
import mekanism.common.tile.TileEntityThermalEvaporationValve;
|
||||
import mekanism.common.tile.*;
|
||||
import mekanism.common.transmitters.grid.EnergyNetwork.EnergyTransferEvent;
|
||||
import mekanism.common.transmitters.grid.FluidNetwork.FluidTransferEvent;
|
||||
import mekanism.common.transmitters.grid.GasNetwork.GasTransferEvent;
|
||||
@@ -129,23 +91,18 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
||||
import net.minecraftforge.fml.common.event.*;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Mekanism - a Minecraft mod
|
||||
@@ -237,12 +194,11 @@ public class Mekanism
|
||||
public static GameProfile gameProfile = new GameProfile(UUID.nameUUIDFromBytes("mekanism.common".getBytes()), "[Mekanism]");
|
||||
|
||||
public static KeySync keyMap = new KeySync();
|
||||
|
||||
public static final Set<String> jetpackOn = new HashSet<>();
|
||||
public static final Set<String> gasmaskOn = new HashSet<>();
|
||||
|
||||
public static final PlayerState playerState = new PlayerState();
|
||||
|
||||
public static final Set<String> freeRunnerOn = new HashSet<>();
|
||||
public static final Set<String> flamethrowerActive = new HashSet<>();
|
||||
|
||||
|
||||
public static Set<Coord4D> activeVibrators = new HashSet<>();
|
||||
|
||||
static {
|
||||
@@ -678,8 +634,7 @@ public class Mekanism
|
||||
public void serverStopping(FMLServerStoppingEvent event)
|
||||
{
|
||||
//Clear all cache data
|
||||
jetpackOn.clear();
|
||||
gasmaskOn.clear();
|
||||
playerState.clear();
|
||||
activeVibrators.clear();
|
||||
worldTickHandler.resetRegenChunks();
|
||||
privateTeleporters.clear();
|
||||
@@ -1005,6 +960,11 @@ public class Mekanism
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldLoad(WorldEvent.Load event) {
|
||||
playerState.init(event.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldUnload(WorldEvent.Unload event) {
|
||||
// Make sure the global fake player drops its reference to the World
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
package mekanism.common;
|
||||
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.config.MekanismConfig;
|
||||
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerDataMessage;
|
||||
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerPacket;
|
||||
import mekanism.common.network.PacketJetpackData;
|
||||
import mekanism.common.network.PacketScubaTankData;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlayerState {
|
||||
|
||||
private Set<String> activeJetpacks = new HashSet<>();
|
||||
private Set<String> activeGasmasks = new HashSet<>();
|
||||
private Set<String> activeFlamethrowers = new HashSet<>();
|
||||
|
||||
private World world;
|
||||
|
||||
public void clear() {
|
||||
activeJetpacks.clear();
|
||||
activeGasmasks.clear();
|
||||
activeFlamethrowers.clear();
|
||||
};
|
||||
|
||||
public void clearPlayer(EntityPlayer p) {
|
||||
activeJetpacks.remove(p.getName());
|
||||
activeGasmasks.remove(p.getName());
|
||||
activeFlamethrowers.remove(p.getName());
|
||||
}
|
||||
|
||||
public void init(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private boolean isLocalPlayer(String playerId) {
|
||||
return Minecraft.getMinecraft().player.getName().equals(playerId);
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
//
|
||||
// Jetpack state tracking
|
||||
//
|
||||
// ----------------------
|
||||
|
||||
public void setJetpackState(String playerId, boolean isActive) {
|
||||
boolean alreadyActive = activeJetpacks.contains(playerId);
|
||||
boolean changed = (alreadyActive != isActive);
|
||||
|
||||
if (alreadyActive && !isActive) {
|
||||
// On -> off
|
||||
activeJetpacks.remove(playerId);
|
||||
} else if (!alreadyActive && isActive) {
|
||||
// Off -> on
|
||||
activeJetpacks.add(playerId);
|
||||
}
|
||||
|
||||
// If something changed and we're in a remote world, take appropriate action
|
||||
if (changed && world.isRemote) {
|
||||
// If the player is the "local" player, we need to tell the server the state has changed
|
||||
if (isLocalPlayer(playerId)) {
|
||||
Mekanism.packetHandler.sendToServer(PacketJetpackData.JetpackDataMessage.UPDATE(playerId, isActive));
|
||||
}
|
||||
|
||||
// Start a sound playing if the person is now flying
|
||||
if (isActive && MekanismConfig.client.enablePlayerSounds) {
|
||||
SoundHandler.startSound(world.getPlayerEntityByName(playerId), "jetpack");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setActiveJetpacks(Set<String> newActiveJetpacks) {
|
||||
for (String activeUser: newActiveJetpacks) {
|
||||
setJetpackState(activeUser, true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isJetpackOn(EntityPlayer p) {
|
||||
return activeJetpacks.contains(p.getName());
|
||||
}
|
||||
|
||||
public Set<String> getActiveJetpacks() {
|
||||
return activeJetpacks;
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
//
|
||||
// Gasmask state tracking
|
||||
//
|
||||
// ----------------------
|
||||
|
||||
public void setGasmaskState(String playerId, boolean isActive) {
|
||||
boolean alreadyActive = activeGasmasks.contains(playerId);
|
||||
boolean changed = (alreadyActive != isActive);
|
||||
|
||||
if (alreadyActive && !isActive) {
|
||||
activeGasmasks.remove(playerId); // On -> off
|
||||
} else if (!alreadyActive && isActive) {
|
||||
activeGasmasks.add(playerId); // Off -> on
|
||||
}
|
||||
|
||||
// If something changed and we're in a remote world, take appropriate action
|
||||
if (changed && world.isRemote) {
|
||||
// If the player is the "local" player, we need to tell the server the state has changed
|
||||
if (isLocalPlayer(playerId)) {
|
||||
Mekanism.packetHandler.sendToServer(PacketScubaTankData.ScubaTankDataMessage.UPDATE(playerId, isActive));
|
||||
}
|
||||
|
||||
// Start a sound playing if the person is now using a gasmask
|
||||
if (isActive && MekanismConfig.client.enablePlayerSounds) {
|
||||
SoundHandler.startSound(world.getPlayerEntityByName(playerId), "gasmask");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setActiveGasmasks(Set<String> newActiveGasmasks) {
|
||||
for (String activeUser: newActiveGasmasks) {
|
||||
setGasmaskState(activeUser, true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGasmaskOn(EntityPlayer p) {
|
||||
return activeGasmasks.contains(p.getName());
|
||||
}
|
||||
|
||||
public Set<String> getActiveGasmasks() {
|
||||
return activeGasmasks;
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
//
|
||||
// Flamethrower state tracking
|
||||
//
|
||||
// ----------------------
|
||||
|
||||
public void setFlamethrowerState(String playerId, boolean isActive) {
|
||||
boolean alreadyActive = activeFlamethrowers.contains(playerId);
|
||||
boolean changed = (alreadyActive != isActive);
|
||||
|
||||
if (alreadyActive && !isActive) {
|
||||
activeFlamethrowers.remove(playerId); // On -> off
|
||||
} else if (!alreadyActive && isActive) {
|
||||
activeFlamethrowers.add(playerId); // Off -> on
|
||||
}
|
||||
|
||||
// If something changed and we're in a remote world, take appropriate action
|
||||
if (changed && world.isRemote) {
|
||||
// If the player is the "local" player, we need to tell the server the state has changed
|
||||
if (isLocalPlayer(playerId)) {
|
||||
Mekanism.packetHandler.sendToServer(new FlamethrowerDataMessage(FlamethrowerPacket.UPDATE, null,
|
||||
playerId, isActive));
|
||||
}
|
||||
|
||||
// Start a sound playing if the person is now using a flamethrower
|
||||
if (isActive && MekanismConfig.client.enablePlayerSounds) {
|
||||
SoundHandler.startSound(world.getPlayerEntityByName(playerId), "flamethrower");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFlamethrowerOn(EntityPlayer p) {
|
||||
return activeFlamethrowers.contains(p.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
|
||||
/**
|
||||
* Internal interface for managing various Factory types.
|
||||
@@ -66,7 +67,7 @@ public interface IFactory
|
||||
INFUSING("Infusing", "metalinfuser", MachineType.METALLURGIC_INFUSER, MachineFuelType.BASIC, false, Recipe.METALLURGIC_INFUSER);
|
||||
|
||||
private String name;
|
||||
private ResourceLocation sound;
|
||||
private SoundEvent sound;
|
||||
private MachineType type;
|
||||
private MachineFuelType fuelType;
|
||||
private boolean fuelSpeed;
|
||||
@@ -280,7 +281,7 @@ public interface IFactory
|
||||
return LangUtils.localize("gui.factory." + name);
|
||||
}
|
||||
|
||||
public ResourceLocation getSound()
|
||||
public SoundEvent getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
@@ -316,7 +317,7 @@ public interface IFactory
|
||||
RecipeType(String s, String s1, MachineType t, MachineFuelType ft, boolean b1, Recipe r)
|
||||
{
|
||||
name = s;
|
||||
sound = new ResourceLocation("mekanism", "tile.machine." + s1);
|
||||
sound = new SoundEvent(new ResourceLocation("mekanism", "tile.machine." + s1));
|
||||
type = t;
|
||||
fuelType = ft;
|
||||
fuelSpeed = b1;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package mekanism.common.base;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Implement this if your TileEntity has a specific sound.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface IHasSound
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
SoundWrapper getSound();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
boolean shouldPlaySound();
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package mekanism.common.base;
|
||||
|
||||
import mekanism.client.sound.IResettableSound;
|
||||
import mekanism.client.sound.ISoundSource;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.client.sound.TileSound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class SoundWrapper
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IResettableSound sound;
|
||||
|
||||
public SoundWrapper(IHasSound tile, ISoundSource source)
|
||||
{
|
||||
try {
|
||||
sound = new TileSound(tile, source);
|
||||
} catch(Throwable t) {}
|
||||
}
|
||||
|
||||
public SoundWrapper(IHasSound tile, ISoundSource source, ResourceLocation location)
|
||||
{
|
||||
try {
|
||||
sound = new TileSound(tile, source, location);
|
||||
} catch(Throwable t) {}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void reset()
|
||||
{
|
||||
sound.reset();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void play()
|
||||
{
|
||||
SoundHandler.playSound(sound);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean canRestart()
|
||||
{
|
||||
return SoundHandler.canRestartSound(sound);
|
||||
}
|
||||
}
|
||||
@@ -204,7 +204,7 @@ public abstract class BlockMachine extends BlockContainer
|
||||
|
||||
if(tile instanceof TileEntityFactory)
|
||||
{
|
||||
state = state.withProperty(BlockStateMachine.recipeProperty, ((TileEntityFactory)tile).recipeType);
|
||||
state = state.withProperty(BlockStateMachine.recipeProperty, ((TileEntityFactory)tile).getRecipeType());
|
||||
}
|
||||
|
||||
return state;
|
||||
@@ -917,7 +917,7 @@ public abstract class BlockMachine extends BlockContainer
|
||||
if(tileEntity instanceof TileEntityFactory)
|
||||
{
|
||||
IFactory factoryItem = (IFactory)itemStack.getItem();
|
||||
factoryItem.setRecipeType(((TileEntityFactory)tileEntity).recipeType.ordinal(), itemStack);
|
||||
factoryItem.setRecipeType(((TileEntityFactory)tileEntity).getRecipeType().ordinal(), itemStack);
|
||||
}
|
||||
|
||||
//this MUST be done after the factory info is saved, as it caps the energy to max, which is based on the recipe type
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ContainerFactory extends Container
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
else if(tileEntity.recipeType.getAnyRecipe(slotStack, inventorySlots.get(4).getStack(), tileEntity.gasTank.getGasType(), tileEntity.infuseStored) != null)
|
||||
else if(tileEntity.getRecipeType().getAnyRecipe(slotStack, inventorySlots.get(4).getStack(), tileEntity.gasTank.getGasType(), tileEntity.infuseStored) != null)
|
||||
{
|
||||
if(!isInputSlot(slotID))
|
||||
{
|
||||
@@ -177,7 +177,7 @@ public class ContainerFactory extends Container
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(tileEntity.recipeType.getItemGas(slotStack) != null)
|
||||
else if(tileEntity.getRecipeType().getItemGas(slotStack) != null)
|
||||
{
|
||||
if(slotID >= tileEntity.inventory.size()-1)
|
||||
{
|
||||
@@ -193,7 +193,7 @@ public class ContainerFactory extends Container
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(tileEntity.recipeType == RecipeType.INFUSING && InfuseRegistry.getObject(slotStack) != null && (tileEntity.infuseStored.type == null || tileEntity.infuseStored.type == InfuseRegistry.getObject(slotStack).type))
|
||||
else if(tileEntity.getRecipeType() == RecipeType.INFUSING && InfuseRegistry.getObject(slotStack) != null && (tileEntity.infuseStored.type == null || tileEntity.infuseStored.type == InfuseRegistry.getObject(slotStack).type))
|
||||
{
|
||||
if(slotID >= tileEntity.inventory.size()-1)
|
||||
{
|
||||
|
||||
@@ -18,35 +18,22 @@ public class PacketFlamethrowerData implements IMessageHandler<FlamethrowerDataM
|
||||
public IMessage onMessage(FlamethrowerDataMessage message, MessageContext context)
|
||||
{
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
|
||||
PacketHandler.handlePacket(() ->
|
||||
{
|
||||
if(message.packetType == FlamethrowerPacket.UPDATE)
|
||||
{
|
||||
if(message.value)
|
||||
{
|
||||
Mekanism.flamethrowerActive.add(message.username);
|
||||
}
|
||||
else {
|
||||
Mekanism.flamethrowerActive.remove(message.username);
|
||||
}
|
||||
|
||||
if(!player.world.isRemote)
|
||||
{
|
||||
Mekanism.packetHandler.sendToDimension(new FlamethrowerDataMessage(FlamethrowerPacket.UPDATE, message.currentHand, message.username, message.value), player.world.provider.getDimension());
|
||||
}
|
||||
}
|
||||
else if(message.packetType == FlamethrowerPacket.MODE)
|
||||
{
|
||||
ItemStack stack = player.getHeldItem(message.currentHand);
|
||||
if (message.packetType == FlamethrowerPacket.UPDATE) {
|
||||
Mekanism.playerState.setFlamethrowerState(message.username, message.value);
|
||||
|
||||
// If we got this packet on the server, resend out to all clients in same dimension
|
||||
// TODO: Why is this a dimensional thing?!
|
||||
if (!player.world.isRemote) {
|
||||
Mekanism.packetHandler.sendToDimension(message, player.world.provider.getDimension());
|
||||
}
|
||||
} else if (message.packetType == FlamethrowerPacket.MODE) {
|
||||
ItemStack stack = player.getHeldItem(message.currentHand);
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemFlamethrower) {
|
||||
((ItemFlamethrower) stack.getItem()).incrementMode(stack);
|
||||
}
|
||||
}
|
||||
|
||||
if(!stack.isEmpty() && stack.getItem() instanceof ItemFlamethrower)
|
||||
{
|
||||
((ItemFlamethrower)stack.getItem()).incrementMode(stack);
|
||||
}
|
||||
}
|
||||
}, player);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,94 +13,91 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PacketJetpackData implements IMessageHandler<JetpackDataMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(JetpackDataMessage message, MessageContext context)
|
||||
{
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
|
||||
PacketHandler.handlePacket(() ->
|
||||
{
|
||||
if(message.packetType == JetpackPacket.UPDATE)
|
||||
{
|
||||
if(message.value)
|
||||
{
|
||||
Mekanism.jetpackOn.add(message.username);
|
||||
}
|
||||
else {
|
||||
Mekanism.jetpackOn.remove(message.username);
|
||||
}
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
|
||||
if(!player.world.isRemote)
|
||||
{
|
||||
Mekanism.packetHandler.sendToDimension(new JetpackDataMessage(JetpackPacket.UPDATE, message.username, message.value), player.world.provider.getDimension());
|
||||
if (message.packetType == JetpackPacket.UPDATE) {
|
||||
Mekanism.playerState.setJetpackState(message.username, message.value);
|
||||
|
||||
// If we got this packet on the server, propagate it out to all players in the same dimension
|
||||
// TODO: Why is this a dimensional thing?!
|
||||
if (!player.world.isRemote) {
|
||||
Mekanism.packetHandler.sendToDimension(message, player.world.provider.getDimension());
|
||||
}
|
||||
} else if (message.packetType == JetpackPacket.MODE) {
|
||||
// Use has changed the mode of their jetpack; update it
|
||||
ItemStack stack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemJetpack) {
|
||||
if (!message.value) {
|
||||
((ItemJetpack) stack.getItem()).incrementMode(stack);
|
||||
} else {
|
||||
((ItemJetpack) stack.getItem()).setMode(stack, JetpackMode.DISABLED);
|
||||
}
|
||||
}
|
||||
else if(message.packetType == JetpackPacket.MODE)
|
||||
{
|
||||
ItemStack stack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
} else if (message.packetType == JetpackPacket.FULL) {
|
||||
// This is a full sync; merge it into our player state
|
||||
Mekanism.playerState.setActiveJetpacks(message.activeJetpacks);
|
||||
}
|
||||
|
||||
if(!stack.isEmpty() && stack.getItem() instanceof ItemJetpack)
|
||||
{
|
||||
if(!message.value)
|
||||
{
|
||||
((ItemJetpack)stack.getItem()).incrementMode(stack);
|
||||
}
|
||||
else {
|
||||
((ItemJetpack)stack.getItem()).setMode(stack, JetpackMode.DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, player);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class JetpackDataMessage implements IMessage
|
||||
{
|
||||
public JetpackPacket packetType;
|
||||
|
||||
public String username;
|
||||
public boolean value;
|
||||
protected JetpackPacket packetType;
|
||||
|
||||
protected Set<String> activeJetpacks;
|
||||
|
||||
protected String username;
|
||||
protected boolean value;
|
||||
|
||||
public JetpackDataMessage() {}
|
||||
|
||||
public JetpackDataMessage(JetpackPacket type, String name, boolean state)
|
||||
{
|
||||
|
||||
public JetpackDataMessage(JetpackPacket type) {
|
||||
packetType = type;
|
||||
value = state;
|
||||
|
||||
if(packetType == JetpackPacket.UPDATE)
|
||||
{
|
||||
username = name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static JetpackDataMessage MODE_CHANGE(boolean change) {
|
||||
JetpackDataMessage m = new JetpackDataMessage(JetpackPacket.MODE);
|
||||
m.value = change;
|
||||
return m;
|
||||
}
|
||||
|
||||
public static JetpackDataMessage UPDATE(String name, boolean state) {
|
||||
JetpackDataMessage m = new JetpackDataMessage(JetpackPacket.UPDATE);
|
||||
m.username = name;
|
||||
m.value = state;
|
||||
return m;
|
||||
}
|
||||
|
||||
public static JetpackDataMessage FULL(Set<String> activeNames) {
|
||||
JetpackDataMessage m = new JetpackDataMessage(JetpackPacket.FULL);
|
||||
m.activeJetpacks = activeNames;
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf dataStream)
|
||||
{
|
||||
public void toBytes(ByteBuf dataStream) {
|
||||
dataStream.writeInt(packetType.ordinal());
|
||||
|
||||
if(packetType == JetpackPacket.MODE)
|
||||
{
|
||||
if(packetType == JetpackPacket.MODE) {
|
||||
dataStream.writeBoolean(value);
|
||||
}
|
||||
else if(packetType == JetpackPacket.UPDATE)
|
||||
{
|
||||
else if(packetType == JetpackPacket.UPDATE) {
|
||||
PacketHandler.writeString(dataStream, username);
|
||||
dataStream.writeBoolean(value);
|
||||
}
|
||||
else if(packetType == JetpackPacket.FULL)
|
||||
{
|
||||
dataStream.writeInt(Mekanism.jetpackOn.size());
|
||||
|
||||
synchronized(Mekanism.jetpackOn)
|
||||
{
|
||||
for(String username : Mekanism.jetpackOn)
|
||||
{
|
||||
PacketHandler.writeString(dataStream, username);
|
||||
}
|
||||
else if(packetType == JetpackPacket.FULL) {
|
||||
dataStream.writeInt(activeJetpacks.size());
|
||||
for(String username : activeJetpacks) {
|
||||
PacketHandler.writeString(dataStream, username);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,24 +107,19 @@ public class PacketJetpackData implements IMessageHandler<JetpackDataMessage, IM
|
||||
{
|
||||
packetType = JetpackPacket.values()[dataStream.readInt()];
|
||||
|
||||
if(packetType == JetpackPacket.MODE)
|
||||
{
|
||||
if(packetType == JetpackPacket.MODE) {
|
||||
value = dataStream.readBoolean();
|
||||
}
|
||||
else if(packetType == JetpackPacket.UPDATE)
|
||||
{
|
||||
else if(packetType == JetpackPacket.UPDATE) {
|
||||
username = PacketHandler.readString(dataStream);
|
||||
value = dataStream.readBoolean();
|
||||
}
|
||||
else if(packetType == JetpackPacket.FULL)
|
||||
{
|
||||
Mekanism.jetpackOn.clear();
|
||||
else if(packetType == JetpackPacket.FULL) {
|
||||
activeJetpacks = new HashSet<>();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
Mekanism.jetpackOn.add(PacketHandler.readString(dataStream));
|
||||
for(int i = 0; i < amount; i++) {
|
||||
activeJetpacks.add(PacketHandler.readString(dataStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PacketScubaTankData implements IMessageHandler<ScubaTankDataMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
@@ -19,74 +22,78 @@ public class PacketScubaTankData implements IMessageHandler<ScubaTankDataMessage
|
||||
{
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
|
||||
if(message.packetType == ScubaTankPacket.UPDATE)
|
||||
{
|
||||
if(message.value)
|
||||
{
|
||||
Mekanism.gasmaskOn.add(message.username);
|
||||
}
|
||||
else {
|
||||
Mekanism.gasmaskOn.remove(message.username);
|
||||
}
|
||||
if(message.packetType == ScubaTankPacket.UPDATE) {
|
||||
Mekanism.playerState.setGasmaskState(message.username, message.value);
|
||||
|
||||
if(!player.world.isRemote)
|
||||
{
|
||||
Mekanism.packetHandler.sendToDimension(new ScubaTankDataMessage(ScubaTankPacket.UPDATE, message.username, message.value), player.world.provider.getDimension());
|
||||
// If we got this on the server, relay out to all players in the same dimension
|
||||
// TODO: Why is this a dimensional thing?!
|
||||
if(!player.world.isRemote) {
|
||||
Mekanism.packetHandler.sendToDimension(message, player.world.provider.getDimension());
|
||||
}
|
||||
}
|
||||
else if(message.packetType == ScubaTankPacket.MODE)
|
||||
{
|
||||
else if(message.packetType == ScubaTankPacket.MODE) {
|
||||
// Use has changed the mode of their gasmask; update it
|
||||
ItemStack stack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
|
||||
if(!stack.isEmpty() && stack.getItem() instanceof ItemScubaTank)
|
||||
{
|
||||
if(!stack.isEmpty() && stack.getItem() instanceof ItemScubaTank) {
|
||||
((ItemScubaTank)stack.getItem()).toggleFlowing(stack);
|
||||
}
|
||||
}
|
||||
else if (message.packetType == ScubaTankPacket.FULL) {
|
||||
// This is a full sync; merge into our player state
|
||||
Mekanism.playerState.setActiveGasmasks(message.activeGasmasks);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class ScubaTankDataMessage implements IMessage
|
||||
{
|
||||
public ScubaTankPacket packetType;
|
||||
protected ScubaTankPacket packetType;
|
||||
|
||||
protected Set<String> activeGasmasks;
|
||||
|
||||
public String username;
|
||||
public boolean value;
|
||||
protected String username;
|
||||
protected boolean value;
|
||||
|
||||
public ScubaTankDataMessage() {}
|
||||
|
||||
public ScubaTankDataMessage(ScubaTankPacket type, String name, boolean state)
|
||||
{
|
||||
packetType = type;
|
||||
|
||||
if(packetType == ScubaTankPacket.UPDATE)
|
||||
{
|
||||
username = name;
|
||||
value = state;
|
||||
}
|
||||
|
||||
public ScubaTankDataMessage(ScubaTankPacket type) { packetType = type; }
|
||||
|
||||
public static ScubaTankDataMessage MODE_CHANGE(boolean change) {
|
||||
ScubaTankDataMessage m = new ScubaTankDataMessage(ScubaTankPacket.MODE);
|
||||
m.value = change;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
public static ScubaTankDataMessage UPDATE(String name, boolean state) {
|
||||
ScubaTankDataMessage m = new ScubaTankDataMessage(ScubaTankPacket.UPDATE);
|
||||
m.username = name;
|
||||
m.value = state;
|
||||
return m;
|
||||
}
|
||||
|
||||
public static ScubaTankDataMessage FULL(Set<String> activeNames) {
|
||||
ScubaTankDataMessage m = new ScubaTankDataMessage((ScubaTankPacket.FULL));
|
||||
m.activeGasmasks = activeNames;
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf dataStream)
|
||||
{
|
||||
dataStream.writeInt(packetType.ordinal());
|
||||
|
||||
if(packetType == ScubaTankPacket.UPDATE)
|
||||
{
|
||||
|
||||
if (packetType == ScubaTankPacket.MODE) {
|
||||
dataStream.writeBoolean(value);
|
||||
}
|
||||
else if(packetType == ScubaTankPacket.UPDATE) {
|
||||
PacketHandler.writeString(dataStream, username);
|
||||
dataStream.writeBoolean(value);
|
||||
}
|
||||
else if(packetType == ScubaTankPacket.FULL)
|
||||
{
|
||||
dataStream.writeInt(Mekanism.gasmaskOn.size());
|
||||
|
||||
synchronized(Mekanism.gasmaskOn)
|
||||
{
|
||||
for (String name : Mekanism.gasmaskOn)
|
||||
{
|
||||
PacketHandler.writeString(dataStream, name);
|
||||
}
|
||||
else if(packetType == ScubaTankPacket.FULL) {
|
||||
dataStream.writeInt(activeGasmasks.size());
|
||||
for (String name : activeGasmasks) {
|
||||
PacketHandler.writeString(dataStream, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,23 +102,22 @@ public class PacketScubaTankData implements IMessageHandler<ScubaTankDataMessage
|
||||
public void fromBytes(ByteBuf dataStream)
|
||||
{
|
||||
packetType = ScubaTankPacket.values()[dataStream.readInt()];
|
||||
|
||||
if(packetType == ScubaTankPacket.FULL)
|
||||
{
|
||||
Mekanism.gasmaskOn.clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
Mekanism.gasmaskOn.add(PacketHandler.readString(dataStream));
|
||||
}
|
||||
|
||||
if (packetType == ScubaTankPacket.MODE) {
|
||||
value = dataStream.readBoolean();
|
||||
}
|
||||
else if(packetType == ScubaTankPacket.UPDATE)
|
||||
{
|
||||
else if(packetType == ScubaTankPacket.UPDATE) {
|
||||
username = PacketHandler.readString(dataStream);
|
||||
value = dataStream.readBoolean();
|
||||
}
|
||||
else if(packetType == ScubaTankPacket.FULL) {
|
||||
activeGasmasks = new HashSet<>();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
for(int i = 0; i < amount; i++) {
|
||||
activeGasmasks.add(PacketHandler.readString(dataStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -244,8 +244,7 @@ public class TileEntityChargepad extends TileEntityNoisyBlock
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getVolume()
|
||||
protected float getVolume()
|
||||
{
|
||||
return 0.4F*super.getVolume();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import mekanism.common.base.IFactory.RecipeType;
|
||||
import mekanism.common.base.ISideConfiguration;
|
||||
import mekanism.common.base.ISustainedData;
|
||||
import mekanism.common.base.ITierUpgradeable;
|
||||
import mekanism.common.base.SoundWrapper;
|
||||
import mekanism.common.base.TileNetworkList;
|
||||
import mekanism.common.block.states.BlockStateMachine;
|
||||
import mekanism.common.block.states.BlockStateMachine.MachineType;
|
||||
@@ -102,8 +101,8 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
/** How many recipe ticks have progressed. */
|
||||
public int recipeTicks;
|
||||
|
||||
/** This machine's recipe type. */
|
||||
public RecipeType recipeType = RecipeType.SMELTING;
|
||||
/** This machine's recipe type. */
|
||||
private RecipeType recipeType = RecipeType.SMELTING;
|
||||
|
||||
private final MachineRecipe[] cachedRecipe;
|
||||
|
||||
@@ -118,9 +117,6 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
|
||||
public double lastUsage;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public SoundWrapper[] sounds;
|
||||
|
||||
/** This machine's current RedstoneControl type. */
|
||||
public RedstoneControl controlType = RedstoneControl.DISABLED;
|
||||
|
||||
@@ -191,12 +187,8 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
|
||||
//Electric
|
||||
factory.electricityStored = electricityStored;
|
||||
|
||||
//Noisy
|
||||
factory.soundURL = soundURL;
|
||||
|
||||
//Factory
|
||||
|
||||
//Factory
|
||||
System.arraycopy(progress, 0, factory.progress, 0, tier.processes);
|
||||
|
||||
factory.recipeTicks = recipeTicks;
|
||||
@@ -390,9 +382,17 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
{
|
||||
recalculateUpgradables(upgrade);
|
||||
}
|
||||
|
||||
if (world.isRemote) {
|
||||
setSoundEvent(type.getSound());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public RecipeType getRecipeType() {
|
||||
return recipeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sideIsConsumer(EnumFacing side)
|
||||
{
|
||||
return configComponent.hasSideForData(TransmissionType.ENERGY, facing, 1, side);
|
||||
@@ -1009,25 +1009,6 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
return facing;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public SoundWrapper getSound()
|
||||
{
|
||||
return sounds[recipeType.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void initSounds()
|
||||
{
|
||||
sounds = new SoundWrapper[RecipeType.values().length];
|
||||
|
||||
for(RecipeType type : RecipeType.values())
|
||||
{
|
||||
sounds[type.ordinal()] = new SoundWrapper(this, this, HolidayManager.filterSound(type.getSound()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileComponentEjector getEjector()
|
||||
{
|
||||
|
||||
@@ -164,9 +164,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i
|
||||
//Electric
|
||||
factory.electricityStored = electricityStored;
|
||||
|
||||
//Noisy
|
||||
factory.soundURL = soundURL;
|
||||
|
||||
//Machine
|
||||
factory.progress[0] = operatingTicks;
|
||||
factory.clientActive = clientActive;
|
||||
@@ -178,7 +175,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i
|
||||
factory.upgradeComponent.setUpgradeSlot(0);
|
||||
factory.ejectorComponent.readFrom(ejectorComponent);
|
||||
factory.ejectorComponent.setOutputData(TransmissionType.ITEM, factory.configComponent.getOutputs(TransmissionType.ITEM).get(2));
|
||||
factory.recipeType = type;
|
||||
factory.setRecipeType(type);
|
||||
factory.upgradeComponent.setSupported(Upgrade.GAS, type.fuelEnergyUpgrades());
|
||||
factory.securityComponent.readFrom(securityComponent);
|
||||
|
||||
|
||||
@@ -125,9 +125,6 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
|
||||
//Electric
|
||||
factory.electricityStored = electricityStored;
|
||||
|
||||
//Noisy
|
||||
factory.soundURL = soundURL;
|
||||
|
||||
//Machine
|
||||
factory.progress[0] = operatingTicks;
|
||||
factory.updateDelay = updateDelay;
|
||||
@@ -139,7 +136,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
|
||||
factory.upgradeComponent.setUpgradeSlot(0);
|
||||
factory.ejectorComponent.readFrom(ejectorComponent);
|
||||
factory.ejectorComponent.setOutputData(TransmissionType.ITEM, factory.configComponent.getOutputs(TransmissionType.ITEM).get(2));
|
||||
factory.recipeType = type;
|
||||
factory.setRecipeType(type);
|
||||
factory.upgradeComponent.setSupported(Upgrade.GAS, type.fuelEnergyUpgrades());
|
||||
factory.securityComponent.readFrom(securityComponent);
|
||||
|
||||
|
||||
@@ -82,9 +82,6 @@ public abstract class TileEntityDoubleElectricMachine<RECIPE extends DoubleMachi
|
||||
//Electric
|
||||
factory.electricityStored = electricityStored;
|
||||
|
||||
//Noisy
|
||||
factory.soundURL = soundURL;
|
||||
|
||||
//Machine
|
||||
factory.progress[0] = operatingTicks;
|
||||
factory.updateDelay = updateDelay;
|
||||
@@ -96,7 +93,7 @@ public abstract class TileEntityDoubleElectricMachine<RECIPE extends DoubleMachi
|
||||
factory.upgradeComponent.setUpgradeSlot(0);
|
||||
factory.ejectorComponent.readFrom(ejectorComponent);
|
||||
factory.ejectorComponent.setOutputData(TransmissionType.ITEM, factory.configComponent.getOutputs(TransmissionType.ITEM).get(2));
|
||||
factory.recipeType = type;
|
||||
factory.setRecipeType(type);
|
||||
factory.upgradeComponent.setSupported(Upgrade.GAS, type.fuelEnergyUpgrades());
|
||||
factory.securityComponent.readFrom(securityComponent);
|
||||
|
||||
|
||||
@@ -81,9 +81,6 @@ public abstract class TileEntityElectricMachine<RECIPE extends BasicMachineRecip
|
||||
//Electric
|
||||
factory.electricityStored = electricityStored;
|
||||
|
||||
//Noisy
|
||||
factory.soundURL = soundURL;
|
||||
|
||||
//Machine
|
||||
factory.progress[0] = operatingTicks;
|
||||
factory.clientActive = clientActive;
|
||||
@@ -95,7 +92,7 @@ public abstract class TileEntityElectricMachine<RECIPE extends BasicMachineRecip
|
||||
factory.upgradeComponent.setUpgradeSlot(0);
|
||||
factory.ejectorComponent.readFrom(ejectorComponent);
|
||||
factory.ejectorComponent.setOutputData(TransmissionType.ITEM, factory.configComponent.getOutputs(TransmissionType.ITEM).get(2));
|
||||
factory.recipeType = type;
|
||||
factory.setRecipeType(type);
|
||||
factory.upgradeComponent.setSupported(Upgrade.GAS, type.fuelEnergyUpgrades());
|
||||
factory.securityComponent.readFrom(securityComponent);
|
||||
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
package mekanism.common.tile.prefab;
|
||||
|
||||
import mekanism.client.HolidayManager;
|
||||
import mekanism.client.sound.ISoundSource;
|
||||
import mekanism.common.Upgrade;
|
||||
import mekanism.common.base.IActiveState;
|
||||
import mekanism.common.base.IHasSound;
|
||||
import mekanism.common.base.IUpgradeTile;
|
||||
import mekanism.common.base.SoundWrapper;
|
||||
import mekanism.common.config.MekanismConfig.client;
|
||||
import net.minecraft.client.audio.ISound.AttenuationType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class TileEntityNoisyBlock extends TileEntityElectricBlock implements IHasSound, ISoundSource, IActiveState
|
||||
public abstract class TileEntityNoisyBlock extends TileEntityElectricBlock implements IActiveState
|
||||
{
|
||||
/** The ResourceLocation of the machine's sound */
|
||||
public ResourceLocation soundURL;
|
||||
private SoundEvent soundEvent;
|
||||
|
||||
/** The bundled URL of this machine's sound effect */
|
||||
@SideOnly(Side.CLIENT)
|
||||
public SoundWrapper sound;
|
||||
|
||||
/** The path of this machine's sound */
|
||||
public String soundPath;
|
||||
private ISound activeSound;
|
||||
|
||||
/**
|
||||
* The base of all blocks that deal with electricity and make noise.
|
||||
@@ -36,98 +30,53 @@ public abstract class TileEntityNoisyBlock extends TileEntityElectricBlock imple
|
||||
public TileEntityNoisyBlock(String sound, String name, double maxEnergy)
|
||||
{
|
||||
super(name, maxEnergy);
|
||||
|
||||
soundPath = sound;
|
||||
|
||||
// TODO: Have subclasses pass in a static SoundEvent so we avoid per-instance # of SoundEvents for same sound
|
||||
soundEvent = new SoundEvent(new ResourceLocation("mekanism", "tile." + sound));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public SoundWrapper getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldPlaySound()
|
||||
{
|
||||
return getActive() && !isInvalid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ResourceLocation getSoundLocation()
|
||||
{
|
||||
return soundURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getVolume()
|
||||
protected float getVolume()
|
||||
{
|
||||
if(this instanceof IUpgradeTile && ((IUpgradeTile)this).getComponent().supports(Upgrade.MUFFLING))
|
||||
{
|
||||
return Math.max(0.001F, 1F - (float)((IUpgradeTile)this).getComponent().getUpgrades(Upgrade.MUFFLING)/(float)Upgrade.MUFFLING.getMax());
|
||||
}
|
||||
|
||||
return 1F;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
// Protected way for subclasses to swap out a sound
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getFrequency()
|
||||
{
|
||||
return 1F;
|
||||
}
|
||||
protected void setSoundEvent(SoundEvent event) {
|
||||
this.soundEvent = event;
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Vec3d getSoundPosition()
|
||||
{
|
||||
return new Vec3d(getPos()).add(0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldRepeat()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getRepeatDelay()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AttenuationType getAttenuation()
|
||||
{
|
||||
return AttenuationType.LINEAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate()
|
||||
{
|
||||
super.validate();
|
||||
|
||||
if(world.isRemote)
|
||||
{
|
||||
try {
|
||||
soundURL = HolidayManager.filterSound(new ResourceLocation("mekanism", "tile." + soundPath));
|
||||
initSounds();
|
||||
} catch(Throwable t) {}
|
||||
// Stop the active sound if it's playing, since underlying sound might be changing
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (activeSound != null && mc.getSoundHandler().isSoundPlaying(activeSound)) {
|
||||
mc.getSoundHandler().stopSound(activeSound);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void initSounds()
|
||||
{
|
||||
sound = new SoundWrapper(this, this);
|
||||
private void updateSound() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (getActive() && !isInvalid()) {
|
||||
// Machine is active; if we don't have a sound already playing, schedule another
|
||||
if (activeSound == null || !mc.getSoundHandler().isSoundPlaying(activeSound)) {
|
||||
activeSound = new PositionedSoundRecord(soundEvent, SoundCategory.BLOCKS, getVolume(), 1.0f, getPos());
|
||||
mc.getSoundHandler().playSound(activeSound);
|
||||
}
|
||||
} else {
|
||||
// Not active; stop any active playing sounds
|
||||
if (activeSound != null && mc.getSoundHandler().isSoundPlaying(activeSound)) {
|
||||
mc.getSoundHandler().stopSound(activeSound);
|
||||
activeSound = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
@@ -138,14 +87,4 @@ public abstract class TileEntityNoisyBlock extends TileEntityElectricBlock imple
|
||||
updateSound();
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void updateSound()
|
||||
{
|
||||
if(shouldPlaySound() && getSound().canRestart() && client.enableMachineSounds)
|
||||
{
|
||||
getSound().reset();
|
||||
getSound().play();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
package mekanism.generators.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.Range4D;
|
||||
import mekanism.client.sound.ISoundSource;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.IActiveState;
|
||||
import mekanism.common.base.IHasSound;
|
||||
import mekanism.common.base.IRedstoneControl;
|
||||
import mekanism.common.base.TileNetworkList;
|
||||
import mekanism.common.config.MekanismConfig.general;
|
||||
@@ -29,7 +24,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class TileEntityGenerator extends TileEntityNoisyBlock implements IComputerIntegration, IActiveState, IHasSound, ISoundSource, IRedstoneControl, ISecurityTile
|
||||
public abstract class TileEntityGenerator extends TileEntityNoisyBlock implements IComputerIntegration, IActiveState, IRedstoneControl, ISecurityTile
|
||||
{
|
||||
/** Output per tick this generator can transfer. */
|
||||
public double output;
|
||||
|
||||
@@ -102,8 +102,7 @@ public class TileEntityWindGenerator extends TileEntityGenerator implements IBou
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getVolume()
|
||||
protected float getVolume()
|
||||
{
|
||||
return 1.5F*super.getVolume();
|
||||
}
|
||||
|
||||
+26
-101
@@ -2,29 +2,26 @@ package mekanism.generators.common.tile.reactor;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.client.sound.ISoundSource;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.MekanismFluids;
|
||||
import mekanism.common.base.IActiveState;
|
||||
import mekanism.common.base.IHasSound;
|
||||
import mekanism.common.base.SoundWrapper;
|
||||
import mekanism.common.base.TileNetworkList;
|
||||
import mekanism.common.config.MekanismConfig.client;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.generators.common.FusionReactor;
|
||||
import net.minecraft.client.audio.ISound.AttenuationType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -33,7 +30,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityReactorController extends TileEntityReactorBlock implements IActiveState, IHasSound, ISoundSource
|
||||
public class TileEntityReactorController extends TileEntityReactorBlock implements IActiveState
|
||||
{
|
||||
public static final int MAX_WATER = 100 * Fluid.BUCKET_VOLUME;
|
||||
public static final int MAX_STEAM = MAX_WATER * 100;
|
||||
@@ -49,10 +46,10 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
||||
|
||||
public AxisAlignedBB box;
|
||||
|
||||
public ResourceLocation soundURL = new ResourceLocation("mekanism", "tile.machine.fusionreactor");
|
||||
|
||||
private SoundEvent soundEvent = new SoundEvent(new ResourceLocation("mekanism", "tile.machine.fusionreactor"));
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public SoundWrapper sound;
|
||||
private ISound activeSound;
|
||||
|
||||
public double clientTemp = 0;
|
||||
public boolean clientBurning = false;
|
||||
@@ -104,7 +101,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
||||
public void onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
|
||||
if(world.isRemote)
|
||||
{
|
||||
updateSound();
|
||||
@@ -124,14 +121,22 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void updateSound()
|
||||
{
|
||||
if(shouldPlaySound() && getSound().canRestart() && client.enableMachineSounds)
|
||||
{
|
||||
getSound().reset();
|
||||
getSound().play();
|
||||
}
|
||||
}
|
||||
private void updateSound() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (isBurning() && !isInvalid()) {
|
||||
// Machine is active; if we don't have a sound already playing, schedule another
|
||||
if (activeSound == null || !mc.getSoundHandler().isSoundPlaying(activeSound)) {
|
||||
activeSound = new PositionedSoundRecord(soundEvent, SoundCategory.BLOCKS, 2.0f, 1.0f, getPos());
|
||||
mc.getSoundHandler().playSound(activeSound);
|
||||
}
|
||||
} else {
|
||||
// Not active; stop any active playing sounds
|
||||
if (activeSound != null && mc.getSoundHandler().isSoundPlaying(activeSound)) {
|
||||
mc.getSoundHandler().stopSound(activeSound);
|
||||
activeSound = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
@@ -333,84 +338,4 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public SoundWrapper getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldPlaySound()
|
||||
{
|
||||
return isBurning() && !isInvalid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ResourceLocation getSoundLocation()
|
||||
{
|
||||
return soundURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getVolume()
|
||||
{
|
||||
return 2F;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getFrequency()
|
||||
{
|
||||
return 1F;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Vec3d getSoundPosition()
|
||||
{
|
||||
return new Vec3d(getPos()).add(0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldRepeat()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getRepeatDelay()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AttenuationType getAttenuation()
|
||||
{
|
||||
return AttenuationType.LINEAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate()
|
||||
{
|
||||
super.validate();
|
||||
|
||||
if(world.isRemote)
|
||||
{
|
||||
initSounds();
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void initSounds()
|
||||
{
|
||||
sound = new SoundWrapper(this, this);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user