mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Use vanilla mechanisms to sync TE's instead of rolling own
This commit is contained in:
3 files changed
+13
-23
No files matched your search
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
package vazkii.botania.api.internal;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
@@ -21,23 +22,8 @@ import net.minecraft.world.WorldServer;
|
||||
public final class VanillaPacketDispatcher {
|
||||
|
||||
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
|
||||
if(tile.getWorld() instanceof WorldServer) {
|
||||
WorldServer ws = ((WorldServer) tile.getWorld());
|
||||
SPacketUpdateTileEntity packet = tile.getUpdatePacket();
|
||||
|
||||
if(packet == null)
|
||||
return;
|
||||
|
||||
for (EntityPlayer player : ws.playerEntities) {
|
||||
EntityPlayerMP playerMP = ((EntityPlayerMP) player);
|
||||
|
||||
if (playerMP.getDistanceSq(tile.getPos()) < 64 * 64
|
||||
&& ws.getPlayerChunkMap().isPlayerWatchingChunk(playerMP, tile.getPos().getX() >> 4, tile.getPos().getZ() >> 4)) {
|
||||
playerMP.connection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
|
||||
tile.getWorld().notifyBlockUpdate(tile.getPos(), state, state, 8);
|
||||
}
|
||||
|
||||
public static void dispatchTEToNearbyPlayers(World world, BlockPos pos) {
|
||||
|
||||
@@ -31,12 +31,14 @@ import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import vazkii.botania.api.lexicon.ILexiconable;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.api.wand.IWandHUD;
|
||||
import vazkii.botania.api.wand.IWandable;
|
||||
import vazkii.botania.client.core.handler.ModelHandler;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.BlockMod;
|
||||
import vazkii.botania.common.block.tile.TileEnchanter;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
@@ -112,7 +114,10 @@ public class BlockEnchanter extends BlockMod implements IWandable, ILexiconable,
|
||||
if(stack != null && stack.getItem() == ModItems.twigWand)
|
||||
return false;
|
||||
|
||||
boolean stackEnchantable = stack != null && stack.getItem() != Items.BOOK && stack.isItemEnchantable() && stack.stackSize == 1 && stack.getItem().getItemEnchantability(stack) > 0;
|
||||
boolean stackEnchantable = stack != null
|
||||
&& stack.getItem() != Items.BOOK
|
||||
&& stack.isItemEnchantable()
|
||||
&& stack.stackSize == 1;
|
||||
|
||||
if(enchanter.itemToEnchant == null) {
|
||||
if(stackEnchantable) {
|
||||
@@ -121,10 +126,9 @@ public class BlockEnchanter extends BlockMod implements IWandable, ILexiconable,
|
||||
enchanter.sync();
|
||||
}
|
||||
} else if(enchanter.stage == TileEnchanter.State.IDLE) {
|
||||
if(player.inventory.addItemStackToInventory(enchanter.itemToEnchant.copy())) {
|
||||
enchanter.itemToEnchant = null;
|
||||
enchanter.sync();
|
||||
} else player.addChatMessage(new TextComponentTranslation("botaniamisc.invFull"));
|
||||
ItemHandlerHelper.giveItemToPlayer(player, enchanter.itemToEnchant.copy());
|
||||
enchanter.itemToEnchant = null;
|
||||
enchanter.sync();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -371,7 +371,7 @@ public class TileEnchanter extends TileMod implements ISparkAttachable {
|
||||
}
|
||||
|
||||
private boolean isEnchantmentValid(Enchantment ench) {
|
||||
if(!ench.canApply(itemToEnchant) || !ench.type.canEnchantItem(itemToEnchant.getItem()))
|
||||
if(!ench.canApply(itemToEnchant))
|
||||
return false;
|
||||
|
||||
for(EnchantmentData data : enchants) {
|
||||
|
||||
Reference in new issue
Block a user