Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi,

How can i let my TileEntity send Packets (Server => Player) everytime a Player loads the chunk that contains the TE?

 

I'm looking for a function like onChunkLoaded(), where i can put something like PacketDispatcher.sentToPlayer(myPacket, playerWhoLoadedTheChunk).

 

Does anyone have an idea how to do this?

thx

  • Author

Figured it out. Now my TE only needs to send Packets when a Player loads the containing chunk or when the TE changes (for example its orientation).

 

IChunkLoader.java

 

package teg.common;

import cpw.mods.fml.common.network.Player;

public interface IChunkLoader {

void onChunkLoaded(Player player);

}

 

 

ChunkLoad_ChunkWatchEvent.java

 

package teg.common;

import java.util.HashMap;

import cpw.mods.fml.common.network.Player;

import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.BonemealEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraft.src.TileEntity;

public class ChunkLoad_ChunkWatchEvent {

@ForgeSubscribe
public void chunkLoaded(ChunkWatchEvent event)
{
	//System.out.println(event.chunk.chunkXPos+", "+event.chunk.chunkZPos);
	HashMap teMap = (HashMap)event.player.worldObj.getChunkFromChunkCoords(event.chunk.chunkXPos, event.chunk.chunkZPos).chunkTileEntityMap;
	for(Object tileEntity: teMap.values())
	{
		if(tileEntity instanceof IChunkLoader)
		{
			System.out.println(tileEntity.getClass());
			IChunkLoader clTileEntity = (IChunkLoader) tileEntity;
			Player chunkLoadingPlayer = (Player)event.player;
			clTileEntity.onChunkLoaded(chunkLoadingPlayer);
		}
	}

}
}

 

 

and my TileEntity (which implements IChunkLoader) has a Method onChunkLoaded(Player)

 

	@Override
public void onChunkLoaded(Player player) 
{
	if(side == Side.SERVER)
        {	
        	PacketDispatcher.sendPacketToPlayer(createPacket(this), player);
        }
       
}

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.