net.minecraftforge.fml.common.network.simpleimpl.IMessage Java Examples

The following examples show how to use net.minecraftforge.fml.common.network.simpleimpl.IMessage. 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: MessageRequestPlayerCivilizationSync.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IMessage onMessage(final MessageRequestPlayerCivilizationSync 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() {
			PlayerCivilizationCapabilityImpl.get(player).syncClient();
		}
	});

	return null;
}
 
Example #2
Source File: VSGuiButtonHandler.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@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: PacketSyncClientHandler.java    From GokiStats with MIT License 6 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(S2CStatSync message, MessageContext ctx) {
    EntityPlayer player = Minecraft.getMinecraft().player;
    if (player == null)
        return null;
    StatBase stat = StatBase.stats.get(message.stat);
    Minecraft.getMinecraft().addScheduledTask(() -> {
        if (stat == Stats.MAX_HEALTH)
            player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH)
                    .setBaseValue(20 + message.amount);
        DataHelper.setPlayerRevertStatLevel(player, stat, message.reverted);
        DataHelper.setPlayerStatLevel(player, stat, message.amount);
        GokiStats.log.debug("Loaded stat from server.");
    });
    return null;
}
 
Example #4
Source File: SKnappingPacket.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IMessage onMessage(final SKnappingPacket message, final MessageContext ctx) {
	IThreadListener mainThread = (WorldServer) ctx.getServerHandler().player.world; // or Minecraft.getMinecraft() on the client
	mainThread.addScheduledTask(new Runnable() 
	{
		@Override
		public void run() 
		{
			PlayerInfo pi = PlayerManagerTFC.getInstance().getPlayerInfoFromUUID(ctx.getServerHandler().player.getUniqueID());
			pi.knappingInterface[message.id] = true;
			if(ctx.getServerHandler().player.openContainer != null && ctx.getServerHandler().player.openContainer instanceof ContainerSpecialCrafting)
			{
				if(pi.specialCraftingTypeAlternate == null)
					((ContainerSpecialCrafting)ctx.getServerHandler().player.openContainer).craftMatrix.setInventorySlotContents(message.id, ItemStack.EMPTY);
				else
					((ContainerSpecialCrafting)ctx.getServerHandler().player.openContainer).craftMatrix.setInventorySlotContents(message.id, pi.specialCraftingTypeAlternate);
			}
		}
	});
	return null; // no response in this case
}
 
Example #5
Source File: PacketAltarAnimation.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 #6
Source File: TileEntityEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void sendPacketToWatchers(IMessage message)
{
    World world = this.getWorld();

    if (world instanceof WorldServer)
    {
        WorldServer worldServer = (WorldServer) world;
        int chunkX = this.getPos().getX() >> 4;
        int chunkZ = this.getPos().getZ() >> 4;
        PlayerChunkMap map = worldServer.getPlayerChunkMap();

        for (EntityPlayerMP player : worldServer.getPlayers(EntityPlayerMP.class, Predicates.alwaysTrue()))
        {
            if (map.isPlayerWatchingChunk(player, chunkX, chunkZ))
            {
                PacketHandler.INSTANCE.sendTo(message, player);
            }
        }
    }
}
 
Example #7
Source File: CMapPacket.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IMessage onMessage(final CMapPacket message, MessageContext ctx) {
	IThreadListener mainThread = net.minecraft.client.Minecraft.getMinecraft(); //(WorldServer) ctx.getServerHandler().playerentityIn.world; // or Minecraft.getMinecraft() on the client
	mainThread.addScheduledTask(new Runnable() 
	{
		@Override
		public void run() 
		{
			if(WorldGen.getInstance().worldSeed == Long.MIN_VALUE)
			{
				WorldGen.getInstance().worldSeed = message.seed - Helper.combineCoords(message.islandX, message.islandZ);
				ClientRenderHandler.IsGeneratingFirstIsland = true;

			}
			//WorldGen.getInstance().createIsland(message.islandX, message.islandZ, message.seed, true);
			WorldGen.getInstance().forceBuildIsland(message.islandX, message.islandZ, message.seed);

		}
	});
	return null; // no response in this case
}
 
Example #8
Source File: SMapRequestPacket.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IMessage onMessage(final SMapRequestPacket message, final MessageContext ctx) {
	IThreadListener mainThread = (WorldServer) ctx.getServerHandler().player.world; // or Minecraft.getMinecraft() on the client
	mainThread.addScheduledTask(new Runnable() 
	{
		@Override
		public void run() 
		{
			int j;
			IslandMap map = WorldGen.getInstance().getIslandMap(message.islandX, message.islandZ);
			long seed = ctx.getServerHandler().player.world.getSeed()+Helper.combineCoords(message.islandX, message.islandZ);
			TFC.network.sendTo(new CMapPacket(message.islandX, message.islandZ, seed), ctx.getServerHandler().player);
		}
	});
	return null; // no response in this case
}
 
Example #9
Source File: PacketSyncClientHandler.java    From GokiStats with MIT License 6 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(S2CSyncAll message, MessageContext ctx) {
    EntityPlayer player = Minecraft.getMinecraft().player;
    if (player == null)
        return null;
    Minecraft.getMinecraft().addScheduledTask(() -> {
        for (int i = 0; i < message.statLevels.length; i++) {
            DataHelper.setPlayerStatLevel(player,
                    StatBase.stats.get(i),
                    message.statLevels[i]);
        }
        for (int i = 0; i < message.revertedStatLevels.length; i++) {
            DataHelper.setPlayerRevertStatLevel(player, StatBase.stats.get(i), message.revertedStatLevels[i]);
        }
        player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH)
                .setBaseValue(20 + DataHelper.getPlayerStatLevel(player, Stats.MAX_HEALTH));
        GokiStats.log.debug("Loaded stats from server.");
    });
    return null;
}
 
Example #10
Source File: PhysWrapperPositionHandler.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: PilotControlsMessageHandler.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@Override
    public IMessage onMessage(final PilotControlsMessage message, final MessageContext ctx) {
        IThreadListener mainThread = ctx.getServerHandler().server;
        mainThread.addScheduledTask(new Runnable() {
            @Override
            public void run() {
                World worldObj = ctx.getServerHandler().player.world;
                if (ValkyrienSkiesMod.VS_PHYSICS_MANAGER.getManagerForWorld(worldObj) != null) {
//                    UUID shipId = message.shipFor;
                    BlockPos posFor = message.controlBlockPos;
                    TileEntity tile = worldObj.getTileEntity(posFor);

                    if (tile instanceof ITileEntityPilotable) {
                        ((ITileEntityPilotable) tile)
                            .onPilotControlsMessage(message, ctx.getServerHandler().player);
                    }
                }
            }
        });

        return null;
    }
 
Example #12
Source File: NetworkHandler.java    From IGW-mod with GNU General Public License v2.0 6 votes vote down vote up
private static List<IMessage> getSplitMessages(IMessage message){
    List<IMessage> messages = new ArrayList<IMessage>();
    ByteBuf buf = Unpooled.buffer();
    message.toBytes(buf);
    byte[] bytes = buf.array();
    if(bytes.length < MAX_SIZE) {
        messages.add(message);
    } else {
        messages.add(new MessageMultiHeader(bytes.length));
        int offset = 0;
        while(offset < bytes.length) {
            messages.add(new MessageMultiPart(Arrays.copyOfRange(bytes, offset, Math.min(offset + MAX_SIZE, bytes.length))));
            offset += MAX_SIZE;
        }
    }
    return messages;
}
 
Example #13
Source File: MessageBarrelModeUpdate.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@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 #14
Source File: MessageFluidUpdate.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@Override
public IMessage onMessage(final MessageFluidUpdate 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;
				Fluid fluid = FluidRegistry.getFluid(msg.fluidName);
				FluidStack f = fluid == null ? null : new FluidStack(fluid, msg.fillAmount);
				te.getTank().setFluid(f);
			}
		}
	});
	return null;
}
 
Example #15
Source File: MessageCompostUpdate.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@Override
public IMessage onMessage(final MessageCompostUpdate 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;
				BarrelModeCompost mode = (BarrelModeCompost) te.getMode();
				mode.setFillAmount(msg.fillAmount);
				mode.setColor(new Color(msg.r, msg.g, msg.b, msg.a));
				mode.setProgress(msg.progress);
			}
		}
	});
	return null;
}
 
Example #16
Source File: SAnvilCraftingPacket.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IMessage onMessage(final SAnvilCraftingPacket message, final MessageContext ctx) {
	final IThreadListener mainThread = (WorldServer) ctx.getServerHandler().player.world; // or Minecraft.getMinecraft() on the client
	mainThread.addScheduledTask(new Runnable() 
	{
		@Override
		public void run() 
		{
			TileEntity te = ((WorldServer)mainThread).getTileEntity(message.pos);
			if(te != null && te instanceof TileAnvil)
			{
				((TileAnvil)te).setAnvilRecipeIndex(message.recipe);
				if(message.startedCrafting)
				{
					((TileAnvil)te).startCrafting(message.smithID);
				}
			}
		}
	});
	return null; // no response in this case
}
 
Example #17
Source File: MessageQuestUpdate.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
@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 #18
Source File: CAnvilStrikePacket.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IMessage onMessage(final CAnvilStrikePacket message, MessageContext ctx) {
	IThreadListener mainThread = net.minecraft.client.Minecraft.getMinecraft(); //(WorldServer) ctx.getServerHandler().playerentityIn.world; // or Minecraft.getMinecraft() on the client
	mainThread.addScheduledTask(new Runnable() 
	{
		@Override
		public void run() 
		{
			TileEntity te = net.minecraft.client.Minecraft.getMinecraft().world.getTileEntity(message.pos);
			if(te != null)
			{
				TileAnvil anvil = (TileAnvil)te;
				anvil.setStrikePoint(message.strikeIndex, message.strikePoint);
			}
		}
	});
	return null; // no response in this case
}
 
Example #19
Source File: SimpleCraftCommandsImplementation.java    From malmo with MIT License 6 votes vote down vote up
@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 #20
Source File: SubspacedEntityRecordHandler.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IMessage onMessage(final SubspacedEntityRecordMessage message,
    final MessageContext ctx) {
    IThreadListener threadScheduler = null;
    World world = null;
    if (ctx.side.isClient()) {
        // We are receiving this on the client
        threadScheduler = getClientThreadListener();
        world = getClientWorld();
    } else {
        // Otherwise we are receiving this on the server
        threadScheduler = ctx.getServerHandler().server;
        world = ctx.getServerHandler().player.world;
    }
    final World worldFinal = world;
    threadScheduler.addScheduledTask(() -> {
        Entity physicsEntity = worldFinal.getEntityByID(message.physicsObjectWrapperID);
        Entity subspacedEntity = worldFinal.getEntityByID(message.entitySubspacedID);
        if (physicsEntity != null && subspacedEntity != null) {
            PhysicsWrapperEntity wrapperEntity = (PhysicsWrapperEntity) physicsEntity;
            ISubspacedEntityRecord record = message.createRecordForThisMessage(
                (ISubspacedEntity) subspacedEntity, wrapperEntity.getPhysicsObject()
                    .getSubspace());
            IDraggable draggable = (IDraggable) subspacedEntity;
            draggable.setForcedRelativeSubspace(wrapperEntity);
            wrapperEntity.getPhysicsObject().getSubspace()
                .forceSubspaceRecord(record.getParentEntity(), record);
            // Now just synchronize the player to the data sent by the client.
        } else {
            System.err.println("An incorrect SubspacedEntityRecordMessage has been thrown out");
        }
    });
    return null;
}
 
Example #21
Source File: OpenRadialMenuPacket.java    From Cyberware with MIT License 5 votes vote down vote up
@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 #22
Source File: BackpacksChannel.java    From WearableBackpacks with MIT License 5 votes vote down vote up
/** Sends a message to a everyone tracking an entity. If sendToEntity is
 *  true and the entity is a player, also sends the message to them. */
public void sendToAllTracking(IMessage message, Entity entity, boolean sendToEntity) {
	((WorldServer)entity.world).getEntityTracker()
		.sendToTracking(entity, getPacketFrom(message));
	if (sendToEntity && (entity instanceof EntityPlayer))
		sendTo(message, (EntityPlayer)entity);
}
 
Example #23
Source File: ParticlePacket.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public IMessage onMessage(ParticlePacket message, MessageContext ctx)
{
	Minecraft.getMinecraft().addScheduledTask(new DoSync(message.effectId, message.x, message.y, message.z));

	return null;
}
 
Example #24
Source File: SurgeryRemovePacket.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public IMessage onMessage(SurgeryRemovePacket message, MessageContext ctx)
{
	DimensionManager.getWorld(message.dimensionId).addScheduledTask(new DoSync(message.pos, message.dimensionId, message.slotNumber, message.isNull));

	return null;
}
 
Example #25
Source File: ScannerSmashPacket.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public IMessage onMessage(ScannerSmashPacket message, MessageContext ctx)
{
	Minecraft.getMinecraft().addScheduledTask(new DoSync(message.x, message.y, message.z));

	return null;
}
 
Example #26
Source File: MessageKeyPressed.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageKeyPressed message, MessageContext ctx)
{
    if (ctx.side != Side.SERVER)
    {
        EnderUtilities.logger.error("Wrong side in MessageKeyPressed: " + ctx.side);
        return null;
    }

    final EntityPlayerMP sendingPlayer = ctx.getServerHandler().player;
    if (sendingPlayer == null)
    {
        EnderUtilities.logger.error("Sending player was null in MessageKeyPressed");
        return null;
    }

    final WorldServer playerWorldServer = sendingPlayer.getServerWorld();
    if (playerWorldServer == null)
    {
        EnderUtilities.logger.error("World was null in MessageKeyPressed");
        return null;
    }

    playerWorldServer.addScheduledTask(new Runnable()
    {
        public void run()
        {
            processMessage(message, sendingPlayer);
        }
    });

    return null;
}
 
Example #27
Source File: EngineeringSwitchArchivePacket.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public IMessage onMessage(EngineeringSwitchArchivePacket message, MessageContext ctx)
{
	DimensionManager.getWorld(message.dimensionId).addScheduledTask(new DoSync(message.pos, message.dimensionId, message.entityId, message.direction, message.isComponent));

	return null;
}
 
Example #28
Source File: SwitchHeldItemAndRotationPacket.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public IMessage onMessage(SwitchHeldItemAndRotationPacket message, MessageContext ctx)
{
	Minecraft.getMinecraft().addScheduledTask(new DoSync(message.entityId, message.slot, message.attackerId));

	return null;
}
 
Example #29
Source File: MessageGuiAction.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageGuiAction message, MessageContext ctx)
{
    if (ctx.side != Side.SERVER)
    {
        EnderUtilities.logger.error("Wrong side in MessageGuiAction: " + ctx.side);
        return null;
    }

    final EntityPlayerMP sendingPlayer = ctx.getServerHandler().player;
    if (sendingPlayer == null)
    {
        EnderUtilities.logger.error("Sending player was null in MessageGuiAction");
        return null;
    }

    final WorldServer playerWorldServer = sendingPlayer.getServerWorld();
    if (playerWorldServer == null)
    {
        EnderUtilities.logger.error("World was null in MessageGuiAction");
        return null;
    }

    playerWorldServer.addScheduledTask(new Runnable()
    {
        public void run()
        {
            processMessage(message, sendingPlayer);
        }
    });

    return null;
}
 
Example #30
Source File: MessageSetQuestInfo.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageSetQuestInfo 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;
}