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) {
}
};
}
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();
}
}
}
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);
}
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();
}
}
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);
}
}
}
Aggregations