Posted December 12, 201212 yr 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
December 12, 201212 yr 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.