Search in sources :

Example 1 with PacketSyncWorktable

use of com.teamwizardry.wizardry.common.network.PacketSyncWorktable in project Wizardry by TeamWizardry.

the class WorktableGui method syncToServer.

public void syncToServer() {
    Set<CommonWorktableModule> commonModules = new HashSet<>();
    for (TableModule head : getSpellHeads()) {
        TableModule lastModule = head;
        CommonWorktableModule lastCommonModule = new CommonWorktableModule(lastModule.hashCode(), lastModule.getModule(), lastModule.getPos(), null, new HashMap<>());
        commonModules.add(lastCommonModule);
        while (lastModule != null) {
            if (lastModule != head) {
                CommonWorktableModule commonModule = new CommonWorktableModule(lastModule.hashCode(), lastModule.getModule(), lastModule.getPos(), null, new HashMap<>());
                lastCommonModule.setLinksTo(commonModule);
                lastCommonModule = commonModule;
            }
            for (ModuleInstance module : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
                if (!(module instanceof ModuleInstanceModifier))
                    continue;
                if (!lastModule.hasData(Integer.class, module.getNBTKey()))
                    continue;
                int count = lastModule.getData(Integer.class, module.getNBTKey());
                lastCommonModule.addModifier((ModuleInstanceModifier) module, count);
            }
            lastModule = lastModule.getLinksTo();
        }
    }
    int dim = Minecraft.getMinecraft().world.provider.getDimension();
    PacketHandler.NETWORK.sendToServer(new PacketSyncWorktable(dim, pos, commonModules));
}
Also used : PacketSyncWorktable(com.teamwizardry.wizardry.common.network.PacketSyncWorktable) CommonWorktableModule(com.teamwizardry.wizardry.api.spell.CommonWorktableModule) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance) ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)

Aggregations

CommonWorktableModule (com.teamwizardry.wizardry.api.spell.CommonWorktableModule)1 ModuleInstance (com.teamwizardry.wizardry.api.spell.module.ModuleInstance)1 ModuleInstanceModifier (com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)1 PacketSyncWorktable (com.teamwizardry.wizardry.common.network.PacketSyncWorktable)1