use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project SilentGems by SilentChaos512.
the class MessageToggleChaosGem method handleMessage.
@Override
public IMessage handleMessage(MessageContext context) {
if (context.side != Side.SERVER)
return null;
EntityPlayer player = context.getServerHandler().player;
Predicate<ItemStack> predicate = s -> s.getItem() instanceof ItemChaosGem;
ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
for (ItemStack stack : stacks) {
if (stack.getItem() instanceof ItemChaosGem) {
ItemChaosGem item = (ItemChaosGem) stack.getItem();
item.setEnabled(stack, !item.isEnabled(stack));
if (item.isEnabled(stack))
item.applyEffects(stack, player);
else
item.removeEffects(stack, player);
if (!all)
return null;
}
}
return null;
}
use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project BuildCraft by BuildCraft.
the class TileAssemblyTable method sendRecipeStateToServer.
public void sendRecipeStateToServer(AssemblyInstruction instruction, EnumAssemblyRecipeState state) {
IMessage message = createMessage(NET_RECIPE_STATE, (buffer) -> {
buffer.writeString(instruction.recipe.getRegistryName().toString());
buffer.writeItemStack(instruction.output);
buffer.writeInt(state.ordinal());
});
MessageManager.sendToServer(message);
}
use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project BuildCraft by BuildCraft.
the class TileBC_Neptune method createAndSendMessage.
public final void createAndSendMessage(int id, EntityPlayerMP player, IPayloadWriter writer) {
if (hasWorld()) {
IMessage message = createMessage(id, writer);
MessageManager.sendTo(message, player);
}
}
use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project BuildCraft by BuildCraft.
the class TileZonePlanner method sendLayerToServer.
public void sendLayerToServer(int index) {
IMessage message = createMessage(NET_PLAN_CHANGE, (buffer) -> {
buffer.writeShort(index);
layers[index].writeToByteBuf(buffer);
});
MessageManager.sendToServer(message);
}
use of net.minecraftforge.fml.common.network.simpleimpl.IMessage in project pnc-repressurized by TeamPneumatic.
the class NetworkHandler method getSplitMessages.
private static List<IMessage> getSplitMessages(IMessage message) {
ByteBuf buf = Unpooled.buffer();
message.toBytes(buf);
byte[] bytes = buf.array();
if (bytes.length < MAX_PAYLOAD_SIZE) {
return Collections.singletonList(message);
} else {
List<IMessage> messages = new ArrayList<>();
messages.add(new PacketMultiHeader(buf.writerIndex(), message.getClass().getName()));
int offset = 0;
while (offset < buf.writerIndex()) {
messages.add(new PacketMultiPart(Arrays.copyOfRange(bytes, offset, Math.min(offset + MAX_PAYLOAD_SIZE, buf.writerIndex()))));
offset += MAX_PAYLOAD_SIZE;
}
return messages;
}
}
Aggregations