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