Added quantity to effect handling

This commit is contained in:
LemADEC 2017-02-13 02:17:46 +01:00
parent bcead39bf0
commit 9b0ca5cf55
4 changed files with 23 additions and 14 deletions

View file

@ -395,7 +395,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
-0.2D * vDirection.x + 0.05 * (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()),
-0.2D * vDirection.y + 0.05 * (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()),
-0.2D * vDirection.z + 0.05 * (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()));
PacketHandler.sendSpawnParticlePacket(worldObj, "explode", origin, direction, r, g, b, r, g, b, 96);
PacketHandler.sendSpawnParticlePacket(worldObj, "explode", (byte) 5, origin, direction, r, g, b, r, g, b, 96);
// apply custom damages
if (block instanceof IDamageReceiver) {

View file

@ -274,7 +274,7 @@ public enum EnumForceFieldUpgrade implements IForceFieldUpgrade, IForceFieldUpgr
v3Direction.scale(0.20D);
PacketHandler.sendBeamPacket(world, v3Projector, v3Entity,
0.25F, 0.38F, 0.75F, 10, 0, 50);
PacketHandler.sendSpawnParticlePacket(world, "snowshovel", v3Entity, v3Direction,
PacketHandler.sendSpawnParticlePacket(world, "snowshovel", (byte) 5, v3Entity, v3Direction,
0.20F + 0.10F * world.rand.nextFloat(), 0.25F + 0.25F * world.rand.nextFloat(), 0.60F + 0.30F * world.rand.nextFloat(),
0.0F, 0.0F, 0.0F, 32);
return 10;
@ -292,7 +292,7 @@ public enum EnumForceFieldUpgrade implements IForceFieldUpgrade, IForceFieldUpgr
v3Direction.scale(0.20D);
PacketHandler.sendBeamPacket(world, v3Projector, v3Entity,
0.95F, 0.52F, 0.38F, 10, 0, 50);
PacketHandler.sendSpawnParticlePacket(world, "snowshovel", v3Entity, v3Direction,
PacketHandler.sendSpawnParticlePacket(world, "snowshovel", (byte) 5, v3Entity, v3Direction,
0.90F + 0.10F * world.rand.nextFloat(), 0.35F + 0.25F * world.rand.nextFloat(), 0.30F + 0.15F * world.rand.nextFloat(),
0.0F, 0.0F, 0.0F, 32);
/*
@ -313,7 +313,7 @@ public enum EnumForceFieldUpgrade implements IForceFieldUpgrade, IForceFieldUpgr
v3Direction.scale(0.15D);
PacketHandler.sendBeamPacket(world, v3Projector, v3Entity,
0.35F, 0.57F, 0.87F, 10, 0, 50);
PacketHandler.sendSpawnParticlePacket(world, "fireworksSpark", v3Entity, v3Direction,
PacketHandler.sendSpawnParticlePacket(world, "fireworksSpark", (byte) 5, v3Entity, v3Direction,
0.20F + 0.30F * world.rand.nextFloat(), 0.50F + 0.15F * world.rand.nextFloat(), 0.75F + 0.25F * world.rand.nextFloat(),
0.10F + 0.20F * world.rand.nextFloat(), 0.10F + 0.30F * world.rand.nextFloat(), 0.20F + 0.10F * world.rand.nextFloat(),
32);

View file

@ -21,6 +21,7 @@ import cr0s.warpdrive.data.Vector3;
public class MessageSpawnParticle implements IMessage, IMessageHandler<MessageSpawnParticle, IMessage> {
private String type;
private byte quantity;
private Vector3 origin;
private Vector3 direction;
private float baseRed;
@ -34,10 +35,11 @@ public class MessageSpawnParticle implements IMessage, IMessageHandler<MessageSp
// required on receiving side
}
public MessageSpawnParticle(final String type, final Vector3 origin, final Vector3 direction,
public MessageSpawnParticle(final String type, final byte quantity, final Vector3 origin, final Vector3 direction,
final float baseRed, final float baseGreen, final float baseBlue,
final float fadeRed, final float fadeGreen, final float fadeBlue) {
this.type = type;
this.quantity = quantity;
this.origin = origin;
this.direction = direction;
this.baseRed = baseRed;
@ -54,6 +56,8 @@ public class MessageSpawnParticle implements IMessage, IMessageHandler<MessageSp
type = buffer.toString(buffer.readerIndex(), typeSize, StandardCharsets.US_ASCII);
buffer.skipBytes(typeSize);
quantity = buffer.readByte();
double x = buffer.readDouble();
double y = buffer.readDouble();
double z = buffer.readDouble();
@ -76,6 +80,7 @@ public class MessageSpawnParticle implements IMessage, IMessageHandler<MessageSp
public void toBytes(ByteBuf buffer) {
buffer.writeByte(type.length());
buffer.writeBytes(type.getBytes(StandardCharsets.US_ASCII), 0, type.length());
buffer.writeByte(quantity);
buffer.writeDouble(origin.x);
buffer.writeDouble(origin.y);
buffer.writeDouble(origin.z);
@ -102,7 +107,7 @@ public class MessageSpawnParticle implements IMessage, IMessageHandler<MessageSp
// adjust color as needed
EntityFX effect;
double noiseLevel = direction.getMagnitude() * 0.35D;
for (int i = 0; i < 5; i++) {
for (int i = 0; i < quantity; i++) {
Vector3 directionRandomized = new Vector3(
direction.x + noiseLevel * (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()),
direction.y + noiseLevel * (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()),
@ -154,9 +159,10 @@ public class MessageSpawnParticle implements IMessage, IMessageHandler<MessageSp
}
if (WarpDriveConfig.LOGGING_EFFECTS) {
WarpDrive.logger.info("Received particle effect '" + messageSpawnParticle.type + "' from " + messageSpawnParticle.origin + " toward " + messageSpawnParticle.direction
+ " as RGB " + messageSpawnParticle.baseRed + " " + messageSpawnParticle.baseGreen + " " + messageSpawnParticle.baseBlue
+ " fading to " + messageSpawnParticle.fadeRed + " " + messageSpawnParticle.fadeGreen + " " + messageSpawnParticle.fadeBlue);
WarpDrive.logger.info("Received particle effect '%s' x %d from %s towards %s as RGB %.2f %.2f %.2f fading to %.2f %.2f %.2f",
messageSpawnParticle.type, messageSpawnParticle.quantity, messageSpawnParticle.origin, messageSpawnParticle.direction,
messageSpawnParticle.baseRed, messageSpawnParticle.baseGreen, messageSpawnParticle.baseBlue,
messageSpawnParticle.fadeRed, messageSpawnParticle.fadeGreen, messageSpawnParticle.fadeBlue);
}
messageSpawnParticle.handle(Minecraft.getMinecraft().theWorld);

View file

@ -91,20 +91,23 @@ public class PacketHandler {
}
// Forced particle effect sent to client side
public static void sendSpawnParticlePacket(World worldObj, final String type, final Vector3 origin, final Vector3 direction,
public static void sendSpawnParticlePacket(World worldObj, final String type, final byte quantity,
final Vector3 origin, final Vector3 direction,
final float baseRed, final float baseGreen, final float baseBlue,
final float fadeRed, final float fadeGreen, final float fadeBlue, final int radius) {
final float fadeRed, final float fadeGreen, final float fadeBlue,
final int radius) {
assert(!worldObj.isRemote);
MessageSpawnParticle messageSpawnParticle = new MessageSpawnParticle(type, origin, direction, baseRed, baseGreen, baseBlue, fadeRed, fadeGreen, fadeBlue);
MessageSpawnParticle messageSpawnParticle = new MessageSpawnParticle(
type, quantity, origin, direction, baseRed, baseGreen, baseBlue, fadeRed, fadeGreen, fadeBlue);
// small beam are sent relative to beam center
simpleNetworkManager.sendToAllAround(messageSpawnParticle, new TargetPoint(
worldObj.provider.dimensionId, origin.x, origin.y, origin.z, radius));
if (WarpDriveConfig.LOGGING_EFFECTS) {
WarpDrive.logger.info("Sent particle effect '" + type + "' from " + origin + " toward " + direction
+ " as RGB " + baseRed + " " + baseGreen + " " + baseBlue + " fading to " + fadeRed + " " + fadeGreen + " " + fadeBlue);
WarpDrive.logger.info(String.format("Sent particle effect '%s' x %d from %s toward %s as RGB %.2f %.2f %.2f fading to %.2f %.2f %.2f",
type, quantity, origin, direction, baseRed, baseGreen, baseBlue, fadeRed, fadeGreen, fadeBlue));
}
}