net.minecraftforge.fml.common.network.simpleimpl.MessageContext Java Examples
The following examples show how to use
net.minecraftforge.fml.common.network.simpleimpl.MessageContext.
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: PacketExplode.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void handle(@NotNull MessageContext messageContext) { if (messageContext.side.isServer()) return; World world = LibrarianLib.PROXY.getClientPlayer().world; if (world == null) return; ClientRunnable.run(new ClientRunnable() { @Override @SideOnly(Side.CLIENT) public void runIfClient() { // LibParticles.ParticleExplosion.INSTANCE.spawn(lifeTime, lifeTimeRange, amount, pos, color1, color2, strengthUpwards, strengthSideways); LibParticles.EXPLODE(world, pos, color1, color2, strengthSideways, strengthUpwards, amount, lifeTime, lifeTimeRange, bounce); } }); }
Example #2
Source File: VSGuiButtonHandler.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@Override public IMessage onMessage(VSGuiButtonMessage message, MessageContext ctx) { IThreadListener mainThread = ctx.getServerHandler().server; mainThread.addScheduledTask(() -> { World playerWorld = ctx.getServerHandler().player.world; TileEntity tileEntity = playerWorld.getTileEntity(message.getTileEntityPos()); if (tileEntity == null) { // Nothing there, ignore this message return; } int buttonId = message.getButtonId(); // Tell the tile entity that this player tried pressing the given button. if (tileEntity instanceof IVSTileGui) { ((IVSTileGui) tileEntity).onButtonPress(buttonId, ctx.getServerHandler().player); } }); return null; }
Example #3
Source File: PacketClearCraftingPlate.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void handle(@NotNull MessageContext ctx) { if (ctx.side.isServer()) return; World world = LibrarianLib.PROXY.getClientPlayer().world; if (world == null) return; if (!world.isBlockLoaded(pos)) return; TileEntity entity = world.getTileEntity(pos); if (entity instanceof TileCraftingPlate) { TileCraftingPlate plate = (TileCraftingPlate) entity; // DEBUG // if (plate.renderHandler != null) { // System.out.println("Map has size " + ((TileCraftingPlateRenderer) plate.renderHandler).hoveringStacks.size()); // } for (int i = 0; i < plate.realInventory.getHandler().getSlots(); i++) { plate.realInventory.getHandler().setStackInSlot(i, ItemStack.EMPTY); if (plate.renderHandler != null) { ((TileCraftingPlateRenderer) plate.renderHandler).update(i, ItemStack.EMPTY); } } } }
Example #4
Source File: PacketRemovePearlFromBelt.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void handle(@NotNull MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().player; ItemStack stack = player.getHeldItemMainhand(); if (stack.getItem() instanceof IPearlStorageHolder) { IPearlStorageHolder holder = (IPearlStorageHolder) stack.getItem(); int originalPearlCount = holder.getPearlCount(stack); ItemStack pearl = holder.removePearl(stack, index, true); player.addItemStackToInventory(pearl); int newPearlCount = holder.getPearlCount(stack); PacketHandler.NETWORK.sendTo(new PacketUpdatePearlGUI(originalPearlCount, newPearlCount, index, null, stack.getTagCompound()), player); } }
Example #5
Source File: PacketSwapPearl.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void handle(@NotNull MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().player; ItemStack swappable = player.getHeldItemMainhand(); ItemStack storageStack = BaublesSupport.getItem(player, IPearlStorageHolder.class); IPearlStorageHolder holder = (IPearlStorageHolder) storageStack.getItem(); int originalPearlCount = holder.getPearlCount(storageStack); if (!storageStack.isEmpty() && swappable.getItem() instanceof IPearlSwappable) { ItemStack pearl = ((IPearlSwappable) swappable.getItem()).swapPearl(swappable, holder.removePearl(storageStack, index, false)); holder.addPearl(storageStack, pearl, false); } PacketHandler.NETWORK.sendTo(new PacketUpdatePearlGUI(originalPearlCount, holder.getPearlCount(storageStack), index, swappable.getTagCompound(), storageStack.getTagCompound()), player); }
Example #6
Source File: PhysWrapperPositionHandler.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@Override public IMessage onMessage(final WrapperPositionMessage message, MessageContext ctx) { if (Minecraft.getMinecraft().player == null) { return null; } IThreadListener mainThread = Minecraft.getMinecraft(); mainThread.addScheduledTask(new Runnable() { @Override public void run() { if (Minecraft.getMinecraft().world != null) { Entity ent = Minecraft.getMinecraft().world .getEntityByID(message.getEntityID()); if (ent instanceof PhysicsWrapperEntity) { PhysicsWrapperEntity wrapper = (PhysicsWrapperEntity) ent; wrapper.getPhysicsObject().getShipTransformationManager().serverBuffer .pushMessage(message); } } } }); return null; }
Example #7
Source File: SimpleCraftCommandsImplementation.java From malmo with MIT License | 6 votes |
@Override public IMessage onMessage(CraftMessage message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; // Try crafting recipes first: List<IRecipe> matching_recipes; String[] split = message.parameters.split(" "); matching_recipes = CraftingHelper.getRecipesForRequestedOutput(message.parameters, split.length > 1); for (IRecipe recipe : matching_recipes) { if (CraftingHelper.attemptCrafting(player, recipe)) return null; } // Now try furnace recipes: ItemStack input = CraftingHelper.getSmeltingRecipeForRequestedOutput(message.parameters); if (input != null) { if (CraftingHelper.attemptSmelting(player, input)) return null; } return null; }
Example #8
Source File: InvokeWandMessage.java From pycode-minecraft with MIT License | 6 votes |
private void handle(InvokeWandMessage message, MessageContext ctx) { // note: we only get send types BLOCK and ENTITY and we only handle this message on the server EntityPlayer player = ctx.getServerHandler().playerEntity; switch (message.typeOfHit) { case BLOCK: FMLLog.info("Got a InvokeWandMessage block=%s", message.blockPos); PythonWandItem.invokeOnBlock(player, message.blockPos); case ENTITY: // in theory this should never be invoked on the client... Entity entity = player.worldObj.getEntityByID(message.entityId); FMLLog.info("Got a InvokeWandMessage entity=%s", entity); if (entity == null) return; PythonWandItem.invokeOnEntity(player, entity); break; case MISS: PythonWandItem.invokeInDirection(player, message.hitVec); } }
Example #9
Source File: ObservationFromServer.java From malmo with MIT License | 6 votes |
/** IMPORTANT: Call this from the onMessage method in the subclass. */ public IMessage processMessage(ObservationRequestMessage message, MessageContext ctx) { IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.world; final EntityPlayerMP player = ctx.getServerHandler().playerEntity; final ObservationRequestMessage mess = message; mainThread.addScheduledTask(new Runnable() { @Override public void run() { JsonObject json = new JsonObject(); buildJson(json, player, mess); // Send this message back again now we've filled in the json stats. Map<String, String> returnData = new HashMap<String, String>(); returnData.put("json", json.toString()); mess.addReturnData(returnData); MalmoMod.network.sendTo(new MalmoMod.MalmoMessage(MalmoMessageType.SERVER_OBSERVATIONSREADY, mess.id, returnData), player); } }); return null; // no response in this case }
Example #10
Source File: InventoryCommandsImplementation.java From malmo with MIT License | 6 votes |
@Override public InventoryChangeMessage onMessage(final InventoryMessage message, MessageContext ctx) { final EntityPlayerMP player = ctx.getServerHandler().playerEntity; IThreadListener mainThread = (WorldServer)ctx.getServerHandler().playerEntity.world; mainThread.addScheduledTask(new Runnable() { @Override public void run() { ItemStack[] changes = null; if (message.combine) changes = combineSlots(player, message.invA, message.slotA, message.invB, message.slotB, message.containerPos); else changes = swapSlots(player, message.invA, message.slotA, message.invB, message.slotB, message.containerPos); if (changes != null) MalmoMod.network.sendTo(new InventoryChangeMessage(changes[0], changes[1]), player); } }); return null; }
Example #11
Source File: MessageQuestUpdate.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
@Override public IMessage onMessage(final MessageQuestUpdate message, MessageContext ctx) { if (ctx.side != Side.SERVER) { return null; } final EntityPlayerMP player = ctx.getServerHandler().player; if (player == null) { return null; } final WorldServer worldServer = player.getServerWorld(); worldServer.addScheduledTask(new Runnable() { @Override public void run() { new Worker(message.action).work(message, player); } }); return null; }
Example #12
Source File: PacketAltarAnimation.java From CommunityMod with GNU Lesser General Public License v2.1 | 6 votes |
@Override public IMessage onMessage(PacketAltarAnimation message, MessageContext ctx) { if (ctx.side == Side.CLIENT) { Minecraft.getMinecraft().addScheduledTask(new Runnable() { @Override public void run() { TileEntity tileEntity = Minecraft.getMinecraft().world.getTileEntity(message.pos); if (tileEntity instanceof TileEntityAltar) { ((TileEntityAltar) tileEntity).altarAnimation = message.altarAnimation; } } }); } else { System.out.println("Bad packet (wrong side: SERVER)!"); } return null; }
Example #13
Source File: MessagePlayerStoppedPilotingHandler.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@Override public IMessage onMessage(MessagePlayerStoppedPiloting message, MessageContext ctx) { IThreadListener mainThread = ctx.getServerHandler().server; mainThread.addScheduledTask(() -> { BlockPos pos = message.posToStopPiloting; EntityPlayerMP player = ctx.getServerHandler().player; TileEntity tileEntity = player.world.getTileEntity(pos); if (tileEntity instanceof ITileEntityPilotable) { ((ITileEntityPilotable) tileEntity).playerWantsToStopPiloting(player); } } ); return null; }
Example #14
Source File: MessageBarrelModeUpdate.java From ExNihiloAdscensio with MIT License | 6 votes |
@Override public IMessage onMessage(final MessageBarrelModeUpdate msg, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(new Runnable() { @Override public void run() { TileEntity entity = Minecraft.getMinecraft().player.world.getTileEntity(new BlockPos(msg.x, msg.y, msg.z)); if (entity instanceof TileBarrel) { TileBarrel te = (TileBarrel) entity; te.setMode(msg.modeName); //Minecraft.getMinecraft().thePlayer.worldObj.notifyBlockUpdate(new BlockPos(msg.x, msg.y, msg.z)); } } }); return null; }
Example #15
Source File: MessageSetItemReputationAmount.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
@Override public IMessage onMessage(final MessageSetItemReputationAmount message, MessageContext ctx) { if (ctx.side != Side.CLIENT) { return null; } Minecraft.getMinecraft().addScheduledTask(new Runnable() { @Override public void run() { new Worker().work(message); } }); return null; }
Example #16
Source File: SwitchHeldItemAndRotationPacket.java From Cyberware with MIT License | 5 votes |
@Override public IMessage onMessage(SwitchHeldItemAndRotationPacket message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(new DoSync(message.entityId, message.slot, message.attackerId)); return null; }
Example #17
Source File: GuiPacket.java From Cyberware with MIT License | 5 votes |
public DoSync(MessageContext ctx, int guid, int x, int y, int z) { this.context = ctx; this.guid = guid; this.x = x; this.y = y; this.z = z; }
Example #18
Source File: OpenRadialMenuPacket.java From Cyberware with MIT License | 5 votes |
@Override public IMessage onMessage(OpenRadialMenuPacket message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; DimensionManager.getWorld(player.worldObj.provider.getDimension()).addScheduledTask(new DoSync(player)); return null; }
Example #19
Source File: PacketAddBouncyBlock.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override @SideOnly(Side.CLIENT) public void handle(@NotNull MessageContext ctx) { if (pos == null) return; World world = Minecraft.getMinecraft().world; BounceManager.INSTANCE.forBlock(world, pos, time); BounceBlockRenderer.addBounce(world, pos, time); }
Example #20
Source File: AbstractPacket.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public REQ onMessage(final REQ message, final MessageContext ctx){ if(ctx.side == Side.SERVER) { Signals.proxy.addScheduledTask(() -> { message.handleServerSide(ctx.getServerHandler().player); }, ctx.side == Side.SERVER); } else { Signals.proxy.addScheduledTask(() -> { message.handleClientSide(Signals.proxy.getPlayer()); }, ctx.side == Side.SERVER); } return null; }
Example #21
Source File: DodgePacket.java From Cyberware with MIT License | 5 votes |
@Override public IMessage onMessage(DodgePacket message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(new DoSync(message.entityId)); return null; }
Example #22
Source File: PacketUpdateMiscCapToServer.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public PacketBase reply(@NotNull MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().player; IMiscCapability cap = MiscCapabilityProvider.getCap(player); if (cap != null) { cap.deserializeNBT(tags); } return new PacketUpdateMiscCapToClient(tags); }
Example #23
Source File: PacketSuccPearlsToStorageHolder.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void handle(@NotNull MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().player; ItemStack stack = player.getHeldItemMainhand(); if (stack.getItem() instanceof IPearlStorageHolder) { IPearlStorageHolder holder = (IPearlStorageHolder) stack.getItem(); int originalPearlCount = holder.getPearlCount(stack); holder.succPearls(player); PacketHandler.NETWORK.sendTo(new PacketUpdatePearlGUI(originalPearlCount, holder.getPearlCount(stack), null, stack.getTagCompound()), player); } }
Example #24
Source File: PacketSendSpellToBook.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void handle(@Nonnull MessageContext messageContext) { EntityPlayer player = messageContext.getServerHandler().player; for (ItemStack stack : player.inventory.mainInventory) { if (stack.getItem() == ModItems.BOOK) { NBTHelper.setList(stack, "common_modules", commonModules); NBTHelper.setList(stack, NBTConstants.NBT.SPELL, moduleList); NBTHelper.setBoolean(stack, "has_spell", true); NBTHelper.setInt(stack, "page", 0); } } }
Example #25
Source File: PacketNemezReversal.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void handle(@Nonnull MessageContext ctx) { ClientRunnable.run(new ClientRunnable() { @Override @SideOnly(Side.CLIENT) public void runIfClient() { NemezTracker tracker = NemezEventHandler.getCurrent(); tracker.absorb(nemez.getTagList("root", Constants.NBT.TAG_COMPOUND)); } }); }
Example #26
Source File: PacketUpdateCraftingPlateSlot.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void handle(@NotNull MessageContext ctx) { if (ctx.side.isServer()) return; World world = LibrarianLib.PROXY.getClientPlayer().world; if (world == null) return; if (!world.isBlockLoaded(pos)) return; TileEntity entity = world.getTileEntity(pos); if (entity instanceof TileCraftingPlate) { TileCraftingPlate plate = (TileCraftingPlate) entity; if (!plate.isInventoryEmpty() && CraftingPlateRecipeManager.doesRecipeExistForItem(stack)) { ItemHandlerHelper.insertItem(plate.input.getHandler(), stack, false); } else if (!(CraftingPlateRecipeManager.doesRecipeExistForItem(stack))) { for (int i = 0; i < plate.realInventory.getHandler().getSlots(); i++) { if (plate.realInventory.getHandler().getStackInSlot(i).isEmpty()) { plate.realInventory.getHandler().insertItem(i, stack, false); if (plate.renderHandler != null) { ((TileCraftingPlateRenderer) plate.renderHandler).update(i, stack); } break; } } } } }
Example #27
Source File: PacketSyncContainerFluid.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@Override public IMessage onMessage(PacketSyncContainerFluid message, MessageContext ctx) { EntityPlayer player = CustomStuff4.proxy.getClientPlayer(); if (NetworkHelper.checkThreadAndEnqueue(message, this, ctx, Minecraft.getMinecraft())) return null; if (player.openContainer.windowId == message.windowId && (player.openContainer instanceof ContainerCS4)) { ContainerCS4 container = (ContainerCS4) player.openContainer; container.putFluidInTank(message.tank, message.fluid); } return null; }
Example #28
Source File: NetworkHelper.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
public static <T extends IMessage> boolean checkThreadAndEnqueue(final T message, final IMessageHandler<T, IMessage> handler, final MessageContext ctx, IThreadListener listener) { if (!listener.isCallingFromMinecraftThread()) { listener.addScheduledTask(() -> handler.onMessage(message, ctx)); return true; } return false; }
Example #29
Source File: MessageProcessorUpdate.java From Minecoprocessors with GNU General Public License v3.0 | 5 votes |
@Override public IMessage onMessage(final MessageProcessorUpdate message, MessageContext ctx) { if (message.processorData == null || message.processorData == null) { return null; } IThreadListener mainThread = Minecraft.getMinecraft(); mainThread.addScheduledTask(new Runnable() { @Override public void run() { if (GuiMinecoprocessor.INSTANCE == null) { return; } if (!GuiMinecoprocessor.INSTANCE.getPos().equals(message.pos)) { Minecoprocessors.NETWORK.sendToServer(new MessageEnableGuiUpdates(message.pos, false)); return; } GuiMinecoprocessor.INSTANCE.updateData(message.processorData, message.name); } }); return null; }
Example #30
Source File: PacketKeyMessageHandler.java From Sakura_mod with MIT License | 5 votes |
@Override public IMessage onMessage(PacketKeyMessage message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().player; if(isPlayerHoldingSheath(player)){ ItemStack sheath = getHeldItemSheath(player); ((ItemSheath)sheath.getItem()).sheath_In(player); } return null; }