Dispatch SubTileEntity packets manually rather than relying on markBlockForUpdate. Good for performance, should close #734

This commit is contained in:
Lizbeth Rika committed 2015-04-09 21:50:21 +01:00
1 parent 08890e4cfb
commit 12d91ce302
3 files changed
+35 -2

No files matched your search

@@ -0,0 +1,32 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Apr 9, 2015, 9:38:44 PM (GMT)]
*/
package vazkii.botania.api.internal;
import java.util.List;
import vazkii.botania.common.core.helper.MathHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
public final class VanillaPacketDispatcher {
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
World world = tile.getWorldObj();
List<EntityPlayer> players = world.playerEntities;
for(EntityPlayer player : players)
if(MathHelper.pointDistancePlane(player.posX, player.posZ, tile.xCoord + 0.5, tile.zCoord + 0.5) < 64 && player instanceof EntityPlayerMP)
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(tile.getDescriptionPacket());
}
}
@@ -1,4 +1,4 @@
@API(owner = "Botania", apiVersion = "37", provides = "BotaniaAPI")
@API(owner = "Botania", apiVersion = "38", provides = "BotaniaAPI")
package vazkii.botania.api;
import cpw.mods.fml.common.API;
@@ -23,6 +23,7 @@ import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.wand.IWandBindable;
import cpw.mods.fml.relauncher.Side;
@@ -81,7 +82,7 @@ public class SubTileEntity {
public void readFromPacketNBT(NBTTagCompound cmp) { }
public void sync() {
supertile.getWorldObj().markBlockForUpdate(supertile.xCoord, supertile.yCoord, supertile.zCoord);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(supertile);
}
public String getUnlocalizedName() {