Jump to content

Recommended Posts

Posted

Hi,

 

I've got a few questions:

 

1. How can I let particles move a specific path.

2. How do I get a "explosion" with particles. So I've got a circle around a block and then all particles move fast away from the block.

 

3. I've saw many people are doing this:

        float currentX = (float) (this.prevPosX + (this.posX - this.prevPosX) * partialTicks);
        float currentY = (float) (this.prevPosX + (this.posX - this.prevPosX) * partialTicks);
        float currentZ = (float) (this.prevPosX + (this.posX - this.prevPosX) * partialTicks);

What does this do?

 

4. How can I set the brightness and color and size of a custom particle?

 

5. What are 'partialTicks'?

 

That's all.

 

I hope someone can help me with this. Never done something before with particle effects.

 

Thx in advance. ;)

Bektor

Developer of Primeval Forest.

Posted

1. Particle is not your everyday Entity. It has no server-side, so only one seeing it is client, therefore - you can't make it move along non-constant path (meaning it generally can't react to server orders).

A constant path (updates defined by client) is possible, just define it if your FX class.

 

2. Spawn a lot of particles, make them move in random directions from center (block)?

 

3. This is partialTick interpolation - game (logical) thread operates with on 20 tick per sec basis. Client rendering logic operates on FPS-basis which only depends on your GPU power. Using logical variables of "prevPosX" and "posX" and interpolating them via partialTick allows FPS-based rendering to display smooth movement (making it NOT update 20 tps).

 

4. GL11.glSomething + GL11.glSomeState (e.g: Blend). - You NEED to learn at least GL basics.

 

5. Read 3.

1.7.10 is no longer supported by forge, you are on your own.

Posted

to 1: Well I could when I would send packets to each player informing them about the path. So basically a path is really hard-coded?

        So such things (

and other effects from other mods ) are really hard-coded? Seems like a lot of code... No other way?

 

to 3: Could you link me something about this. I really want to read more about it because I've never heard of such stuff. I just knew, never do FPS and logic as the same.... like some stupid AAA games do..... (nice games, but not really good in that terms of rendering)

 

to 4: Well, I learned some of the basics. But it was modern OpenGL. ;) Look into the spoiler to see what I mean. (it was never much what I learned back then, but I'm going to buy a OpenGL 4.5 book soon.... hopefully I can just work with matrix stuff without really understanding them because I'm going to learn that in 2 years in school and not yet.... currently doing that in school: an=a1*q^(n-1)

But you could link a book to OpenGL 4.5 which also teaches the GLSL shading language and the math behind if you want. ;)

 

 

 

Thats what I worked with.

This is the rendering code for my background of my small flappy bird which I made with the help of my opengl tutorial which

used flappy bird to teach modern opengl.... never finished the series thought...

 

#version 410 core

layout (location = 0) out vec4 color;

in DATA {
vec2 tc;
} fs_in;

uniform sampler2D tex;

void main() {
color = texture(tex, fs_in.tc);
}

 

#version 410 core

layout (location = 0) in vec4 position;
layout (location = 1) in vec2 tc;

uniform mat4 pr_matrix;
uniform mat4 vw_matrix;

out DATA {
vec2 tc;
} vs_out;

void main() {
gl_Position = pr_matrix * vw_matrix * position;
vs_out.tc = tc;
}

 

 

 

And thx for the answer. ;)

Developer of Primeval Forest.

Posted

1. In short: Yup. Server should never really rely on particles and other way around. They were designed to display client effects, so yes - I think that linked effect is most likely hard-coded client animation which is most likely a little bit different on every client that sees the effect (difference will be coming at least from different time of receiving pakets telling to trigger particle-spawning). As to how they act - well, yeah you can code whatever you like, but it should still be client-only stuff. If you really need server to manipulate something you can always spawn normal Entity on server and apply standard server-client logic.

 

I've seen ppl spawn e.g 10 entities which then in their update method spawn more particles each allowing server-manipulated movements.

You can also mix then - e.g spawn stream of dozens of fire particles in which there is also few server Entities that would ignite hit targets (entities are used because particles are client-only and can lie).

 

3. Well, its pretty basic concept.

 

You take "previousPos" in e.g tick number "1" as starting point. You calculate difference of "currentPos - previousPos" which will give you how much you moved between tick number "1" and "2" on logical side of the game. Then you add this between-movement-amount to starting point, BUT before - you multiply it by "partialTick". PartialTick is a double from 0 to 1 that tells you what part of rendering frame relative to ticks are you in (and how much there are frames is defined by GPU, FPS). So basically the closer you are to firing tick "2", that double will be closed to 1, making movement smooth. Ofc. this is for display only, server still operates on tick logic.

 

4. I highly recommend learning basic-minecraft-rendering.

Lookup Gui.class and its methods. You can extend that class to use them or rewrite them to static utility (like I did, since they for example don't support some stuff, for one I think they only take integers as args, don't remember).

 

You will soon notice that VertexBuffer (previously called WorldRenderer) is just a wrapper aroungd GL's glBegin and addVertex and other methods like colorization, but it is really nice if you use it on 1.9 where you have those VertexFormats and nice colorization.

 

Note that vertexes used by MC are QUADS (which you can say are slower than making 2x TRIANGLES because you leave converting from QUADS to TRIANGLES to GPU, instead of deciding it on CPU).

 

Also note: GL vertexes should always be added anti-clockwise to be drawn face-to-screen.

If you ever want to use other formats: https://en.wikibooks.org/wiki/OpenGL_Programming/GLStart/Tut3

 

As to other stuff - well, a lot of examples (onve you understand 2d rendering) are in hierarchy of Render.class. There you have 3d rendering with translations and scaling. Also note that you always will be doing interpolation when rendering stuff in world.

 

Idk what more I can tell, those basics literally create most of MC rendering code. Most messed up things are probably learning using glStates which when not used with care will cause shitload of problems (especially if you render in some forge events where you are in mid-rendering of other vanilla things).

That I leave to google.

 

Hope it helps :D

 

 

1.7.10 is no longer supported by forge, you are on your own.

  • 3 weeks later...

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

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • 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() ); } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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