dalobstah
Members-
Posts
4 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
dalobstah's Achievements
Tree Puncher (2/8)
2
Reputation
-
[1.12.2] [SOLVED] spawnParticle not working
dalobstah replied to dalobstah's topic in Modder Support
Thank you for the help. I got it to work with packets. I'll put the code below for any future googlers @Override public void onUpdate() { setFuse(--this.fuse); if (getFuse() <= 0) { this.setDead(); if (!this.world.isRemote) { world.setBlockState(pos, Blocks.AIR.getDefaultState()); world.createExplosion(null, this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, 4.f, true); } } else { ParticlePacket particlePacket = new ParticlePacket(this.posX, this.posY, this.posZ); NetworkRegistry.TargetPoint target = new TargetPoint(world.provider.getDimension(), this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 20.d); CommonProxy.simpleNetworkWrapper.sendToAllAround(particlePacket, target); } if(world.getBlockState(pos).getBlock() instanceof BlockAir) { this.setDead(); } } //Message and client handler public class ParticlePacket implements IMessage { private boolean messageValid; private double x, y, z; public ParticlePacket() { this.messageValid = false; } public ParticlePacket(double x, double y, double z) { this.x = x; this.y = y; this.z = z; this.messageValid = true; } @Override public void fromBytes(ByteBuf buf) { try { this.x = buf.readDouble(); this.y = buf.readDouble(); this.z = buf.readDouble(); } catch(IndexOutOfBoundsException ioe) { return; } } @Override public void toBytes(ByteBuf buf) { if(!this.messageValid) return; buf.writeDouble(x); buf.writeDouble(y); buf.writeDouble(z); } public static class Handler implements IMessageHandler<ParticlePacket, IMessage> { @Override public IMessage onMessage(ParticlePacket message, MessageContext ctx) { if(!message.messageValid && ctx.side != Side.CLIENT) { return null; } Minecraft minecraft = Minecraft.getMinecraft(); final WorldClient worldClient = minecraft.world; minecraft.addScheduledTask(() -> processMessage(message, worldClient)); return null; } void processMessage(ParticlePacket message, WorldClient worldClient) { worldClient.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, message.x + 0.5D, message.y + 1.0D, message.z + 0.5D, 0.0D, 0.0D, 0.0D); } } } //ClientProxy public static void preInitClientOnly() { CommonProxy.simpleNetworkWrapper.registerMessage(ParticlePacket.Handler.class, ParticlePacket.class, CommonProxy.FUSE_SMOKE, Side.CLIENT); } //CommonProxy public static final byte FUSE_SMOKE = 88; public static SimpleNetworkWrapper simpleNetworkWrapper; public static void preInitCommon() { simpleNetworkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("TestChannel"); simpleNetworkWrapper.registerMessage(ServerHandlerDummy.class, ParticlePacket.class, FUSE_SMOKE, Side.SERVER); } //Server handler public class ServerHandlerDummy implements IMessageHandler<ParticlePacket, IMessage> { @Override public IMessage onMessage(ParticlePacket message, MessageContext ctx) { return null; } } -
[1.12.2] [SOLVED] spawnParticle not working
dalobstah replied to dalobstah's topic in Modder Support
Do you know why this works Minecraft MINECRAFT = Minecraft.getMinecraft(); MINECRAFT.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D); but this doesn't this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D); It works in vanilla code and in other 1.12.2 mods source code I've looked at, but it doesn't work in my code. Is there a reason? -
[1.12.2] [SOLVED] spawnParticle not working
dalobstah replied to dalobstah's topic in Modder Support
I'm spawning the particles on an entity. Nothing I've tried outside of the client proxy has spawned particles. EntityTNTPrimed spawns particles for every player with just this.world.spawnParticle, however that doesn't work at all for me. How would I go about getting the clients aware of particles or using packets? -
I've been trying to get this to work for a few days without much success. Every example I find doesn't work properly and I can't figure out why. public void onUpdate() { --this.fuse; if (this.fuse <= 0) { this.setDead(); if (!this.world.isRemote) { world.setBlockState(pos, Blocks.AIR.getDefaultState()); world.createExplosion(null, this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, 4.f, true); } } else { Main.proxy.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D); } if(world.getBlockState(pos).getBlock() instanceof BlockAir) { this.setDead(); } } //Client proxy @Override public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed) { MINECRAFT.world.spawnParticle(particleType, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed); } ^ This is the only code that has worked at all, however it doesn't spawn particles in LAN or multiplayer. this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D); When I try to use this like in EntityTNTPrimed it doesn't work at all. I also experimented with using WorldServer instead of WorldClient, but that resulted in server crashes. Also, using else if(!this.world.isRemote) instead of just else didn't effect the code.