mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
* First pass reformatting code to be more readable (common still not done) * Replace google common collect calls with Java calls where possible * Remove a bunch of unnecessary parenthesis leaving clarifying ones * Add some missing @Nonnull annotations * Fix checking wrong type * Remove unnecessary continue/return statements and simplify comparision check * Pass exception instead of directly printing stack trace * Work on cleaning up common, through config so far * Work on cleaning up common, through integration so far * Work on cleaning up common, through network so far * Work on cleaning up common, through tier so far * Remove empty constructors that get created by default anyways * Work on cleaning up common, through transmitters so far * Work on cleaning up common, through utils so far * Finish cleaning up spacing for common
160 lines
5.5 KiB
Java
160 lines
5.5 KiB
Java
package mekanism.common;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
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.entity.player.EntityPlayer;
|
|
import net.minecraft.world.World;
|
|
|
|
public class PlayerState {
|
|
|
|
private Set<UUID> activeJetpacks = new HashSet<>();
|
|
private Set<UUID> activeGasmasks = new HashSet<>();
|
|
private Set<UUID> activeFlamethrowers = new HashSet<>();
|
|
|
|
private World world;
|
|
|
|
public void clear() {
|
|
activeJetpacks.clear();
|
|
activeGasmasks.clear();
|
|
activeFlamethrowers.clear();
|
|
}
|
|
|
|
public void clearPlayer(EntityPlayer p) {
|
|
activeJetpacks.remove(p.getUniqueID());
|
|
activeGasmasks.remove(p.getUniqueID());
|
|
activeFlamethrowers.remove(p.getUniqueID());
|
|
}
|
|
|
|
public void init(World world) {
|
|
this.world = world;
|
|
}
|
|
|
|
// ----------------------
|
|
//
|
|
// Jetpack state tracking
|
|
//
|
|
// ----------------------
|
|
|
|
public void setJetpackState(UUID uuid, boolean isActive, boolean isLocal) {
|
|
boolean alreadyActive = activeJetpacks.contains(uuid);
|
|
boolean changed = alreadyActive != isActive;
|
|
if (alreadyActive && !isActive) {
|
|
// On -> off
|
|
activeJetpacks.remove(uuid);
|
|
} else if (!alreadyActive && isActive) {
|
|
// Off -> on
|
|
activeJetpacks.add(uuid);
|
|
}
|
|
|
|
// 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 (isLocal) {
|
|
Mekanism.packetHandler.sendToServer(PacketJetpackData.JetpackDataMessage.UPDATE(uuid, isActive));
|
|
}
|
|
|
|
// Start a sound playing if the person is now flying
|
|
if (isActive && MekanismConfig.current().client.enablePlayerSounds.val()) {
|
|
SoundHandler.startSound(world.getPlayerEntityByUUID(uuid), "jetpack");
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean isJetpackOn(EntityPlayer p) {
|
|
return activeJetpacks.contains(p.getUniqueID());
|
|
}
|
|
|
|
public Set<UUID> getActiveJetpacks() {
|
|
return activeJetpacks;
|
|
}
|
|
|
|
public void setActiveJetpacks(Set<UUID> newActiveJetpacks) {
|
|
for (UUID activeUser : newActiveJetpacks) {
|
|
setJetpackState(activeUser, true, false);
|
|
}
|
|
}
|
|
|
|
// ----------------------
|
|
//
|
|
// Gasmask state tracking
|
|
//
|
|
// ----------------------
|
|
|
|
public void setGasmaskState(UUID uuid, boolean isActive, boolean isLocal) {
|
|
boolean alreadyActive = activeGasmasks.contains(uuid);
|
|
boolean changed = alreadyActive != isActive;
|
|
if (alreadyActive && !isActive) {
|
|
activeGasmasks.remove(uuid); // On -> off
|
|
} else if (!alreadyActive && isActive) {
|
|
activeGasmasks.add(uuid); // 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 (isLocal) {
|
|
Mekanism.packetHandler.sendToServer(PacketScubaTankData.ScubaTankDataMessage.UPDATE(uuid, isActive));
|
|
}
|
|
|
|
// Start a sound playing if the person is now using a gasmask
|
|
if (isActive && MekanismConfig.current().client.enablePlayerSounds.val()) {
|
|
SoundHandler.startSound(world.getPlayerEntityByUUID(uuid), "gasmask");
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean isGasmaskOn(EntityPlayer p) {
|
|
return activeGasmasks.contains(p.getUniqueID());
|
|
}
|
|
|
|
public Set<UUID> getActiveGasmasks() {
|
|
return activeGasmasks;
|
|
}
|
|
|
|
public void setActiveGasmasks(Set<UUID> newActiveGasmasks) {
|
|
for (UUID activeUser : newActiveGasmasks) {
|
|
setGasmaskState(activeUser, true, false);
|
|
}
|
|
}
|
|
|
|
// ----------------------
|
|
//
|
|
// Flamethrower state tracking
|
|
//
|
|
// ----------------------
|
|
|
|
public void setFlamethrowerState(UUID uuid, boolean isActive, boolean isLocal) {
|
|
boolean alreadyActive = activeFlamethrowers.contains(uuid);
|
|
boolean changed = alreadyActive != isActive;
|
|
if (alreadyActive && !isActive) {
|
|
activeFlamethrowers.remove(uuid); // On -> off
|
|
} else if (!alreadyActive && isActive) {
|
|
activeFlamethrowers.add(uuid); // 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 (isLocal) {
|
|
Mekanism.packetHandler.sendToServer(new FlamethrowerDataMessage(FlamethrowerPacket.UPDATE, null, uuid, isActive));
|
|
}
|
|
|
|
// Start a sound playing if the person is now using a flamethrower
|
|
if (isActive && MekanismConfig.current().client.enablePlayerSounds.val()) {
|
|
SoundHandler.startSound(world.getPlayerEntityByUUID(uuid), "flamethrower");
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean isFlamethrowerOn(EntityPlayer p) {
|
|
return activeFlamethrowers.contains(p.getUniqueID());
|
|
}
|
|
|
|
} |