Work on jetpacks - specifically networking fixes and sounds!
This commit is contained in:
parent
aadd4fb741
commit
bf9d48d86f
12 changed files with 248 additions and 159 deletions
|
@ -2,8 +2,6 @@ package mekanism.client;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
|
@ -14,11 +12,15 @@ import mekanism.common.item.ItemJetpack;
|
|||
import mekanism.common.item.ItemWalkieTalkie;
|
||||
import mekanism.common.network.PacketConfiguratorState;
|
||||
import mekanism.common.network.PacketElectricBowState;
|
||||
import mekanism.common.network.PacketJetpackData;
|
||||
import mekanism.common.network.PacketWalkieTalkieState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -103,20 +105,32 @@ public class ClientPlayerTickHandler implements ITickHandler
|
|||
}
|
||||
}
|
||||
|
||||
if(cacheJetpackOn(entityPlayer) != isJetpackOn(entityPlayer))
|
||||
if(Mekanism.jetpackOn.contains(entityPlayer) != isJetpackOn(entityPlayer))
|
||||
{
|
||||
System.out.println("update");
|
||||
Mekanism.jetpackOn.put(entityPlayer, isJetpackOn(entityPlayer));
|
||||
if(isJetpackOn(entityPlayer))
|
||||
{
|
||||
Mekanism.jetpackOn.add(entityPlayer);
|
||||
}
|
||||
else {
|
||||
Mekanism.jetpackOn.remove(entityPlayer);
|
||||
}
|
||||
|
||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketJetpackData().setParams(entityPlayer, isJetpackOn(entityPlayer)));
|
||||
}
|
||||
|
||||
for(EntityPlayer entry : Mekanism.jetpackOn)
|
||||
{
|
||||
Mekanism.proxy.registerSound(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean cacheJetpackOn(EntityPlayer player)
|
||||
{
|
||||
return Mekanism.jetpackOn.get(player) != null ? Mekanism.jetpackOn.get(player) : false;
|
||||
return Mekanism.jetpackOn.contains(player);
|
||||
}
|
||||
|
||||
private boolean isJetpackOn(EntityPlayer player)
|
||||
public static boolean isJetpackOn(EntityPlayer player)
|
||||
{
|
||||
if(player.inventory.armorInventory[2] != null)
|
||||
{
|
||||
|
|
|
@ -60,8 +60,8 @@ import mekanism.client.sound.SoundHandler;
|
|||
import mekanism.common.CommonProxy;
|
||||
import mekanism.common.EntityObsidianTNT;
|
||||
import mekanism.common.EntityRobit;
|
||||
import mekanism.common.IInvConfiguration;
|
||||
import mekanism.common.IElectricChest;
|
||||
import mekanism.common.IInvConfiguration;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.block.BlockMachine.MachineType;
|
||||
import mekanism.common.inventory.InventoryElectricChest;
|
||||
|
@ -143,13 +143,13 @@ public class ClientProxy extends CommonProxy
|
|||
}
|
||||
|
||||
@Override
|
||||
public void registerSound(TileEntity tileEntity)
|
||||
public void registerSound(Object obj)
|
||||
{
|
||||
if(MekanismClient.enableSounds && Minecraft.getMinecraft().sndManager.sndSystem != null)
|
||||
{
|
||||
synchronized(MekanismClient.audioHandler.sounds)
|
||||
{
|
||||
MekanismClient.audioHandler.register(tileEntity);
|
||||
MekanismClient.audioHandler.register(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -400,13 +400,15 @@ public class ClientProxy extends CommonProxy
|
|||
{
|
||||
synchronized(MekanismClient.audioHandler.sounds)
|
||||
{
|
||||
HashMap<TileEntity, Sound> sounds = new HashMap<TileEntity, Sound>();
|
||||
HashMap<Object, Sound> sounds = new HashMap<Object, Sound>();
|
||||
sounds.putAll(MekanismClient.audioHandler.sounds);
|
||||
|
||||
for(Sound sound : sounds.values())
|
||||
{
|
||||
sound.remove();
|
||||
}
|
||||
|
||||
MekanismClient.audioHandler.sounds.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
69
common/mekanism/client/sound/JetpackSound.java
Normal file
69
common/mekanism/client/sound/JetpackSound.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package mekanism.client.sound;
|
||||
|
||||
import mekanism.client.ClientPlayerTickHandler;
|
||||
import mekanism.common.item.ItemJetpack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
public class JetpackSound extends Sound
|
||||
{
|
||||
/** The TileEntity this sound is associated with. */
|
||||
public EntityPlayer player;
|
||||
|
||||
public JetpackSound(String id, String sound, EntityPlayer entity)
|
||||
{
|
||||
super(id, sound, entity, new Vector3(entity));
|
||||
|
||||
player = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMultiplier()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 getLocation()
|
||||
{
|
||||
return new Vector3(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(World world)
|
||||
{
|
||||
if(player.isDead)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(!world.loadedEntityList.contains(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(!hasJetpack(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(ClientPlayerTickHandler.isJetpackOn(player) != isPlaying)
|
||||
{
|
||||
if(ClientPlayerTickHandler.isJetpackOn(player))
|
||||
{
|
||||
play();
|
||||
}
|
||||
else {
|
||||
stopLoop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasJetpack(EntityPlayer player)
|
||||
{
|
||||
return player.inventory.armorInventory[2] != null && player.inventory.armorInventory[2].getItem() instanceof ItemJetpack;
|
||||
}
|
||||
}
|
|
@ -5,20 +5,10 @@ import java.net.URL;
|
|||
import mekanism.client.MekanismClient;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* Sound -- an object that is created in SoundHandler. A 'Sound' object runs off of
|
||||
* PaulsCode's SoundSystem. It has several methods; play(), for looping the clip,
|
||||
* stop(), for stopping the loop, remove(), for removing the sound from PaulsCode,
|
||||
* and updateVolume() for updating the volume based on where the player is.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class Sound
|
||||
public abstract class Sound
|
||||
{
|
||||
/** The bundled path where the sound is */
|
||||
public String soundPath;
|
||||
|
@ -26,25 +16,24 @@ public class Sound
|
|||
/** A unique identifier for this sound */
|
||||
public String identifier;
|
||||
|
||||
/** The TileEntity this sound is associated with. */
|
||||
public TileEntity tileEntity;
|
||||
|
||||
/** Whether or not this sound is playing */
|
||||
public boolean isPlaying = false;
|
||||
|
||||
private Object objRef;
|
||||
|
||||
/**
|
||||
* A sound that runs off of the PaulsCode sound system.
|
||||
* @param id - unique identifier
|
||||
* @param sound - bundled path to the sound
|
||||
* @param tileentity - the tile this sound is playing from.
|
||||
*/
|
||||
public Sound(String id, String sound, TileEntity tileentity)
|
||||
public Sound(String id, String sound, Object obj, Vector3 loc)
|
||||
{
|
||||
synchronized(MekanismClient.audioHandler.sounds)
|
||||
{
|
||||
soundPath = sound;
|
||||
identifier = id;
|
||||
tileEntity = tileentity;
|
||||
objRef = obj;
|
||||
|
||||
URL url = getClass().getClassLoader().getResource("assets/mekanism/sound/" + sound);
|
||||
|
||||
|
@ -55,12 +44,12 @@ public class Sound
|
|||
|
||||
if(SoundHandler.getSoundSystem() != null)
|
||||
{
|
||||
SoundHandler.getSoundSystem().newSource(false, id, url, sound, true, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 0, 16F);
|
||||
SoundHandler.getSoundSystem().newSource(false, id, url, sound, true, (float)loc.x, (float)loc.y, (float)loc.z, 0, 16F);
|
||||
updateVolume(Minecraft.getMinecraft().thePlayer);
|
||||
SoundHandler.getSoundSystem().activate(id);
|
||||
}
|
||||
|
||||
MekanismClient.audioHandler.sounds.put(tileEntity, this);
|
||||
MekanismClient.audioHandler.sounds.put(obj, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +109,7 @@ public class Sound
|
|||
stopLoop();
|
||||
}
|
||||
|
||||
MekanismClient.audioHandler.sounds.remove(tileEntity);
|
||||
MekanismClient.audioHandler.sounds.remove(objRef);
|
||||
|
||||
if(SoundHandler.getSoundSystem() != null)
|
||||
{
|
||||
|
@ -130,6 +119,12 @@ public class Sound
|
|||
}
|
||||
}
|
||||
|
||||
public abstract boolean update(World world);
|
||||
|
||||
public abstract Vector3 getLocation();
|
||||
|
||||
public abstract float getMultiplier();
|
||||
|
||||
/**
|
||||
* Updates the volume based on how far away the player is from the machine.
|
||||
* @param entityplayer - player who is near the machine, always Minecraft.thePlayer
|
||||
|
@ -138,20 +133,19 @@ public class Sound
|
|||
{
|
||||
synchronized(MekanismClient.audioHandler.sounds)
|
||||
{
|
||||
if(entityplayer != null && tileEntity != null && entityplayer.worldObj == tileEntity.worldObj)
|
||||
{
|
||||
float multiplier = ((IHasSound)tileEntity).getVolumeMultiplier();
|
||||
try {
|
||||
float multiplier = getMultiplier();
|
||||
float volume = 0;
|
||||
float masterVolume = MekanismClient.audioHandler.masterVolume;
|
||||
|
||||
double distance = entityplayer.getDistance(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
double distance = entityplayer.getDistance(getLocation().x, getLocation().y, getLocation().z);
|
||||
volume = (float)Math.min(Math.max(masterVolume-((distance*.08F)*masterVolume), 0)*multiplier, 1);
|
||||
|
||||
if(SoundHandler.getSoundSystem() != null)
|
||||
{
|
||||
SoundHandler.getSoundSystem().setVolume(identifier, volume);
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ import java.util.zip.ZipEntry;
|
|||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.IActiveState;
|
||||
import mekanism.common.Mekanism;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -37,7 +37,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
public class SoundHandler
|
||||
{
|
||||
/** All the sound references in the Minecraft game. */
|
||||
public Map<TileEntity, Sound> sounds = Collections.synchronizedMap(new HashMap<TileEntity, Sound>());
|
||||
public Map<Object, Sound> sounds = Collections.synchronizedMap(new HashMap<Object, Sound>());
|
||||
|
||||
/** The current base volume Minecraft is using. */
|
||||
public float masterVolume = 0;
|
||||
|
@ -171,43 +171,16 @@ public class SoundHandler
|
|||
{
|
||||
ArrayList<Sound> soundsToRemove = new ArrayList<Sound>();
|
||||
World world = FMLClientHandler.instance().getClient().theWorld;
|
||||
|
||||
for(Sound sound : sounds.values())
|
||||
{
|
||||
if(FMLClientHandler.instance().getClient().thePlayer != null && world != null)
|
||||
{
|
||||
if(!(sound.tileEntity instanceof IHasSound))
|
||||
if(!sound.update(world))
|
||||
{
|
||||
soundsToRemove.add(sound);
|
||||
continue;
|
||||
}
|
||||
else if(world.getBlockTileEntity(sound.tileEntity.xCoord, sound.tileEntity.yCoord, sound.tileEntity.zCoord) != sound.tileEntity)
|
||||
{
|
||||
soundsToRemove.add(sound);
|
||||
continue;
|
||||
}
|
||||
else if(!((IHasSound)sound.tileEntity).getSoundPath().equals(sound.soundPath))
|
||||
{
|
||||
soundsToRemove.add(sound);
|
||||
continue;
|
||||
}
|
||||
else if(sound.tileEntity instanceof IActiveState)
|
||||
{
|
||||
if(((IActiveState)sound.tileEntity).getActive() != sound.isPlaying)
|
||||
{
|
||||
if(((IActiveState)sound.tileEntity).getActive())
|
||||
{
|
||||
sound.play();
|
||||
}
|
||||
else {
|
||||
sound.stopLoop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(sound.isPlaying)
|
||||
{
|
||||
sound.updateVolume(FMLClientHandler.instance().getClient().thePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,6 +189,14 @@ public class SoundHandler
|
|||
sound.remove();
|
||||
}
|
||||
|
||||
for(Sound sound : sounds.values())
|
||||
{
|
||||
if(sound.isPlaying)
|
||||
{
|
||||
sound.updateVolume(FMLClientHandler.instance().getClient().thePlayer);
|
||||
}
|
||||
}
|
||||
|
||||
masterVolume = FMLClientHandler.instance().getClient().gameSettings.soundVolume;
|
||||
}
|
||||
else {
|
||||
|
@ -239,11 +220,11 @@ public class SoundHandler
|
|||
* @param tileEntity - the holder of the sound
|
||||
* @return Sound instance
|
||||
*/
|
||||
public Sound getFrom(TileEntity tileEntity)
|
||||
public Sound getFrom(Object obj)
|
||||
{
|
||||
synchronized(sounds)
|
||||
{
|
||||
return sounds.get(tileEntity);
|
||||
return sounds.get(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,18 +233,25 @@ public class SoundHandler
|
|||
* @param tileEntity - the holder of this sound.
|
||||
* @return Sound instance
|
||||
*/
|
||||
public void register(TileEntity tileEntity)
|
||||
public void register(Object obj)
|
||||
{
|
||||
if(!(tileEntity instanceof IHasSound))
|
||||
if(obj instanceof TileEntity && !(obj instanceof IHasSound))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized(sounds)
|
||||
{
|
||||
if(getFrom(tileEntity) == null)
|
||||
if(getFrom(obj) == null)
|
||||
{
|
||||
new Sound(getIdentifier(), ((IHasSound)tileEntity).getSoundPath(), tileEntity);
|
||||
if(obj instanceof TileEntity)
|
||||
{
|
||||
new TileSound(getIdentifier(), ((IHasSound)obj).getSoundPath(), (TileEntity)obj);
|
||||
}
|
||||
else if(obj instanceof EntityPlayer)
|
||||
{
|
||||
new JetpackSound(getIdentifier(), "Jetpack.ogg", (EntityPlayer)obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
84
common/mekanism/client/sound/TileSound.java
Normal file
84
common/mekanism/client/sound/TileSound.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
package mekanism.client.sound;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import mekanism.client.MekanismClient;
|
||||
import mekanism.common.IActiveState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Sound -- an object that is created in SoundHandler. A 'Sound' object runs off of
|
||||
* PaulsCode's SoundSystem. It has several methods; play(), for looping the clip,
|
||||
* stop(), for stopping the loop, remove(), for removing the sound from PaulsCode,
|
||||
* and updateVolume() for updating the volume based on where the player is.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TileSound extends Sound
|
||||
{
|
||||
/** The TileEntity this sound is associated with. */
|
||||
public TileEntity tileEntity;
|
||||
|
||||
/**
|
||||
* A sound that runs off of the PaulsCode sound system.
|
||||
* @param id - unique identifier
|
||||
* @param sound - bundled path to the sound
|
||||
* @param tileentity - the tile this sound is playing from.
|
||||
*/
|
||||
public TileSound(String id, String sound, TileEntity tileentity)
|
||||
{
|
||||
super(id, sound, tileentity, new Vector3(tileentity));
|
||||
|
||||
tileEntity = tileentity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMultiplier()
|
||||
{
|
||||
return ((IHasSound)tileEntity).getVolumeMultiplier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 getLocation()
|
||||
{
|
||||
return new Vector3(tileEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(World world)
|
||||
{
|
||||
if(!(tileEntity instanceof IHasSound))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(world.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(!((IHasSound)tileEntity).getSoundPath().equals(soundPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(tileEntity instanceof IActiveState)
|
||||
{
|
||||
if(((IActiveState)tileEntity).getActive() != isPlaying)
|
||||
{
|
||||
if(((IActiveState)tileEntity).getActive())
|
||||
{
|
||||
play();
|
||||
}
|
||||
else {
|
||||
stopLoop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
package mekanism.common;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketJetpackData;
|
||||
import mekanism.common.network.PacketJetpackData.PacketType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.common.IPlayerTracker;
|
||||
|
||||
|
@ -10,10 +7,7 @@ public class CommonPlayerTracker implements IPlayerTracker
|
|||
@Override
|
||||
public void onPlayerLogin(EntityPlayer player)
|
||||
{
|
||||
if(!player.worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(PacketType.INITIAL), player.worldObj.provider.dimensionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,10 +19,7 @@ public class CommonPlayerTracker implements IPlayerTracker
|
|||
@Override
|
||||
public void onPlayerChangedDimension(EntityPlayer player)
|
||||
{
|
||||
if(!player.worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(PacketType.INITIAL), player.worldObj.provider.dimensionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -106,7 +106,7 @@ public class CommonProxy
|
|||
* Registers a client-side sound, assigned to a TileEntity.
|
||||
* @param tileEntity - TileEntity who is registering the sound
|
||||
*/
|
||||
public void registerSound(TileEntity tileEntity) {}
|
||||
public void registerSound(Object obj) {}
|
||||
|
||||
/**
|
||||
* Unregisters a client-side sound, assigned to a TileEntity;
|
||||
|
|
|
@ -178,7 +178,7 @@ public class Mekanism
|
|||
/** A list of the usernames of players who have donated to Mekanism. */
|
||||
public static List<String> donators = new ArrayList<String>();
|
||||
|
||||
public static Map<EntityPlayer, Boolean> jetpackOn = new HashMap<EntityPlayer, Boolean>();
|
||||
public static Set<EntityPlayer> jetpackOn = new HashSet<EntityPlayer>();
|
||||
|
||||
public static Set<Object3D> ic2Registered = new HashSet<Object3D>();
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
|
@ -13,12 +10,8 @@ import net.minecraft.world.World;
|
|||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class PacketJetpackData implements IMekanismPacket
|
||||
{
|
||||
public PacketType packetType;
|
||||
|
||||
public EntityPlayer updatePlayer;
|
||||
public boolean value;
|
||||
|
||||
|
@ -31,50 +24,33 @@ public class PacketJetpackData implements IMekanismPacket
|
|||
@Override
|
||||
public IMekanismPacket setParams(Object... data)
|
||||
{
|
||||
packetType = (PacketType)data[0];
|
||||
|
||||
if(packetType == PacketType.UPDATE)
|
||||
{
|
||||
updatePlayer = (EntityPlayer)data[1];
|
||||
value = (Boolean)data[2];
|
||||
}
|
||||
|
||||
updatePlayer = (EntityPlayer)data[0];
|
||||
value = (Boolean)data[1];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
|
||||
{
|
||||
packetType = PacketType.values()[dataStream.readInt()];
|
||||
String username = dataStream.readUTF();
|
||||
boolean value = dataStream.readBoolean();
|
||||
|
||||
if(packetType == PacketType.INITIAL)
|
||||
EntityPlayer p = world.getPlayerEntityByName(username);
|
||||
|
||||
if(p != null)
|
||||
{
|
||||
Mekanism.jetpackOn.clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
if(value)
|
||||
{
|
||||
EntityPlayer p = world.getPlayerEntityByName(dataStream.readUTF());
|
||||
|
||||
if(p != null)
|
||||
{
|
||||
Mekanism.jetpackOn.put(p, true);
|
||||
}
|
||||
Mekanism.jetpackOn.add(p);
|
||||
}
|
||||
else {
|
||||
Mekanism.jetpackOn.remove(p);
|
||||
}
|
||||
}
|
||||
else if(packetType == PacketType.UPDATE)
|
||||
{
|
||||
String username = dataStream.readUTF();
|
||||
boolean value = dataStream.readBoolean();
|
||||
|
||||
EntityPlayer p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().getPlayerForUsername(username);
|
||||
|
||||
if(p != null)
|
||||
if(!world.isRemote)
|
||||
{
|
||||
Mekanism.jetpackOn.put(p, value);
|
||||
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(PacketType.UPDATE, p, value), world.provider.dimensionId);
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(p, value), world.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,36 +58,7 @@ public class PacketJetpackData implements IMekanismPacket
|
|||
@Override
|
||||
public void write(DataOutputStream dataStream) throws Exception
|
||||
{
|
||||
dataStream.writeInt(packetType.ordinal());
|
||||
|
||||
if(packetType == PacketType.UPDATE)
|
||||
{
|
||||
dataStream.writeUTF(updatePlayer.username);
|
||||
dataStream.writeBoolean(value);
|
||||
}
|
||||
else if(packetType == PacketType.INITIAL)
|
||||
{
|
||||
List<EntityPlayer> toSend = new ArrayList<EntityPlayer>();
|
||||
|
||||
for(Map.Entry<EntityPlayer, Boolean> entry : Mekanism.jetpackOn.entrySet())
|
||||
{
|
||||
if(entry.getValue())
|
||||
{
|
||||
toSend.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
dataStream.writeInt(toSend.size());
|
||||
|
||||
for(EntityPlayer player : toSend)
|
||||
{
|
||||
dataStream.writeUTF(player.username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum PacketType
|
||||
{
|
||||
INITIAL, UPDATE
|
||||
dataStream.writeUTF(updatePlayer.username);
|
||||
dataStream.writeBoolean(value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package mekanism.generators.common.tileentity;
|
|||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import mekanism.client.sound.Sound;
|
||||
import mekanism.client.sound.TileSound;
|
||||
import mekanism.common.FluidSlot;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
@ -29,7 +29,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui
|
|||
{
|
||||
/** The Sound instance for this machine. */
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Sound audio;
|
||||
public TileSound audio;
|
||||
|
||||
/** The FluidSlot biofuel instance for this generator. */
|
||||
public FluidSlot bioFuelSlot = new FluidSlot(24000, -1);
|
||||
|
|
BIN
resources/assets/mekanism/sound/Jetpack.ogg
Normal file
BIN
resources/assets/mekanism/sound/Jetpack.ogg
Normal file
Binary file not shown.
Loading…
Reference in a new issue