NaturesAura/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java

116 lines
5.7 KiB
Java
Raw Normal View History

2018-10-14 14:27:18 +02:00
package de.ellpeck.naturesaura.packet;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.Multiblocks;
2018-10-14 14:27:18 +02:00
import io.netty.buffer.ByteBuf;
2018-10-17 15:02:29 +02:00
import net.minecraft.block.state.IBlockState;
2018-10-14 14:27:18 +02:00
import net.minecraft.client.Minecraft;
import net.minecraft.util.Rotation;
2018-10-17 15:02:29 +02:00
import net.minecraft.util.math.AxisAlignedBB;
2018-10-16 17:48:36 +02:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2018-10-14 14:27:18 +02:00
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 net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class PacketParticles implements IMessage {
2018-10-16 01:36:30 +02:00
private float posX;
private float posY;
private float posZ;
2018-10-16 17:48:36 +02:00
private int type;
2018-10-14 14:27:18 +02:00
2018-10-16 17:48:36 +02:00
public PacketParticles(float posX, float posY, float posZ, int type) {
2018-10-16 01:36:30 +02:00
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
2018-10-16 17:48:36 +02:00
this.type = type;
2018-10-14 14:27:18 +02:00
}
public PacketParticles() {
}
@Override
public void fromBytes(ByteBuf buf) {
2018-10-16 01:36:30 +02:00
this.posX = buf.readFloat();
this.posY = buf.readFloat();
this.posZ = buf.readFloat();
2018-10-16 17:48:36 +02:00
this.type = buf.readInt();
2018-10-14 14:27:18 +02:00
}
@Override
public void toBytes(ByteBuf buf) {
2018-10-16 01:36:30 +02:00
buf.writeFloat(this.posX);
buf.writeFloat(this.posY);
buf.writeFloat(this.posZ);
2018-10-16 17:48:36 +02:00
buf.writeInt(this.type);
2018-10-14 14:27:18 +02:00
}
public static class Handler implements IMessageHandler<PacketParticles, IMessage> {
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(PacketParticles message, MessageContext ctx) {
2018-10-16 17:48:36 +02:00
NaturesAura.proxy.scheduleTask(() -> {
World world = Minecraft.getMinecraft().world;
if (world != null) {
switch (message.type) {
2018-10-18 17:12:20 +02:00
case 0: // Tree ritual: Gold powder
2018-10-16 17:48:36 +02:00
BlockPos pos = new BlockPos(message.posX, message.posY, message.posZ);
Multiblocks.TREE_RITUAL.forEach(world, pos, Rotation.NONE, 'G', dustPos -> {
2018-10-17 15:02:29 +02:00
IBlockState state = world.getBlockState(dustPos);
2018-10-18 17:12:20 +02:00
AxisAlignedBB box = state.getBoundingBox(world, dustPos);
2018-10-16 17:48:36 +02:00
NaturesAura.proxy.spawnMagicParticle(world,
2018-10-17 15:02:29 +02:00
dustPos.getX() + box.minX + (box.maxX - box.minX) * world.rand.nextFloat(),
2018-10-16 17:48:36 +02:00
dustPos.getY() + 0.1F,
2018-10-17 15:02:29 +02:00
dustPos.getZ() + box.minZ + (box.maxZ - box.minZ) * world.rand.nextFloat(),
2018-10-16 17:48:36 +02:00
(float) world.rand.nextGaussian() * 0.01F,
world.rand.nextFloat() * 0.005F + 0.01F,
(float) world.rand.nextGaussian() * 0.01F,
0xf4cb42, 2F, 100, 0F, false, true);
});
2018-10-16 17:48:36 +02:00
break;
2018-10-18 17:12:20 +02:00
case 1: // Tree ritual: Consuming item
2018-10-16 17:48:36 +02:00
for (int i = world.rand.nextInt(20) + 10; i >= 0; i--) {
NaturesAura.proxy.spawnMagicParticle(world,
message.posX + 0.5F, message.posY + 0.9F, message.posZ + 0.5F,
(float) world.rand.nextGaussian() * 0.02F, world.rand.nextFloat() * 0.02F, (float) world.rand.nextGaussian() * 0.02F,
2018-10-17 15:02:29 +02:00
0x89cc37, 1.5F, 50, 0F, false, true);
2018-10-16 17:48:36 +02:00
}
break;
2018-10-18 17:12:20 +02:00
case 2: // Tree ritual: Tree disappearing
2018-10-16 17:48:36 +02:00
for (int i = world.rand.nextInt(5) + 3; i >= 0; i--) {
NaturesAura.proxy.spawnMagicParticle(world,
message.posX + world.rand.nextFloat(), message.posY + world.rand.nextFloat(), message.posZ + world.rand.nextFloat(),
0F, 0F, 0F,
0x33FF33, 1F, 100, 0F, false, true);
}
break;
2018-10-18 17:12:20 +02:00
case 3: // Tree ritual: Spawn result item
2018-10-16 17:48:36 +02:00
for (int i = world.rand.nextInt(10) + 10; i >= 0; i--) {
NaturesAura.proxy.spawnMagicParticle(world,
message.posX, message.posY, message.posZ,
world.rand.nextGaussian() * 0.05F, world.rand.nextGaussian() * 0.05F, world.rand.nextGaussian() * 0.05F,
2018-10-17 15:02:29 +02:00
0x89cc37, 2F, 200, 0F, true, true);
2018-10-16 17:48:36 +02:00
}
break;
2018-10-18 17:12:20 +02:00
case 4: // Nature altar: Conversion
for (int i = world.rand.nextInt(5) + 2; i >= 0; i--) {
NaturesAura.proxy.spawnMagicParticle(world,
message.posX + 0.25F + world.rand.nextFloat() * 0.5F,
message.posY + 0.9F + 0.25F * world.rand.nextFloat(),
message.posZ + 0.25F + world.rand.nextFloat() * 0.5F,
world.rand.nextGaussian() * 0.01F, world.rand.nextFloat() * 0.01F, world.rand.nextGaussian() * 0.01F,
0x00FF00, world.rand.nextFloat() * 1.5F + 0.75F, 40, 0F, false, true);
}
2018-10-16 17:48:36 +02:00
}
}
});
2018-10-14 14:27:18 +02:00
return null;
}
}
}