Search in sources :

Example 1 with ISyncableData

use of mekanism.common.inventory.container.sync.ISyncableData in project Mekanism by mekanism.

the class VirtualCraftingOutputSlot method addTrackers.

@Override
public void addTrackers(PlayerEntity player, Consumer<ISyncableData> tracker) {
    if (player.level.isClientSide || !(player instanceof ServerPlayerEntity)) {
        // If we are on the client or not a server player entity for some reason return our cached value
        tracker.accept(SyncableBoolean.create(() -> canCraft, value -> canCraft = value));
    } else {
        // Otherwise if we are on the server validate if the player can craft or not
        // Note: We handle syncing the canCraft concept for our slots by just checking if the "owning" player is able to perform
        // the craft. We can get away with doing this as for the most part even server side containers are on a per player basis
        // so there is no harm in hiding/showing the output in the rare cases that another mod may let you hook into viewing an
        // existing container and interact with it.
        // TODO: Eventually if this does turn out to be an issue, it can probably be solved/worked around by using some per player
        // aware syncable boolean. In theory it shouldn't be that hard to create, as sync packet wise we could just have it take
        // two lists:
        // 1. The current one
        // 2. The player specific one
        // and then when encoding it just add the sizes together and pretend they are all part of the first list for purposes of
        // what the client is aware of as the client shouldn't care about them
        ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
        tracker.accept(SyncableBoolean.create(() -> craftingWindow.canViewRecipe(serverPlayer), value -> canCraft = value));
    }
}
Also used : PlayerEntity(net.minecraft.entity.player.PlayerEntity) AutomationType(mekanism.api.inventory.AutomationType) SyncableBoolean(mekanism.common.inventory.container.sync.SyncableBoolean) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) QIOCraftingWindow(mekanism.common.content.qio.QIOCraftingWindow) Consumer(java.util.function.Consumer) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) IInventorySlot(mekanism.api.inventory.IInventorySlot) Nonnull(javax.annotation.Nonnull) Action(mekanism.api.Action) Nullable(javax.annotation.Nullable) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 2 with ISyncableData

use of mekanism.common.inventory.container.sync.ISyncableData in project Mekanism by mekanism.

the class MekanismContainer method broadcastChanges.

@Override
public void broadcastChanges() {
    // and also batch various sync packets
    if (!containerListeners.isEmpty()) {
        // Only check tracked data for changes if we actually have any listeners
        List<PropertyData> dirtyData = new ArrayList<>();
        for (short i = 0; i < trackedData.size(); i++) {
            ISyncableData data = trackedData.get(i);
            DirtyType dirtyType = data.isDirty();
            if (dirtyType != DirtyType.CLEAN) {
                dirtyData.add(data.getPropertyData(i, dirtyType));
            }
        }
        if (!dirtyData.isEmpty()) {
            sendChange(new PacketUpdateContainer((short) containerId, dirtyData));
        }
    }
}
Also used : PropertyData(mekanism.common.network.to_client.container.property.PropertyData) ArrayList(java.util.ArrayList) PacketUpdateContainer(mekanism.common.network.to_client.container.PacketUpdateContainer) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) DirtyType(mekanism.common.inventory.container.sync.ISyncableData.DirtyType)

Example 3 with ISyncableData

use of mekanism.common.inventory.container.sync.ISyncableData in project Mekanism by mekanism.

the class TileComponentUpgrade method getSpecificSyncableData.

@Override
public List<ISyncableData> getSpecificSyncableData() {
    List<ISyncableData> list = new ArrayList<>();
    list.add(SyncableInt.create(() -> upgradeTicks, value -> upgradeTicks = value));
    // so we just do it based on their ordinal
    for (Upgrade upgrade : EnumUtils.UPGRADES) {
        if (supports(upgrade)) {
            list.add(SyncableInt.create(() -> upgrades.getOrDefault(upgrade, 0), value -> {
                if (value == 0) {
                    upgrades.remove(upgrade);
                } else if (value > 0) {
                    upgrades.put(upgrade, value);
                }
            }));
        }
    }
    return list;
}
Also used : UpgradeInventorySlot(mekanism.common.inventory.slot.UpgradeInventorySlot) Upgrade(mekanism.api.Upgrade) Arrays(java.util.Arrays) SyncableInt(mekanism.common.inventory.container.sync.SyncableInt) AutomationType(mekanism.api.inventory.AutomationType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ArrayList(java.util.ArrayList) ISpecificContainerTracker(mekanism.common.inventory.container.MekanismContainer.ISpecificContainerTracker) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) EnumSet(java.util.EnumSet) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) EnumUtils(mekanism.common.util.EnumUtils) EnumMap(java.util.EnumMap) NBTUtils(mekanism.common.util.NBTUtils) SyntheticComputerMethod(mekanism.common.integration.computer.annotation.SyntheticComputerMethod) DataHandlerUtils(mekanism.api.DataHandlerUtils) Set(java.util.Set) MekanismUtils(mekanism.common.util.MekanismUtils) List(java.util.List) IUpgradeItem(mekanism.common.item.interfaces.IUpgradeItem) NBT(net.minecraftforge.common.util.Constants.NBT) IInventorySlot(mekanism.api.inventory.IInventorySlot) NBTConstants(mekanism.api.NBTConstants) Action(mekanism.api.Action) UpgradeUtils(mekanism.common.util.UpgradeUtils) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) ArrayList(java.util.ArrayList) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) Upgrade(mekanism.api.Upgrade)

Example 4 with ISyncableData

use of mekanism.common.inventory.container.sync.ISyncableData in project Mekanism by mekanism.

the class TileComponentConfig method getSpecificSyncableData.

@Override
public List<ISyncableData> getSpecificSyncableData() {
    List<ISyncableData> list = new ArrayList<>();
    List<TransmissionType> transmissions = getTransmissions();
    for (TransmissionType transmission : transmissions) {
        ConfigInfo info = configInfo.get(transmission);
        list.add(SyncableBoolean.create(info::isEjecting, info::setEjecting));
    }
    return list;
}
Also used : TransmissionType(mekanism.common.lib.transmitter.TransmissionType) ArrayList(java.util.ArrayList) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo)

Aggregations

ISyncableData (mekanism.common.inventory.container.sync.ISyncableData)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Action (mekanism.api.Action)2 AutomationType (mekanism.api.inventory.AutomationType)2 IInventorySlot (mekanism.api.inventory.IInventorySlot)2 ItemStack (net.minecraft.item.ItemStack)2 Arrays (java.util.Arrays)1 EnumMap (java.util.EnumMap)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 DataHandlerUtils (mekanism.api.DataHandlerUtils)1 NBTConstants (mekanism.api.NBTConstants)1 Upgrade (mekanism.api.Upgrade)1 QIOCraftingWindow (mekanism.common.content.qio.QIOCraftingWindow)1 ComputerMethod (mekanism.common.integration.computer.annotation.ComputerMethod)1