net.minecraft.entity.player.ServerPlayerEntity Java Examples
The following examples show how to use
net.minecraft.entity.player.ServerPlayerEntity.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public static void openContainer(ServerPlayerEntity player, INamedContainerProvider containerProvider, Consumer<MCDataOutput> packetConsumer) { if (player.world.isRemote()) { return; } player.closeContainer(); player.getNextWindowId(); int containerId = player.currentWindowId; Container container = containerProvider.createMenu(containerId, player.inventory, player); ContainerType<?> type = container.getType(); PacketCustom packet = new PacketCustom(CCLNetwork.NET_CHANNEL, C_OPEN_CONTAINER); packet.writeRegistryIdUnsafe(ForgeRegistries.CONTAINERS, type); packet.writeVarInt(containerId); packet.writeTextComponent(containerProvider.getDisplayName()); packetConsumer.accept(packet); packet.sendToPlayer(player); player.openContainer = container; player.openContainer.addListener(player); MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container)); }
Example #2
Source File: PacketGhostSlot.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketGhostSlot msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); if (sender == null) return; Container container = sender.openContainer; if (container == null) return; Slot slot = container.inventorySlots.get(msg.slotNumber); if (slot instanceof GhostSlot) slot.putStack(msg.stack); }); ctx.get().setPacketHandled(true); }
Example #3
Source File: PacketUpdateUpgrade.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketUpdateUpgrade msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; Upgrade upgrade = UpgradeTools.getUpgradeByName(msg.upgrade); if( upgrade == null ) return; ItemStack stack = MiningGadget.getGadget(player); UpgradeTools.updateUpgrade(stack, upgrade); //todo: change. }); ctx.get().setPacketHandled(true); }
Example #4
Source File: PacketChangeColor.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketChangeColor msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningProperties.setColor(stack, msg.red, MiningProperties.COLOR_RED); MiningProperties.setColor(stack, msg.green, MiningProperties.COLOR_GREEN); MiningProperties.setColor(stack, msg.blue, MiningProperties.COLOR_BLUE); MiningProperties.setColor(stack, msg.red_inner, MiningProperties.COLOR_RED_INNER); MiningProperties.setColor(stack, msg.green_inner, MiningProperties.COLOR_GREEN_INNER); MiningProperties.setColor(stack, msg.blue_inner, MiningProperties.COLOR_BLUE_INNER); }); ctx.get().setPacketHandled(true); }
Example #5
Source File: PacketExtractUpgrade.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketExtractUpgrade msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; World world = player.world; BlockPos pos = msg.pos; TileEntity te = world.getTileEntity(pos); if (!(te instanceof ModificationTableTileEntity)) return; ModificationTableContainer container = ((ModificationTableTileEntity) te).getContainer(player); ModificationTableCommands.extractButton(container, player, msg.upgrade); }); ctx.get().setPacketHandled(true); }
Example #6
Source File: PacketChangeRange.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeRange msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningProperties.setBeamRange(stack, msg.range); }); ctx.get().setPacketHandled(true); }
Example #7
Source File: EnderStorageSPH.java From EnderStorage with MIT License | 5 votes |
@Override public void handlePacket(PacketCustom packet, ServerPlayerEntity sender, IServerPlayNetHandler handler) { switch (packet.getType()) { case 1: TankSynchroniser.handleVisiblityPacket(sender, packet); break; } }
Example #8
Source File: ModificationTableCommands.java From MiningGadgets with MIT License | 5 votes |
public static void extractButton(ModificationTableContainer container, ServerPlayerEntity player, String upgradeName) { Slot laserSlot = container.inventorySlots.get(0); ItemStack laser = laserSlot.getStack(); if (!(laser.getItem() instanceof MiningGadget)) return; if (!UpgradeTools.containsUpgrades(laser)) return; UpgradeTools.getUpgrades(laser).forEach(upgrade -> { if( !upgrade.getName().equals(upgradeName) ) return; UpgradeTools.removeUpgrade(laser, upgrade); boolean success = player.inventory.addItemStackToInventory(new ItemStack(upgrade.getCard(), 1)); if (!success) { player.dropItem(new ItemStack(upgrade.getCard(), 1), true); } if (upgrade == Upgrade.THREE_BY_THREE) MiningProperties.setRange(laser, 1); // Set both max and default range to MIN_RANGE. if (upgrade.getBaseName().equals(Upgrade.RANGE_1.getBaseName())) { MiningProperties.setBeamRange(laser, MiningProperties.MIN_RANGE); MiningProperties.setBeamMaxRange(laser, UpgradeTools.getMaxBeamRange(0)); } if (upgrade.getBaseName().equals(Upgrade.BATTERY_1.getBaseName())) laser.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> ((EnergisedItem) e).updatedMaxEnergy(UpgradeBatteryLevels.BATTERY.getPower())); }); }
Example #9
Source File: PacketChangeVolume.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeVolume msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setVolume(stack, msg.volume); }); ctx.get().setPacketHandled(true); }
Example #10
Source File: PacketChangeMiningSize.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeMiningSize msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningGadget.changeRange(stack); }); ctx.get().setPacketHandled(true); }
Example #11
Source File: PacketOpenFilterContainer.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketOpenFilterContainer msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); if (sender == null) return; Container container = sender.openContainer; if (container == null) return; ItemStack stack = MiningGadget.getGadget(sender); if( stack.isEmpty() ) return; ItemStackHandler ghostInventory = new ItemStackHandler(30) { @Override protected void onContentsChanged(int slot) { stack.getOrCreateTag().put(MiningProperties.KEY_FILTERS, serializeNBT()); } }; ghostInventory.deserializeNBT(stack.getOrCreateChildTag(MiningProperties.KEY_FILTERS)); sender.openContainer(new SimpleNamedContainerProvider( (windowId, playerInventory, playerEntity) -> new FilterContainer(windowId, playerInventory, ghostInventory), new StringTextComponent("") )); }); ctx.get().setPacketHandled(true); }
Example #12
Source File: SimpleServerPacketHandler.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void handlePacket(PacketCustom packet, ServerPlayerEntity sender, IServerPlayNetHandler handler) { IServerPacketHandler h = handlers.get(packet.getType()); if (h != null) { h.handlePacket(packet, sender, handler); } else { logger.warn("Received unknown packet on channel '{}' with descriptor '{}'.", packet.getChannel(), packet.getType()); } }
Example #13
Source File: PacketToggleFilters.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketToggleFilters msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setWhitelist(stack, !MiningProperties.getWhiteList(stack)); }); ctx.get().setPacketHandled(true); }
Example #14
Source File: PacketTogglePrecision.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketTogglePrecision msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setPrecisionMode(stack, !MiningProperties.getPrecisionMode(stack)); }); ctx.get().setPacketHandled(true); }
Example #15
Source File: PacketChangeFreezeDelay.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeFreezeDelay msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setFreezeDelay(stack, msg.freezeDelay); }); ctx.get().setPacketHandled(true); }
Example #16
Source File: EnderItemStoragePlugin.java From EnderStorage with MIT License | 5 votes |
@Override public void sendClientInfo(ServerPlayerEntity player, List<EnderItemStorage> list) { for (AbstractEnderStorage inv : list) { if (((EnderItemStorage) inv).openCount() > 0) { EnderStorageSPH.sendOpenUpdateTo(player, inv.freq, true); } } }
Example #17
Source File: PacketChangeBreakType.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeBreakType msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningProperties.nextBreakType(stack); }); ctx.get().setPacketHandled(true); }
Example #18
Source File: CommonInterop.java From BoundingBoxOutlineReloaded with MIT License | 5 votes |
public static void playerLoggedIn(ServerPlayerEntity player) { ServerPlayNetHandler connection = player.connection; if (connection == null) return; NetworkManager networkManager = connection.netManager; if (networkManager.isLocalChannel()) return; EventBus.publish(new PlayerLoggedIn(new ServerPlayer(player))); }
Example #19
Source File: ContainerExtended.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void sendSlotContents(@Nonnull Container container, int slot, @Nonnull ItemStack stack) { if (!stack.isEmpty() && stack.getCount() > Byte.MAX_VALUE) { sendLargeStack(stack, slot, playerCrafters); } else { for (ServerPlayerEntity player : playerCrafters) { player.sendSlotContents(container, slot, stack); } } }
Example #20
Source File: PacketHandler.java From MiningGadgets with MIT License | 5 votes |
public static void sendToAll(Object msg, World world) { //Todo Maybe only send to nearby players? for (PlayerEntity player : world.getPlayers()) { if (!(player instanceof FakePlayer)) HANDLER.sendTo(msg, ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT); } }
Example #21
Source File: DryingRackBlock.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Deprecated @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult) { if (worldIn.isRemote) return ActionResultType.SUCCESS; TileEntity tileEntity = worldIn.getTileEntity(pos); if (!(tileEntity instanceof INamedContainerProvider)) return ActionResultType.FAIL; NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity); return ActionResultType.SUCCESS; }
Example #22
Source File: ItemBreakingTracker.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SubscribeEvent public void attachCapabilities(AttachCapabilitiesEvent<Entity> e) { if (!ConfigManager.SERVER.enableScraping.get()) return; final Entity entity = e.getObject(); if (!(entity instanceof ServerPlayerEntity)) return; if (entity.world == null || entity.world.isRemote) return; e.addCapability(PROP_KEY, new ICapabilityProvider() { ItemBreakingTracker cap = new ItemBreakingTracker(); LazyOptional<ItemBreakingTracker> cap_provider = LazyOptional.of(() -> cap); { cap.init(entity, entity.world); } @SuppressWarnings("unchecked") @Override public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) { if (capability == TRACKER) return cap_provider.cast(); return LazyOptional.empty(); } }); }
Example #23
Source File: ItemBreakingTracker.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void onItemBroken(PlayerEntity player, ItemStack stack) { int scrappingLevel = EnchantmentHelper.getEnchantmentLevel(SurvivalistMod.SCRAPING.get(), stack); if (player.getClass().getName().equals("com.rwtema.extrautils2.fakeplayer.XUFakePlayer")) return; boolean fortune = rnd.nextDouble() > 0.9 / (1 + scrappingLevel); ItemStack ret = null; for (Triple<ItemStack, ItemStack, ItemStack> scraping : scrapingRegistry) { ItemStack source = scraping.getLeft(); if (source.getItem() != stack.getItem()) continue; ItemStack good = scraping.getMiddle(); ItemStack bad = scraping.getRight(); ret = fortune ? good.copy() : bad.copy(); break; } if (ret != null) { SurvivalistMod.LOGGER.debug("Item broke (" + stack + ") and the player got " + ret + " in return!"); SurvivalistMod.channel.sendTo(new ScrapingMessage(stack, ret), ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT); ItemHandlerHelper.giveItemToPlayer(player, ret); } }
Example #24
Source File: SawmillBlock.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult) { if (worldIn.isRemote) return ActionResultType.SUCCESS; TileEntity tileEntity = worldIn.getTileEntity(pos); if (!(tileEntity instanceof INamedContainerProvider)) return ActionResultType.FAIL; NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity); return ActionResultType.SUCCESS; }
Example #25
Source File: ItemEnderPouch.java From EnderStorage with MIT License | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) { ItemStack stack = player.getHeldItem(hand); if (player.isShiftKeyDown()) { return new ActionResult<>(ActionResultType.PASS, stack); } if (!world.isRemote) { Frequency frequency = Frequency.readFromStack(stack); EnderStorageManager.instance(world.isRemote).getStorage(frequency, EnderItemStorage.TYPE).openContainer((ServerPlayerEntity) player, new TranslationTextComponent(stack.getTranslationKey())); } return new ActionResult<>(ActionResultType.SUCCESS, stack); }
Example #26
Source File: PacketCustom.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static void sendToOps(IPacket<?> packet) { OpList opList = ServerUtils.getServer().getPlayerList().getOppedPlayers(); for (ServerPlayerEntity player : ServerUtils.getServer().getPlayerList().getPlayers()) { if (opList.hasEntry(player.getGameProfile())) { sendToPlayer(packet, player); } } }
Example #27
Source File: EnderItemStorage.java From EnderStorage with MIT License | 5 votes |
public void openContainer(ServerPlayerEntity player, ITextComponent title) { ServerUtils.openContainer(player, new SimpleNamedContainerProvider((id, inv, p) -> new ContainerEnderItemStorage(id, inv, EnderItemStorage.this), title),// packet -> { freq.writeToPacket(packet); packet.writeByte(size); }); }
Example #28
Source File: PacketCustom.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static void sendToPlayer(IPacket<?> packet, ServerPlayerEntity player) { if (player == null) { sendToClients(packet); } else { player.connection.sendPacket(packet); } }
Example #29
Source File: ContainerExtended.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void addListener(@Nonnull IContainerListener listener) { if (listener instanceof ServerPlayerEntity) { playerCrafters.add((ServerPlayerEntity) listener); sendContainerAndContentsToPlayer(this, getInventory(), Collections.singletonList((ServerPlayerEntity) listener)); detectAndSendChanges(); } else { super.addListener(listener); } }
Example #30
Source File: ContainerExtended.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void removeListener(@Nonnull IContainerListener listener) { if (listener instanceof ServerPlayerEntity) { playerCrafters.remove(listener); } else { super.removeListener(listener); } }