Jump to content

Recommended Posts

Posted

Hi everyone

 

I am fairly new to modding but know java pretty well. I have been practising basic skills e.g. Creating blocks, Custom Renders, Items, Gui's etc but then i came across particle fx. Ive had a scratch about the mine craft code and made some basic particles.

 

recently i found this video of a mod and decided i wanted to do something similar to it. The video:

 

How would i go about creating Similar like this in which the particle is "projected out" as such and follows the wall line?

 

Thanks if anyone could help me.

Posted

Has anyone done this before? I have a basic particle(copied large smoke) but now i want it so it will float from the walls in the room. The mod i am aiming to design is a mod that adds "ghost" effects using a single block. That block has a gui(completed) that has different selections. I would like it if that block could have particles coming from it and whizzing around the walls similar to the one in the video i posted.

Posted

I thought i would need to override it and add my own but i don't know how i would Implement the movement and i don't know how it would spawn on the walls

 

If you look at the constructor it sets the initial motion and the life of the particles and then the onUpdate() updates the position.  So you would put in what you want -- do you want them to start out in specific directions, move fast or slow, move randomly, move straight or in circles, etc.

 

And to spawn on the walls you just need to set their initial position to be where the wall is.  Whether or not the wall is easy to detect would depend on whether the size and shape of the room is already expected to be a certain way or whether you want your particles to be smart enough to go around any shape and size of room.

 

However, I looked at that video you posted again and it is possible that they did not use particles.  They may just be doing some sort of render effect.

 

Anyway, I think it would be possible for the disco ball in that example to have a TileEntity associated which is controlling the effect.  In fact, if you keep track of the particles that are created, the TileEntity itself should be able to update the position.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I thought i would need to override it and add my own but i don't know how i would Implement the movement and i don't know how it would spawn on the walls

 

If you look at the constructor it sets the initial motion and the life of the particles and then the onUpdate() updates the position.  So you would put in what you want -- do you want them to start out in specific directions, move fast or slow, move randomly, move straight or in circles, etc.

 

And to spawn on the walls you just need to set their initial position to be where the wall is.  Whether or not the wall is easy to detect would depend on whether the size and shape of the room is already expected to be a certain way or whether you want your particles to be smart enough to go around any shape and size of room.

 

However, I looked at that video you posted again and it is possible that they did not use particles.  They may just be doing some sort of render effect.

 

Anyway, I think it would be possible for the disco ball in that example to have a TileEntity associated which is controlling the effect.  In fact, if you keep track of the particles that are created, the TileEntity itself should be able to update the position.

 

I downloaded this mod to play with some mates and found that the classes to do with the Block are as followed:

BlockClass

and a TileEntityBlockClass

(I can't quite remember what they were named)

 

How would i achieve a similar effect with the tile entity because i have never seen anything like this before.

 

EDIT: I have opened the class file to try and see what is going on. This is it:

package maaatin.disco;

import abw;
import asp;
import asx;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;

public class TileEntityDiscoBall extends asp
{
  public int lightsPerRow;
  public int height;
  public int resolution;
  public double[][][] possibleLightCoords;
  public int[][] orientations;
  public double[][][] allLightXCoordinates;
  public double[][][] allLightYCoordinates;
  public double[][][] allLightZCoordinates;
  public int[][][] allOrientations;
  public int lightRange;
  public double angle;
  public boolean initialized;
  public int[][] rand;
  public int counter;
  public double orientationAngle;
  public int speed;

  public TileEntityDiscoBall()
  {
    this.lightsPerRow = 16;
    this.height = 9;
    this.resolution = 300;

    this.possibleLightCoords = new double[3][this.resolution][this.height];
    this.orientations = new int[this.resolution][this.height];

    this.allLightXCoordinates = new double[this.lightsPerRow][this.height][this.resolution];
    this.allLightYCoordinates = new double[this.lightsPerRow][this.height][this.resolution];
    this.allLightZCoordinates = new double[this.lightsPerRow][this.height][this.resolution];
    this.allOrientations = new int[this.lightsPerRow][this.height][this.resolution];

    this.lightRange = 16;
    this.angle = 0.0D;

    this.initialized = false;

    this.rand = new int[60][60];

    this.speed = 100;
  }

  public void h()
  {
    if (!this.initialized)
    {
      initialize();
    }
  }

  @SideOnly(Side.CLIENT)
  public asx getRenderBoundingBox()
  {
    return INFINITE_EXTENT_AABB;
  }

  public void initialize()
  {
    boolean stopLoop = false;
    for (int h = 1; h < this.height; h++)
    {
      if ((!this.k.c(this.l, this.m - h, this.n)) && (!stopLoop))
      {
        this.height = h;
        stopLoop = true;
      }
    }

    for (int h = 0; h < this.height; h++)
    {
      for (int i = 0; i < this.lightsPerRow; i++)
      {
        this.rand[i][h] = this.k.s.nextInt(this.resolution / 10);
      }

    }

    for (int h = 0; h < this.height; h++)
    {
      this.counter = (this.resolution - 1);
      this.angle = 0.0D;
      for (int i = this.resolution - 1; i >= 0; i--)
      {
        getCoords(this.l + 0.5D, this.m + 0.5D - h, this.n + 0.5D, this.k, this.angle, h);
        this.angle += 3.141592653589793D / (this.resolution / 2.0D);
        this.counter -= 1;
      }
    }

    for (int h = 0; h < this.height; h++)
    {
      for (int i = 0; i < this.lightsPerRow; i++)
      {
        for (int j = 0; j < this.resolution; j++)
        {
          this.allLightXCoordinates[i][h][j] = this.possibleLightCoords[0][((j + (this.rand[i][h] + this.resolution * i / this.lightsPerRow)) % this.resolution)][h];
          this.allLightYCoordinates[i][h][j] = this.possibleLightCoords[1][((j + (this.rand[i][h] + this.resolution * i / this.lightsPerRow)) % this.resolution)][h];
          this.allLightZCoordinates[i][h][j] = this.possibleLightCoords[2][((j + (this.rand[i][h] + this.resolution * i / this.lightsPerRow)) % this.resolution)][h];

          this.allOrientations[i][h][j] = this.orientations[((j + (this.rand[i][h] + this.resolution * i / this.lightsPerRow)) % this.resolution)][h];
        }
      }
    }

    this.initialized = true;
  }

  public void getCoords(double x, double y, double z, abw world, double angle, int h)
  {
    boolean coordinateFilled = false;

    for (int i = 1; i < this.lightRange; i++)
    {
      if ((!coordinateFilled) && (!world.c(truncateDoubleToInt(x + i * Math.cos(angle)), (int)y, truncateDoubleToInt(z + i * Math.sin(angle)))))
      {
        if (world.c(truncateDoubleToInt(x + (i - 0.1D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.1D) * Math.sin(angle))))
        {
          fillCoords(0.1D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.2D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.2D) * Math.sin(angle))))
        {
          fillCoords(0.2D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.3D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.3D) * Math.sin(angle))))
        {
          fillCoords(0.3D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.4D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.4D) * Math.sin(angle))))
        {
          fillCoords(0.4D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.5D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.5D) * Math.sin(angle))))
        {
          fillCoords(0.5D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.6D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.6D) * Math.sin(angle))))
        {
          fillCoords(0.6D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.7D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.7D) * Math.sin(angle))))
        {
          fillCoords(0.7D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.8D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.8D) * Math.sin(angle))))
        {
          fillCoords(0.8D, x, y, z, i, h);
        }
        else if (world.c(truncateDoubleToInt(x + (i - 0.9D) * Math.cos(angle)), (int)y, truncateDoubleToInt(z + (i - 0.9D) * Math.sin(angle))))
        {
          fillCoords(0.9D, x, y, z, i, h);
        }
        else
        {
          fillCoords(1.0D, x, y, z, i, h);
        }

        coordinateFilled = true;
      }
    }
  }

  public void fillCoords(double j, double x, double y, double z, int i, int h)
  {
    this.possibleLightCoords[0][this.counter][h] = (x + (i - j) * Math.cos(this.angle));
    this.possibleLightCoords[1][this.counter][h] = y;
    this.possibleLightCoords[2][this.counter][h] = (z + (i - j) * Math.sin(this.angle));

    this.orientations[this.counter][h] = getOrientation(this.possibleLightCoords[0][this.counter][h], this.possibleLightCoords[1][this.counter][h], this.possibleLightCoords[2][this.counter][h]);
  }

  public int getOrientation(double x, double y, double z)
  {
    this.orientationAngle = 0.0D;

    for (int i = 0; i < 4; i++)
    {
      double j = 0.2D;

      if (!this.k.c(truncateDoubleToInt(x + j * Math.cos(this.orientationAngle)), truncateDoubleToInt(y), truncateDoubleToInt(z + j * Math.sin(this.orientationAngle))))
      {
        return i;
      }

      this.orientationAngle += 1.570796326794897D;
    }

    return 0;
  }

  public static int truncateDoubleToInt(double par0)
  {
    return (int)(par0 + 1024.0D) - 1024;
  }
}

 

Now i this abw is World. asp is TileEntity and asx is maybe Block.

I cannot see how this is working just due to the lack of methods actually listed.

 

 

Posted

Look up examples of EntityFX tutorials.

 

The EntityFX will be your custom particle.  It will only reside on the client.

 

What I have done is create a packet class, where my server can say where to generate a particle.  You specifcy a name, location, motion.  I suggest only sending the particle to the world of interest.  You could try area around, but I stuck with world.

 

On the client side, it takes that and if the name is for one of my customFX particles, it generates it for the clients.  If it is a minecraft basic, it generates it as well.

 

 

This has served me well in my mods.

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

The disco ball is a TileEntity which is just fancy way of saying a block that executes logic.  All that codes seems to obviously be calculating the positions of the little lights.  I suppose that those could positions could be used to control particles but it isn't clear since there is no mention of particles in the code you showed.  It could still be some sort of render effect.

 

Anyway, let's go back to what you want to do -- make some ghostly smoke come from some blocks.  The main point is that you should have a TileEntity somewhere (I assume that would be your custom block you mentioned that already has a guy) that searches for the blocks you care about (the walls) and then creates the effect with your particles. 

 

There are probably several ways to do this, but basically your TileEntity just needs to do a "search" around itself to find where the blocks that form the walls are, and then you just control the particle position according to what you find.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

If he just wants smoke particles out of block, that could be done without a tilentity.

Long time Bukkit & Forge Programmer

Happy to try and help

  • 3 weeks later...
Posted

I have been trying for a while now to get a similar effect but with just white squares or grey squares and i couldn't figure it out. Could someone pls run me through this?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.