Search in sources :

Example 1 with MessageContext

use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext 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;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) Predicate(com.google.common.base.Predicate) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) Message(net.silentchaos512.gems.network.Message) PlayerHelper(net.silentchaos512.lib.util.PlayerHelper) BaublesCompat(net.silentchaos512.gems.compat.BaublesCompat) ItemChaosGem(net.silentchaos512.gems.item.ItemChaosGem) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) ItemChaosGem(net.silentchaos512.gems.item.ItemChaosGem) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 2 with MessageContext

use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project BuildCraft by BuildCraft.

the class TileFiller method readPayload.

@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
    super.readPayload(id, buffer, side, ctx);
    if (side == Side.CLIENT) {
        if (id == NET_RENDER_DATA) {
            builder.readFromByteBuf(buffer);
            readPayload(NET_BOX, buffer, side, ctx);
        } else if (id == NET_GUI_DATA || id == NET_GUI_TICK) {
            readPayload(NET_CAN_EXCAVATE, buffer, side, ctx);
            readPayload(NET_INVERT, buffer, side, ctx);
            readPayload(NET_PATTERN, buffer, side, ctx);
            builder.readFromByteBuf(buffer);
            finished = buffer.readBoolean();
            lockedTicks = buffer.readBoolean() ? (byte) 1 : (byte) 0;
            mode = buffer.readEnumValue(Mode.class);
        } else if (id == NET_BOX) {
            box.readData(buffer);
            markerBox = buffer.readBoolean();
            if (buffer.readBoolean()) {
                UUID volumeBoxId = buffer.readUniqueId();
                VolumeBox volumeBox = world.isRemote ? ClientVolumeBoxes.INSTANCE.volumeBoxes.stream().filter(localVolumeBox -> localVolumeBox.id.equals(volumeBoxId)).findFirst().orElseThrow(NullPointerException::new) : WorldSavedDataVolumeBoxes.get(world).getVolumeBoxFromId(volumeBoxId);
                addon = (AddonFillerPlanner) volumeBox.addons.get(buffer.readEnumValue(EnumAddonSlot.class));
            }
        } else if (id == NET_CAN_EXCAVATE) {
            canExcavate = buffer.readBoolean();
        } else if (id == NET_INVERT) {
            inverted = buffer.readBoolean();
        } else if (id == NET_PATTERN) {
            patternStatement.readFromBuffer(buffer);
        }
    }
    if (side == Side.SERVER) {
        if (id == NET_CAN_EXCAVATE) {
            canExcavate = buffer.readBoolean();
            sendNetworkGuiUpdate(NET_CAN_EXCAVATE);
        }
    }
}
Also used : EnumAccess(buildcraft.lib.tile.item.ItemHandlerManager.EnumAccess) IFillerPattern(buildcraft.api.filler.IFillerPattern) ItemHandlerSimple(buildcraft.lib.tile.item.ItemHandlerSimple) FillerType(buildcraft.builders.filler.FillerType) Side(net.minecraftforge.fml.relauncher.Side) TilesAPI(buildcraft.api.tiles.TilesAPI) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Template(buildcraft.builders.snapshot.Template) IBox(buildcraft.api.core.IBox) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) AddonFillerPlanner(buildcraft.builders.addon.AddonFillerPlanner) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) VolumeBox(buildcraft.core.marker.volume.VolumeBox) TileBC_Neptune(buildcraft.lib.tile.TileBC_Neptune) UUID(java.util.UUID) List(java.util.List) BlockBCBase_Neptune(buildcraft.lib.block.BlockBCBase_Neptune) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) MjBattery(buildcraft.api.mj.MjBattery) Optional(java.util.Optional) ItemBlocks(buildcraft.builders.snapshot.ItemBlocks) IFillerStatementContainer(buildcraft.api.statements.containers.IFillerStatementContainer) MjAPI(buildcraft.api.mj.MjAPI) EnumPipePart(buildcraft.api.core.EnumPipePart) IntStream(java.util.stream.IntStream) Box(buildcraft.lib.misc.data.Box) TemplateBuilder(buildcraft.builders.snapshot.TemplateBuilder) IAreaProvider(buildcraft.api.core.IAreaProvider) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ITileForTemplateBuilder(buildcraft.builders.snapshot.ITileForTemplateBuilder) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) ItemStack(net.minecraft.item.ItemStack) NBTUtilBC(buildcraft.lib.misc.NBTUtilBC) MjBatteryReceiver(buildcraft.lib.mj.MjBatteryReceiver) BoundingBoxUtil(buildcraft.lib.misc.BoundingBoxUtil) IStatementParameter(buildcraft.api.statements.IStatementParameter) ITickable(net.minecraft.util.ITickable) BuildingInfo(buildcraft.builders.snapshot.Template.BuildingInfo) MessageManager(buildcraft.lib.net.MessageManager) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) FullStatement(buildcraft.lib.statement.FullStatement) FillerUtil(buildcraft.builders.filler.FillerUtil) IdAllocator(buildcraft.lib.misc.data.IdAllocator) World(net.minecraft.world.World) IDebuggable(buildcraft.api.tiles.IDebuggable) EnumFacing(net.minecraft.util.EnumFacing) MjCapabilityHelper(buildcraft.api.mj.MjCapabilityHelper) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) ClientVolumeBoxes(buildcraft.core.marker.volume.ClientVolumeBoxes) IBlockState(net.minecraft.block.state.IBlockState) IControllable(buildcraft.api.tiles.IControllable) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Lock(buildcraft.core.marker.volume.Lock) TileEntity(net.minecraft.tileentity.TileEntity) SnapshotBuilder(buildcraft.builders.snapshot.SnapshotBuilder) IItemTransactor(buildcraft.api.inventory.IItemTransactor) VolumeBox(buildcraft.core.marker.volume.VolumeBox) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) UUID(java.util.UUID)

Example 3 with MessageContext

use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project RebornCore by TechReborn.

the class PacketSlotSync method processData.

@Override
public void processData(PacketSlotSync message, MessageContext context) {
    if (!RebornCore.proxy.getClientWorld().isBlockLoaded(pos, false)) {
        return;
    }
    TileLegacyMachineBase machineBase = (TileLegacyMachineBase) RebornCore.proxy.getClientWorld().getTileEntity(pos);
    if (machineBase == null || machineBase.slotConfiguration == null || slotConfig == null || slotConfig.getSlotDetails() == null) {
        RebornCore.logHelper.error("Failed to sync slot data to " + pos);
    }
    Minecraft.getMinecraft().addScheduledTask(() -> slotConfig.getSlotDetails().forEach(slotConfigHolder -> machineBase.slotConfiguration.updateSlotDetails(slotConfigHolder)));
}
Also used : SlotConfiguration(reborncore.common.tile.SlotConfiguration) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) ExtendedPacketBuffer(reborncore.common.network.ExtendedPacketBuffer) Minecraft(net.minecraft.client.Minecraft) INetworkPacket(reborncore.common.network.INetworkPacket) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) RebornCore(reborncore.RebornCore) TileLegacyMachineBase(reborncore.common.tile.TileLegacyMachineBase) TileLegacyMachineBase(reborncore.common.tile.TileLegacyMachineBase)

Example 4 with MessageContext

use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project AgriCraft by AgriCraft.

the class MessageTileEntitySeedStorage method processMessage.

@Override
protected void processMessage(MessageContext ctx) {
    TileEntity te = FMLClientHandler.instance().getClient().world.getTileEntity(this.pos);
    if (te instanceof TileEntitySeedStorage) {
        TileEntitySeedStorage storage = (TileEntitySeedStorage) te;
        ItemStack stack = storage.getLockedSeed().map(s -> s.toStack()).orElse(null);
        if (stack != null) {
            stack.setCount(this.amount);
            NBTTagCompound tag = new NBTTagCompound();
            stats.writeToNBT(tag);
            stack.setTagCompound(tag);
            storage.setSlotContents(this.slotId, stack);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMessageReader(com.infinityraider.infinitylib.network.serialization.IMessageReader) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) MessageBase(com.infinityraider.infinitylib.network.MessageBase) SeedStorageSlot(com.infinityraider.agricraft.tiles.storage.SeedStorageSlot) IMessageSerializer(com.infinityraider.infinitylib.network.serialization.IMessageSerializer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IMessageWriter(com.infinityraider.infinitylib.network.serialization.IMessageWriter) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) Side(net.minecraftforge.fml.relauncher.Side) ByteBufUtil(com.infinityraider.infinitylib.network.serialization.ByteBufUtil) TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySeedStorage(com.infinityraider.agricraft.tiles.storage.TileEntitySeedStorage) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) TileEntitySeedStorage(com.infinityraider.agricraft.tiles.storage.TileEntitySeedStorage) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 5 with MessageContext

use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project SilentGems by SilentChaos512.

the class MessageKeyReturnHome method handleMessage.

@Override
public IMessage handleMessage(MessageContext ctx) {
    if (ctx.side != Side.SERVER)
        return null;
    Predicate<ItemStack> predicate = s -> s.getItem() == ModItems.returnHomeCharm;
    EntityPlayer player = ctx.getServerHandler().player;
    ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
    stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
    if (stacks.isEmpty())
        return null;
    ModItems.returnHomeCharm.tryTeleportPlayer(stacks.get(0), player);
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) ModItems(net.silentchaos512.gems.init.ModItems) Predicate(com.google.common.base.Predicate) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) Message(net.silentchaos512.gems.network.Message) PlayerHelper(net.silentchaos512.lib.util.PlayerHelper) BaublesCompat(net.silentchaos512.gems.compat.BaublesCompat) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MessageContext (net.minecraftforge.fml.common.network.simpleimpl.MessageContext)7 Side (net.minecraftforge.fml.relauncher.Side)6 ItemStack (net.minecraft.item.ItemStack)5 EnumPipePart (buildcraft.api.core.EnumPipePart)2 IdAllocator (buildcraft.lib.misc.data.IdAllocator)2 MessageManager (buildcraft.lib.net.MessageManager)2 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)2 IOException (java.io.IOException)2 List (java.util.List)2 BlockPos (net.minecraft.util.math.BlockPos)2 IMessage (net.minecraftforge.fml.common.network.simpleimpl.IMessage)2 IAreaProvider (buildcraft.api.core.IAreaProvider)1 IBox (buildcraft.api.core.IBox)1 NbtSquishConstants (buildcraft.api.data.NbtSquishConstants)1 IFillerPattern (buildcraft.api.filler.IFillerPattern)1 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 MjAPI (buildcraft.api.mj.MjAPI)1 MjBattery (buildcraft.api.mj.MjBattery)1 MjCapabilityHelper (buildcraft.api.mj.MjCapabilityHelper)1 IStatementParameter (buildcraft.api.statements.IStatementParameter)1