Jump to content

Recommended Posts

Posted (edited)
11 minutes ago, diesieben07 said:

What is a "cubed mc style radius"?

radius is normally in circle style this is radius in mc style radius of 1. circle style has 4 points cube style has more then that depending on the radius

xxx
xyx
xxx

 

I am mostly confused on how to get chunks without creating them if it's null. I think I found the equation of getting radius in chunks though from this post. How does one get chunks and expect null if not loaded already so it doesn't become recursion and lag everything. I don't want to populate or generate it if it doesn't exist

 

Edited by jredfox
Posted (edited)
1 hour ago, diesieben07 said:

What is a "cubed mc style radius"?

Would this make recursion I am trying to avoid it when trying to get chunk radius otherwise it would lag very bad seconds per chunk 

 

	/**
	 * Get chunks from center radius intention is to ignores chunks that haven't been populated yet?
	 */
	public static ArrayList<Chunk> getRadiusChunks(World w, int chunkPosX, int chunkPosZ,int radius) {
		ArrayList<Chunk> chunks = new ArrayList();
		  for (int x = chunkPosX - radius; x <= chunkPosX + radius; x++) {
	            for (int z = chunkPosZ - radius; z <= chunkPosZ + radius; z++) {
	            	if(w.isChunkGeneratedAt(x, z))
	            		chunks.add(w.getChunkFromChunkCoords(x, z));
	            }
		  }
		return chunks;
	}

 

Edited by jredfox
Posted (edited)

isn't solved I got this warning

[17:32:12] [Server thread/WARN] [FML]: Dungeon Tweeks loaded a new chunk (-14, 6  Dimension: -1) during chunk population, causing cascading worldgen lag. Please report this to the mod's issue tracker. This log can be disabled in the Forge config.

 

 

Also I noticed that this might not work with negitive chunks is this correct? What should I do instead math.abs then what?

Edited by jredfox
Posted

If you are in a chunk that has just been populated, you can only (for sure) request the three chunks that are X+ and Z+ of the current one

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
11 hours ago, Draco18s said:

If you are in a chunk that has just been populated, you can only (for sure) request the three chunks that are X+ and Z+ of the current one

I don't want an ify of only scan these chunks I want a radius that will get any loaded chunks already and maybe also ones that doe exists (on disk) but, are dormant

Posted
2 minutes ago, diesieben07 said:

There is no black and white "generated" and "not generated". Chunks may have rough generation (terrain, etc.) being done but they are not populated (trees, other plants, structures, etc.) yet. Requesting those latter chunks will cause them to be populated.

 

Do you want those chunks or not?

I actually saw loaded chunks in one of the classes so there is a way to determine that part. And I might have seen stuff with does exists on disk. I just need to know when chunks are written to disk one they are unloaded? So if it's not written to disk and if it's not loaded I should ignore that chunk.

 

So vanilla keeps track of loaded chunks I might have to do some manual reflection method to determine if it exists on the disk if if not loaded or not on disk return null maybe then the messege would go away. Or would forge still be spamming that console if I loaded a chunk that was already to the disk.

 

If I load a chunk is it forever loaded or does an entity/tile entity need to keep loading it? If so I am not worried about loading unloaded chunks that have been populated and exist on disk but, not loaded into memory

Posted (edited)
7 minutes ago, diesieben07 said:

I am having a real hard time following what you are trying to say.

Why are you trying to check for loaded chunks? Also please clarify what you mean by "loaded". Loaded into RAM? 

because when scanning for an already scanned chunk from my mod such as the blaze spawner going to an already loaded chunk scan radius of 1 to newer chunk and bam find the blaze spawner that is why I am scanning in the radius. yes loaded into ram

 

My code specified only if chunk wasn't loaded to add it to the arraylist  what is wrong with vanilla that simply doing that loads the chunk anyways?

Edited by jredfox
Posted
1 minute ago, diesieben07 said:

I asked why you are checking for loaded chunks. Not why you are scanning.

 

isChunkGeneratedAt should not cause a chunkload. Use the debugger to find out why (or if) it does.

doesn't happen one only the default chunk was added the current chunk.

 

if(w.isChunkGeneratedAt(x, z));

doesn't seem to be causing it the code causing it has to be

chunks.add(w.getChunkFromChunkCoords(x, z));

 

Posted
1 minute ago, diesieben07 said:

Wat?

 

Well, yes, requesting the chunk will load it...

Well if I only can loaded chunks and scan for only generated will it cause any issues with the spawners or does it need those extra chunks?

Posted (edited)
4 minutes ago, diesieben07 said:

Your sentences make no sense, sorry.

  public boolean isChunkGeneratedAt(int x, int z)
    {
        return this.isChunkLoaded(x, z, false) ? true : this.chunkProvider.isChunkGeneratedAt(x, z);
    }

it's checking for both the is generated and is loaded. Forge is saying o no the chunks are loading before we expect them to.

 

I was saying if I use reflection to call world.isChunkLoaded(x,z,false); instead of simply world.isChunkGeneratedAt(x,z) will it cause issues with the spawner I am scanning for not to show up sometimes?

Edited by jredfox
Posted
Just now, diesieben07 said:

Checking if the chunk is generated yet does not check if it is populated (i.e. chunks which are generated but not populated will be accepted as "ok" by your method). But accessing it will cause it to get populated.

 

You must follow Draco's advice.

Actually I could simply create my own method I found some codessss
https://bukkit.org/threads/how-do-you-determine-if-a-chunk-has-been-loaded-and-populated.216667/

 

Chunk c = w.getChunkProvider().getLoadedChunk(x, z);
 if(c.isPopulated())

 

There is also forge fetch dormant chunk then I could check if it is populated already which should return true else do nothing

Posted
8 minutes ago, diesieben07 said:

This will be equivalent to what Draco suggested. Only way too complicated.

maybe equivalent but, mine will also grab the chunks he considers rarely happens so.

Posted (edited)
1 hour ago, diesieben07 said:

This will be equivalent to what Draco suggested. Only way too complicated.

Got it working had to check both loaded and populated chunks. If loaded is null check dormant populated chunks

Edited by jredfox
Posted

Question would calling this ever cause an index out of bounds exception if the chunk is not loaded?

Chunk c = w.getChunkProvider().getLoadedChunk(x, z);

 

Posted (edited)
2 minutes ago, diesieben07 said:

No.

One last quest will using cause any breakage since I don't call chunk.load or populate? I only use it when the loaded chunk is null
 

long pos = ChunkPos.asLong(x, z);
c = net.minecraftforge.common.ForgeChunkManager.fetchDormantChunk(pos, w);

 

Edited by jredfox
Posted (edited)
2 minutes ago, diesieben07 said:

The fact that you ask this shows you should not call it... Why are you randomly calling methods that you do not understand?

 

fetchDormantChunk is an internal method used by Forge to cache Chunk data in RAM to make chunks that rapidly load and unload less taxing. You do not need to call it, it is called from patches to vanilla code already.

Ok how do I get an unloaded chunk without loading it into memory via the world? Then once I determine if it's populated then I should load it into the world temporary then at end of the method unload so it sync's?

Edited by jredfox
Posted (edited)
8 minutes ago, diesieben07 said:

You cannot.

Well if I comment out the lines about getting using the method you don't like it turns into a blaze spawener again. So what's the issue it loads it into ram how do I unload it because I physically need to scan this or maybe I should be using player tick on server side?


So what should I be unloading or should I let the game do that really confused right now because, if I don't use that method then it doesn't do it's job with the wither skele spawners

https://github.com/jredfox/dungeontweeks

 

public static Chunk getLoadedOrPopulatedChunk(World w, int x, int z)
	{
		Chunk c = w.getChunkProvider().getLoadedChunk(x, z);
		if(c == null)
			c = getPopulatedChunk(w,x,z,true);
		return c;
	}
public static Chunk getPopulatedChunk(World w, int x, int z,boolean dormant) {
		Chunk c = null;
		if(!dormant)
			w.getChunkProvider().getLoadedChunk(x, z);
		if(c == null)
		{
			 long pos = ChunkPos.asLong(x, z);
	         c = net.minecraftforge.common.ForgeChunkManager.fetchDormantChunk(pos, w);
	         if(c == null)
	        	 return null;
		}
    	if(c.isPopulated())
    		return c;
    	else
    		return null;
	}

 

Edited by jredfox
Posted
2 minutes ago, diesieben07 said:

I guess actually you will ultimately have to call it, but you can't do it that simple.

You would need to copy what ChunkProviderServer::loadChunk does in some way (and leave out the chunk population), but this is getting quite dangerous, as you might end up with chunks in the world which are not populated and the game will "forget" to populate them until they unload and reload again.

 

Overall this "loading of chunks but not populating them" is not a good idea.

What about this it's seems simple and clean with it unloading the chunk from the world or whatever as soon as I fetch it then it will re-load it when necessary if tile entities are read and update properly because if it's dormant it will do it if it's not it won't

public static Chunk getPopulatedChunk(World w, int x, int z,boolean dormant) {
		Chunk c = null;
		if(!dormant)
			w.getChunkProvider().getLoadedChunk(x, z);
		if(c == null)
		{
			 long pos = ChunkPos.asLong(x, z);
	         c = net.minecraftforge.common.ForgeChunkManager.fetchDormantChunk(pos, w);
	         if(c == null)
	        	 return null;
	         c.onUnload();//if dormant chunk isn't null unload after fetching
		}
    	if(c.isPopulated())
    		return c;
    	else
    		return null;
	}

 

Posted
2 minutes ago, diesieben07 said:
  • Chunk::onUnload does not unload the chunk.
  • You should really change the name of that "dormant" parameter.
  • Your method will not work for chunks which are generated, but are not loaded into memory at the moment.

Then What should I be calling? Everything that the provider server is calling?

Posted (edited)
19 minutes ago, diesieben07 said:
  • Chunk::onUnload does not unload the chunk.
  • You should really change the name of that "dormant" parameter.
  • Your method will not work for chunks which are generated, but are not loaded into memory at the moment.

Edit: I don't think I need dormant chunks do I? Because, by placing blocks into unloaded chunks it would load them right? Well if that's true then it was just something I did that was my fault which I did fix but, I want to be 100% in case your speed with a mod velocity goes like 80 blocks a second and unloads chunks before the next one can load causing issues.

 

But if that's the case that above is going to cause Issues I should still work on getting dormant chunks how should I accomplish this?

Edited by jredfox
Posted (edited)
2 hours ago, diesieben07 said:

25jnbn.jpg

 

Sorry, mate, you just keep spewing out words. It is completely unclear to me what the hell you are talking about and what you are trying to do.

well I thought it meant chunks written to disk but, not loaded into memory made some sense.

 

I am looking for unloaded chunks how do I get unloaded chunks then only if it's not in the process of loading? But, am I already fine or does it need more work I currently now only use loaded chunks radius

 

so what is dormant chunks and when do they get stored to a cache not to be used should I also be grabbing them or nah?

Edited by jredfox
Posted
31 minutes ago, diesieben07 said:

I already explained this above. Dormant chunks are chunks that have been kept in RAM by Forge after they are unloaded in case they are loaded again quickly.

 

What is "it"? Who is loading? I thought you were saying unloaded chunks...

Loaded chunks = already grab them
Dormant chunks = ok don't need them

Unloaded chunks = how does one get them if and only if they are populated, if forge freaks out about generally loading a chunk on populate then I will forget it

 

Hope that's clear just that one last question here thanks. Yes my spawners are working I did something really stupid when converting the event back to the old one

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

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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