Search in sources :

Example 21 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project Random-Things by lumien231.

the class TileEntityBlockBreaker method initFakePlayer.

private void initFakePlayer() {
    if (uuid == null) {
        uuid = UUID.randomUUID();
        syncTE();
    }
    fakePlayer = new WeakReference<>(FakePlayerFactory.get((WorldServer) world, breakerProfile));
    ItemStack unbreakingIronPickaxe = new ItemStack(Items.IRON_PICKAXE, 1);
    unbreakingIronPickaxe.setTagCompound(new NBTTagCompound());
    unbreakingIronPickaxe.getTagCompound().setBoolean("Unbreakable", true);
    HashMap<Enchantment, Integer> enchantmentMap = new HashMap<>();
    enchantmentMap.put(ModEnchantments.magnetic, 1);
    EnchantmentHelper.setEnchantments(enchantmentMap, unbreakingIronPickaxe);
    fakePlayer.get().setHeldItem(EnumHand.MAIN_HAND, unbreakingIronPickaxe);
    fakePlayer.get().onGround = true;
    fakePlayer.get().connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer.get()) {

        @Override
        public void sendPacket(Packet packetIn) {
        }
    };
}
Also used : Packet(net.minecraft.network.Packet) HashMap(java.util.HashMap) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) NetworkManager(net.minecraft.network.NetworkManager) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer)

Example 22 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project ArsMagica2 by Mithion.

the class AMPacketProcessorServer method onServerPacketData.

@SubscribeEvent
public void onServerPacketData(ServerCustomPacketEvent event) {
    ByteBufInputStream bbis = new ByteBufInputStream(event.packet.payload());
    byte packetID = -1;
    try {
        if (event.packet.getTarget() != Side.SERVER) {
            return;
        }
        // constant details all packets share:  ID, player, and remaining data
        packetID = bbis.readByte();
        NetHandlerPlayServer srv = (NetHandlerPlayServer) event.packet.handler();
        EntityPlayerMP player = srv.playerEntity;
        byte[] remaining = new byte[bbis.available()];
        bbis.readFully(remaining);
        switch(packetID) {
            case AMPacketIDs.SPELL_SHAPE_GROUP_CHANGE:
                handleCastingModeChange(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.MAGIC_LEVEL_UP:
                handleMagicLevelUp(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SYNC_BETA_PARTICLES:
                handleSyncBetaParticles(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.POSSIBLE_CLIENT_EXPROP_DESYNC:
                handlePossibleClientExpropDesync(remaining);
                break;
            case AMPacketIDs.REQUEST_BETA_PARTICLES:
                handleRequestBetaParticles(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SPELL_CUSTOMIZE:
                handleSpellCustomize(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SPELLBOOK_CHANGE_ACTIVE_SLOT:
                handleSpellBookChangeActiveSlot(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SYNC_SPELL_KNOWLEDGE:
                handleSyncSpellKnowledge(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.DECO_BLOCK_UPDATE:
                handleDecoBlockUpdate(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.INSCRIPTION_TABLE_UPDATE:
                handleInscriptionTableUpdate(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.TK_DISTANCE_SYNC:
                ExtendedProperties.For((EntityPlayerMP) player).TK_Distance = new AMDataReader(remaining).getFloat();
                break;
            case AMPacketIDs.SAVE_KEYSTONE_COMBO:
                handleSaveKeystoneCombo(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SET_KEYSTONE_COMBO:
                handleSetKeystoneCombo(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SET_MAG_WORK_REC:
                handleSetMagiciansWorkbenchRecipe(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.RUNE_BAG_GUI_OPEN:
                handleRuneBagGUIOpen(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.M_BENCH_LOCK_RECIPE:
                handleMBenchLockRecipe(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.IMBUE_ARMOR:
                handleImbueArmor(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.REQUEST_PWR_PATHS:
                handlePowerPathSync(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SYNC_EXTENDED_PROPS:
                handleExpropOperation(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.AFFINITY_ACTIVATE:
                handleAffinityActivate(remaining, player);
                break;
        }
    } catch (Throwable t) {
        LogHelper.error("Server Packet Failed to Handle!");
        LogHelper.error("Packet Type: " + packetID);
        t.printStackTrace();
    } finally {
        try {
            if (bbis != null)
                bbis.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 23 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project RecurrentComplex by Ivorforce.

the class PacketSaveStructureHandler method processServer.

@Override
public void processServer(PacketSaveStructure message, MessageContext ctx, WorldServer server) {
    NetHandlerPlayServer netHandlerPlayServer = ctx.getServerHandler();
    EntityPlayerMP player = netHandlerPlayServer.player;
    if (RecurrentComplex.checkPerms(player))
        return;
    RCEntityInfo entityInfo = RCEntityInfo.get(player, null);
    GenericStructure genericStructureInfo = message.getStructureInfo();
    if (entityInfo != null)
        genericStructureInfo.worldDataCompound = entityInfo.getCachedExportStructureBlockDataNBT();
    SaveDirectoryData.Result saveDirectoryDataResult = message.getSaveDirectoryDataResult();
    String id = message.getStructureID();
    ResourceDirectory saveDir = saveDirectoryDataResult.directory;
    write(player, genericStructureInfo, id, saveDir, saveDirectoryDataResult.deleteOther, true);
}
Also used : ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) SaveDirectoryData(ivorius.reccomplex.utils.SaveDirectoryData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 24 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project RecurrentComplex by Ivorforce.

the class PacketSaveLootTableHandler method processServer.

@Override
public void processServer(PacketSaveLootTable message, MessageContext ctx, WorldServer server) {
    NetHandlerPlayServer playServer = ctx.getServerHandler();
    EntityPlayerMP player = playServer.player;
    if (RecurrentComplex.checkPerms(player))
        return;
    SaveDirectoryData.Result saveDirectoryDataResult = message.getSaveDirectoryDataResult();
    String id = message.getKey();
    ResourceDirectory saveDir = saveDirectoryDataResult.directory;
    ResourceDirectory delDir = saveDir.opposite();
    GenericItemCollectionRegistry.INSTANCE.register(id, "", message.getComponent(), saveDir.isActive(), saveDir.getLevel());
    if (RCCommands.informSaveResult((message.getComponent() != null && id != null) && RecurrentComplex.saver.trySave(saveDir.toPath(), RCFileSaver.INVENTORY_GENERATION_COMPONENT, id), player, saveDir, RCFileSaver.INVENTORY_GENERATION_COMPONENT, id)) {
        if (saveDirectoryDataResult.deleteOther)
            RCCommands.informDeleteResult(RecurrentComplex.saver.tryDeleteWithID(delDir.toPath(), RCFileSaver.INVENTORY_GENERATION_COMPONENT, id), player, RCFileSaver.INVENTORY_GENERATION_COMPONENT, id, delDir);
        ItemStack heldItem = playServer.player.getHeldItem(EnumHand.MAIN_HAND);
        if (heldItem != null && heldItem.getItem() instanceof ItemLootTableComponentTag)
            ItemLootTableComponentTag.setComponentKey(heldItem, id);
        player.openContainer.detectAndSendChanges();
    }
}
Also used : ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) SaveDirectoryData(ivorius.reccomplex.utils.SaveDirectoryData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemLootTableComponentTag(ivorius.reccomplex.item.ItemLootTableComponentTag) ItemStack(net.minecraft.item.ItemStack) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer)

Example 25 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ITransformablePacket method doPostProcessing.

/**
 * Restores the player from local coordinates to where they used to be.
 */
default void doPostProcessing(INetHandlerPlayServer server, boolean callingFromSponge) {
    if (isPacketOnMainThread(server, callingFromSponge)) {
        NetHandlerPlayServer serverHandler = (NetHandlerPlayServer) server;
        EntityPlayerMP player = serverHandler.player;
        // If we made a backup in doPreProcessing(), then restore from that backup.
        ICapabilityEntityBackup entityBackup = player.getCapability(VSCapabilityRegistry.VS_ENTITY_BACKUP, null);
        if (entityBackup.hasBackupPosition()) {
            entityBackup.restoreEntityToBackup(player);
        }
    }
}
Also used : ICapabilityEntityBackup(org.valkyrienskies.mod.common.capability.entity_backup.ICapabilityEntityBackup) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) INetHandlerPlayServer(net.minecraft.network.play.INetHandlerPlayServer)

Aggregations

NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)26 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)16 ItemStack (net.minecraft.item.ItemStack)6 GameProfile (com.mojang.authlib.GameProfile)5 NetworkManager (net.minecraft.network.NetworkManager)5 WorldServer (net.minecraft.world.WorldServer)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)3 SaveDirectoryData (ivorius.reccomplex.utils.SaveDirectoryData)3 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 INetHandlerPlayServer (net.minecraft.network.play.INetHandlerPlayServer)3 Entity (net.minecraft.entity.Entity)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 SPacketCustomPayload (net.minecraft.network.play.server.SPacketCustomPayload)2 SPacketSetSlot (net.minecraft.network.play.server.SPacketSetSlot)2 Player (org.spongepowered.api.entity.living.player.Player)2 CauseStackManager (org.spongepowered.api.event.CauseStackManager)2 ICapabilityEntityBackup (org.valkyrienskies.mod.common.capability.entity_backup.ICapabilityEntityBackup)2 FakePlayerItemInWorldManager (pneumaticCraft.common.ai.FakePlayerItemInWorldManager)2