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
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user