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));
}
}
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));
}
}
}
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;
}
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;
}
Aggregations