Add some more functionality to sending sounds, and some preliminary work on an abstract way to spawn particles from the server side
This commit is contained in:
parent
ad8a9f4b70
commit
a9bf0e6bea
|
@ -1,13 +1,17 @@
|
|||
package com.pahimar.ee3.array;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import com.pahimar.ee3.api.AlchemyArray;
|
||||
import com.pahimar.ee3.init.ModBlocks;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSingleParticleEvent;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.reference.Particles;
|
||||
import com.pahimar.ee3.reference.Sounds;
|
||||
import com.pahimar.ee3.reference.Textures;
|
||||
import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
|
||||
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
||||
import com.pahimar.ee3.util.CommonSoundHelper;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
@ -46,7 +50,8 @@ public class TransmutationAlchemyArray extends AlchemyArray
|
|||
((TileEntityTransmutationTablet) world.getTileEntity(arrayX, arrayY - 1, arrayZ)).setOrientation(tileEntityAlchemyArray.getOrientation());
|
||||
}
|
||||
|
||||
EquivalentExchange3.proxy.playSound(Sounds.TRANSMUTE, arrayX, arrayY, arrayZ, 1f, 1f);
|
||||
CommonSoundHelper.playSoundAtLocation(world.provider.dimensionId, arrayX, arrayY, arrayZ, Sounds.TRANSMUTE, 1f, 1f);
|
||||
PacketHandler.INSTANCE.sendToAllAround(new MessageSingleParticleEvent(Particles.LARGE_EXPLODE, arrayX + 0.5d, arrayY + 0.625d, arrayZ + 0.5d, 0d, 0d, 0d), new NetworkRegistry.TargetPoint(world.provider.dimensionId, (double) arrayX, (double) arrayY, (double) arrayZ, 128d));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.pahimar.ee3.api.AlchemyArray;
|
|||
import com.pahimar.ee3.array.AlchemyArrayRegistry;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.reference.RenderIds;
|
||||
import com.pahimar.ee3.reference.Sounds;
|
||||
import com.pahimar.ee3.settings.ChalkSettings;
|
||||
import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
|
||||
import com.pahimar.ee3.tileentity.TileEntityEE;
|
||||
|
@ -224,7 +225,7 @@ public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
|
|||
((TileEntityEE) world.getTileEntity(x, y, z)).setOrientation(world.getBlockMetadata(x, y, z));
|
||||
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).setRotation(chalkSettings.getRotation(), facing);
|
||||
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).setAlchemyArray(alchemyArray, chalkSettings.getSize());
|
||||
CommonSoundHelper.playChalkSoundAt((EntityPlayer) entityLiving);
|
||||
CommonSoundHelper.playSoundAtPlayer((EntityPlayer) entityLiving, Sounds.Chalk.getRandomChalkSound(), 1f, 1f);
|
||||
|
||||
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.pahimar.ee3.client.util;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
public class ClientParticleHelper
|
||||
{
|
||||
public static void spawnParticle(String particleName, double xCoord, double yCoord, double zCoord, double xVelocity, double yVelocity, double zVelocity)
|
||||
{
|
||||
FMLClientHandler.instance().getWorldClient().spawnParticle(particleName, xCoord, yCoord, zCoord, xVelocity, yVelocity, zVelocity);
|
||||
}
|
||||
}
|
|
@ -86,30 +86,30 @@ public class ItemDarkMatterAxe extends ItemToolModalEE implements IKeyBound, ICh
|
|||
{
|
||||
if (getChargeLevel(itemStack) == this.getMaxChargeLevel())
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
increaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getChargeLevel(itemStack) == 0)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
decreaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key == Key.EXTRA)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
changeToolMode(itemStack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,30 +124,30 @@ public class ItemDarkMatterHoe extends ItemHoe implements IKeyBound, IChargeable
|
|||
{
|
||||
if (getChargeLevel(itemStack) == this.getMaxChargeLevel())
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
increaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getChargeLevel(itemStack) == 0)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
decreaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key == Key.EXTRA)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
changeToolMode(itemStack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,30 +117,30 @@ public class ItemDarkMatterPickAxe extends ItemToolModalEE implements IKeyBound,
|
|||
{
|
||||
if (getChargeLevel(itemStack) == this.getMaxChargeLevel())
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
increaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getChargeLevel(itemStack) == 0)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
decreaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key == Key.EXTRA)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
changeToolMode(itemStack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,30 +86,30 @@ public class ItemDarkMatterShovel extends ItemToolModalEE implements IKeyBound,
|
|||
{
|
||||
if (getChargeLevel(itemStack) == this.getMaxChargeLevel())
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
increaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getChargeLevel(itemStack) == 0)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
decreaseChargeLevel(itemStack);
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key == Key.EXTRA)
|
||||
{
|
||||
CommonSoundHelper.playSoundAt(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
|
||||
changeToolMode(itemStack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,5 +26,6 @@ public class PacketHandler
|
|||
INSTANCE.registerMessage(MessageTileEntityDummy.class, MessageTileEntityDummy.class, 11, Side.CLIENT);
|
||||
INSTANCE.registerMessage(MessageTileEntityAlchemyArray.class, MessageTileEntityAlchemyArray.class, 12, Side.CLIENT);
|
||||
INSTANCE.registerMessage(MessageTileEntityTransmutationTablet.class, MessageTileEntityTransmutationTablet.class, 13, Side.CLIENT);
|
||||
INSTANCE.registerMessage(MessageSingleParticleEvent.class, MessageSingleParticleEvent.class, 14, Side.CLIENT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.pahimar.ee3.network.message;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class MessageSingleParticleEvent implements IMessage, IMessageHandler<MessageSingleParticleEvent, IMessage>
|
||||
{
|
||||
private String particleName;
|
||||
private double xCoord, yCoord, zCoord;
|
||||
private double xVelocity, yVelocity, zVelocity;
|
||||
|
||||
public MessageSingleParticleEvent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public MessageSingleParticleEvent(String particleName, double xCoord, double yCoord, double zCoord, double xVelocity, double yVelocity, double zVelocity)
|
||||
{
|
||||
this.particleName = particleName;
|
||||
this.xCoord = xCoord;
|
||||
this.yCoord = yCoord;
|
||||
this.zCoord = zCoord;
|
||||
this.xVelocity = xVelocity;
|
||||
this.yVelocity = yVelocity;
|
||||
this.zVelocity = zVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf byteBuf)
|
||||
{
|
||||
int particleNameLength = byteBuf.readInt();
|
||||
this.particleName = new String(byteBuf.readBytes(particleNameLength).array());
|
||||
this.xCoord = byteBuf.readDouble();
|
||||
this.yCoord = byteBuf.readDouble();
|
||||
this.zCoord = byteBuf.readDouble();
|
||||
this.xVelocity = byteBuf.readDouble();
|
||||
this.yVelocity = byteBuf.readDouble();
|
||||
this.zVelocity = byteBuf.readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf byteBuf)
|
||||
{
|
||||
byteBuf.writeInt(particleName.length());
|
||||
byteBuf.writeBytes(particleName.getBytes());
|
||||
byteBuf.writeDouble(xCoord);
|
||||
byteBuf.writeDouble(yCoord);
|
||||
byteBuf.writeDouble(zCoord);
|
||||
byteBuf.writeDouble(xVelocity);
|
||||
byteBuf.writeDouble(yVelocity);
|
||||
byteBuf.writeDouble(zVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MessageSingleParticleEvent message, MessageContext ctx)
|
||||
{
|
||||
EquivalentExchange3.proxy.spawnParticle(message.particleName, message.xCoord, message.yCoord, message.zCoord, message.xVelocity, message.yVelocity, message.zVelocity);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.pahimar.ee3.client.handler.KeyInputEventHandler;
|
|||
import com.pahimar.ee3.client.renderer.item.*;
|
||||
import com.pahimar.ee3.client.renderer.tileentity.*;
|
||||
import com.pahimar.ee3.client.settings.Keybindings;
|
||||
import com.pahimar.ee3.client.util.ClientParticleHelper;
|
||||
import com.pahimar.ee3.client.util.ClientSoundHelper;
|
||||
import com.pahimar.ee3.init.ModBlocks;
|
||||
import com.pahimar.ee3.reference.RenderIds;
|
||||
|
@ -48,6 +49,12 @@ public class ClientProxy extends CommonProxy
|
|||
ClientSoundHelper.playSound(soundName, xCoord, yCoord, zCoord, volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(String particleName, double xCoord, double yCoord, double zCoord, double xVelocity, double yVelocity, double zVelocity)
|
||||
{
|
||||
ClientParticleHelper.spawnParticle(particleName, xCoord, yCoord, zCoord, xVelocity, yVelocity, zVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientProxy getClientProxy()
|
||||
{
|
||||
|
|
|
@ -11,4 +11,6 @@ public interface IProxy
|
|||
public abstract void registerKeybindings();
|
||||
|
||||
public abstract void playSound(String soundName, float xCoord, float yCoord, float zCoord, float volume, float pitch);
|
||||
|
||||
public abstract void spawnParticle(String particleName, double xCoord, double yCoord, double zCoord, double xVelocity, double yVelocity, double zVelocity);
|
||||
}
|
||||
|
|
|
@ -25,4 +25,10 @@ public class ServerProxy extends CommonProxy
|
|||
{
|
||||
// NOOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(String particleName, double xCoord, double yCoord, double zCoord, double xVelocity, double yVelocity, double zVelocity)
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.pahimar.ee3.util;
|
||||
|
||||
public class CommonParticleHelper
|
||||
{
|
||||
}
|
|
@ -2,24 +2,28 @@ package com.pahimar.ee3.util;
|
|||
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSoundEvent;
|
||||
import com.pahimar.ee3.reference.Sounds;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class CommonSoundHelper
|
||||
{
|
||||
public static void playSoundAt(EntityPlayer entityPlayer, String soundName, float volume, float pitch)
|
||||
public static void playSoundAtLocation(int dimensionId, float xCoord, float yCoord, float zCoord, String soundName, float volume, float pitch)
|
||||
{
|
||||
playSoundAt(entityPlayer, soundName, volume, pitch, 32d);
|
||||
playSoundAtLocation(dimensionId, xCoord, yCoord, zCoord, soundName, volume, pitch, 32d);
|
||||
}
|
||||
|
||||
public static void playSoundAt(EntityPlayer entityPlayer, String soundName, float volume, float pitch, double range)
|
||||
public static void playSoundAtLocation(int dimensionId, float xCoord, float yCoord, float zCoord, String soundName, float volume, float pitch, double range)
|
||||
{
|
||||
PacketHandler.INSTANCE.sendToAllAround(new MessageSoundEvent(soundName, xCoord, yCoord, zCoord, volume, pitch), new NetworkRegistry.TargetPoint(dimensionId, xCoord, yCoord, zCoord, range));
|
||||
}
|
||||
|
||||
public static void playSoundAtPlayer(EntityPlayer entityPlayer, String soundName, float volume, float pitch)
|
||||
{
|
||||
playSoundAtPlayer(entityPlayer, soundName, volume, pitch, 32d);
|
||||
}
|
||||
|
||||
public static void playSoundAtPlayer(EntityPlayer entityPlayer, String soundName, float volume, float pitch, double range)
|
||||
{
|
||||
PacketHandler.INSTANCE.sendToAllAround(new MessageSoundEvent(entityPlayer, soundName, volume, pitch), new NetworkRegistry.TargetPoint(entityPlayer.worldObj.provider.dimensionId, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, range));
|
||||
}
|
||||
|
||||
public static void playChalkSoundAt(EntityPlayer entityPlayer)
|
||||
{
|
||||
playSoundAt(entityPlayer, Sounds.Chalk.getRandomChalkSound(), 1f, 1f);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue