Jump to content

Teleporting into an unloaded chunk? 1.8


Captain_Admiral

Recommended Posts

Hello there friends :) First time posting so forgive my probable posting of this topic in the wrong area.

 

 

I have an issue concerning changing an entities xyz coordinates to values which are associated with an unloaded chunk. For a player, the player in question will teleport but the chunk they are placed in will not load until the game is restarted. For an entity teleporting into an unloaded chunk everything works fine if they are teleporting on the same tick as a player, but if the player unloads the chunk containing their original coordinates and then tries to load the chunk they should now exist in, the entities instead seem to elope into some irretrievable void from which they never return.

 

Being entirely unfamiliar with chunk loading I thought I'd ask you lovely people where I should start with an issue like this.

 

Here are the methods concerned for reference;

 

affectEntity() - Always called from server side

/**@param distance max distance capped at 1*/
@Override
public void affectEntity(Entity potionEntity, Entity throwingEntity, EntityLivingBase affectedEntity, int amplifier, double distance) {
	if(this.getId() == EEMain.mating.getId()) {
		if(affectedEntity instanceof EntityAnimal) {
			((EntityAnimal)affectedEntity).setInLove((throwingEntity instanceof EntityPlayer? (EntityPlayer)throwingEntity:null));
		}
		if(affectedEntity instanceof EntityWolf) {
			((EntityWolf)affectedEntity).setInLove((throwingEntity instanceof EntityPlayer? (EntityPlayer)throwingEntity:null));
		}
		if(affectedEntity instanceof EntityOcelot) {
			((EntityOcelot)affectedEntity).setInLove((throwingEntity instanceof EntityPlayer? (EntityPlayer)throwingEntity:null));
		}
	}

	if(this.getId() == EEMain.recall.getId()) {
		if(throwingEntity instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer)throwingEntity;
			if(player.getBedLocation() != null) {
				affectedEntity.worldObj.markBlockForUpdate(new BlockPos(player.getBedLocation().getX(), player.getBedLocation().getY() ,player.getBedLocation().getZ()));
				affectedEntity.setPosition(player.getBedLocation().getX(), player.getBedLocation().getY() ,player.getBedLocation().getZ());
				if(affectedEntity instanceof EntityPlayer) {
					EEMain.network.sendTo(new MessageMovePlayer(player.getBedLocation().getX(), player.getBedLocation().getY() ,player.getBedLocation().getZ()), ((EntityPlayerMP) player));
				}
			}
		}
	}

}

 

@Override
	public IMessage onMessage(final MessageMovePlayer message, final MessageContext ctx) {
		IThreadListener mainThread = Minecraft.getMinecraft();
        mainThread.addScheduledTask(new Runnable() {
            @Override
            public void run() {
                Minecraft.getMinecraft().thePlayer.setPosition(message.xPos, message.yPos, message.zPos);
            }
        });
		return null;
	}

 

Any help would be greatly appreciated <3

 

 

Edit: It's also entirely possible this has nothing to do with chunk loading in which case help is definitely appreciated

Link to comment
Share on other sites

First of all, why do you send a packet to the client? If you set the player's position on the server, the client will be notified automatically. See here, but you'll need to update some of the method naameters probably if you are 1.9 or up. 1.9 or up. Also note that the packet I send is just to play a sound client side, nothing else.

Link to comment
Share on other sites

I believe I spoke too soon. Changing the method to setPositionAndUpdate from setPosition seems to have fixed the problem of the chunk not loading (Even though the comment for that method clearly states that the only thing being updated is the previous position values :/). Thank you for your help :).

The problem of other entities not teleporting and disappearing from existence or teleporting but not rendering at all on arrival persists however.

Link to comment
Share on other sites

This was my attempt at forcing nearby client players to recognize that a new entity has popped into existence near them, but it doesn't seem to work 100% of the time. However, if the entity doesn't render right away, it does after a few seconds.

 

As for entities teleporting into unloaded chunks, you will have to first load the chunk, teleport to it, and then mark the chunk as needing to save to disk. You should be able to do this even if there aren't any players in that chunk.

Link to comment
Share on other sites

Ah excellent, the client is working perfectly with the teleported entities now. Thank you so much for your help. Now just to wrap my head around chunk loading in 1.8 (A smart system I guess, if not a little convoluted) and I'm all set.

 

 

Also, huge fan of the Legend of Zelda so I have to say that you have developed a marvelous mod.

Link to comment
Share on other sites

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

    • Solved! Here is my solution: Create my own RenderType.CompositeRenderType that does what i need it to. First you will need to add an access transfomer in your build.gradle (https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/) and paste this there  public net.minecraft.client.renderer.RenderType$CompositeRenderType public net.minecraft.client.renderer.RenderType m_173209_(Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;ILnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType; # create public net.minecraft.client.renderer.RenderStateShard$LineStateShard after that you just create your own CompositeRenderType, here is the code for mine  public static RenderType.CompositeRenderType myOutline = RenderType.CompositeRenderType.create("myLines", DefaultVertexFormat.POSITION_COLOR_NORMAL, VertexFormat.Mode.LINES, 256, RenderType.CompositeState.builder().setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getRendertypeLinesShader)).setLineState(new RenderStateShard.LineStateShard(OptionalDouble.empty())).setLayeringState(new RenderStateShard.LayeringStateShard("view_offset_z_layering", () -> { PoseStack $$0 = RenderSystem.getModelViewStack(); $$0.pushPose(); $$0.scale(0.99975586F, 0.99975586F, 0.99975586F); RenderSystem.applyModelViewMatrix(); }, () -> { PoseStack $$0 = RenderSystem.getModelViewStack(); $$0.popPose(); RenderSystem.applyModelViewMatrix(); })).setTransparencyState(new RenderStateShard.TransparencyStateShard("translucent_transparency", () -> { RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.disableDepthTest(); }, () -> { RenderSystem.disableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); })).setOutputState(new RenderStateShard.OutputStateShard("item_entity_target", () -> { if (Minecraft.useShaderTransparency()) { Minecraft.getInstance().levelRenderer.getItemEntityTarget().bindWrite(false); } }, () -> { if (Minecraft.useShaderTransparency()) { Minecraft.getInstance().getMainRenderTarget().bindWrite(false); } })).setDepthTestState(new RenderStateShard.DepthTestStateShard("always", 519)).setWriteMaskState(new RenderStateShard.WriteMaskStateShard(true, false)).setCullState(new RenderStateShard.CullStateShard(false)).createCompositeState(false)); I hope this helped 🙏 if you have any questions dm me on discord .ducklett
    • Trust in their expertise to handle your situation with precision and discretion.  
    • Me and my friends have a server with our mod pack that we made and we all have the same files. And i was able to play for a while and then all of the sudden when ever i tried to join it kept not responding when it says loading terrain. I dont know what could be the cause of the problem at all. Thank you in advance!
    • I tried with official launchers, the lauchers that you recommended to me and other non-safe launcher, and nothing works, so what's now?  
    • You'd just use this function to register your blocks that you want to be fuels, instead of registerBlock. That's all. 
  • Topics

×
×
  • Create New...

Important Information

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