Search in sources :

Example 1 with MultiblockWorldSavedData

use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.

the class MultiblockState method onBlockStateChanged.

public void onBlockStateChanged(BlockPos pos) {
    if (pos.equals(controllerPos)) {
        if (this.getMatchContext().containsKey("renderMask")) {
            MultiblockedNetworking.sendToAll(new SPacketRemoveDisabledRendering(controllerPos));
        }
        if (lastController != null) {
            lastController.onStructureInvalid();
        }
        MultiblockWorldSavedData mbds = MultiblockWorldSavedData.getOrCreate(world);
        mbds.removeMapping(this);
        mbds.removeLoading(controllerPos);
    } else if (error != UNLOAD_ERROR) {
        ControllerTileEntity controller = getController();
        if (controller != null && !controller.checkPattern()) {
            controller.onStructureInvalid();
            MultiblockWorldSavedData.getOrCreate(world).removeMapping(this);
        }
    }
}
Also used : MultiblockWorldSavedData(com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData) SPacketRemoveDisabledRendering(com.lowdragmc.multiblocked.network.s2c.SPacketRemoveDisabledRendering) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Example 2 with MultiblockWorldSavedData

use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.

the class ControllerTileEntity method load.

@Override
public void load(@Nonnull BlockState blockState, @Nonnull CompoundNBT compound) {
    try {
        super.load(blockState, compound);
    } catch (Exception e) {
        if (definition == null) {
            MultiblockWorldSavedData mwsd = MultiblockWorldSavedData.getOrCreate(level);
            if (worldPosition != null && mwsd.mapping.containsKey(worldPosition)) {
                mwsd.removeMapping(mwsd.mapping.get(worldPosition));
            }
            return;
        }
    }
    if (compound.contains("ars")) {
        asyncRecipeSearching = compound.getBoolean("ars");
    }
    if (compound.contains("recipeLogic")) {
        recipeLogic = new RecipeLogic(this);
        recipeLogic.readFromNBT(compound.getCompound("recipeLogic"));
        status = recipeLogic.getStatus().name;
    }
    if (compound.contains("capabilities")) {
        ListNBT tagList = compound.getList("capabilities", Constants.NBT.TAG_COMPOUND);
        settings = new HashMap<>();
        for (INBT base : tagList) {
            CompoundNBT tag = (CompoundNBT) base;
            settings.computeIfAbsent(tag.getLong("pos"), l -> new HashMap<>()).put(MbdCapabilities.get(tag.getString("cap")), new Tuple<>(IO.VALUES[tag.getInt("io")], Direction.values()[tag.getInt("facing")]));
        }
    }
}
Also used : com.lowdragmc.multiblocked.api.kubejs.events(com.lowdragmc.multiblocked.api.kubejs.events) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) Direction(net.minecraft.util.Direction) TabContainer(com.lowdragmc.lowdraglib.gui.widget.TabContainer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Tables(com.google.common.collect.Tables) IAsyncThreadUpdate(com.lowdragmc.multiblocked.persistence.IAsyncThreadUpdate) ServerLifecycleHooks(net.minecraftforge.fml.server.ServerLifecycleHooks) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Map(java.util.Map) MultiblockWorldSavedData(com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData) IO(com.lowdragmc.multiblocked.api.capability.IO) ModularUI(com.lowdragmc.lowdraglib.gui.modular.ModularUI) BlockState(net.minecraft.block.BlockState) MultiblockPreviewRenderer(com.lowdragmc.multiblocked.client.renderer.MultiblockPreviewRenderer) LongSet(it.unimi.dsi.fastutil.longs.LongSet) ListNBT(net.minecraft.nbt.ListNBT) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EnumMap(java.util.EnumMap) IPartComponent(com.lowdragmc.multiblocked.api.tile.part.IPartComponent) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) LongSets(it.unimi.dsi.fastutil.longs.LongSets) Set(java.util.Set) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) IOPageWidget(com.lowdragmc.multiblocked.api.gui.controller.IOPageWidget) CapabilityProxy(com.lowdragmc.multiblocked.api.capability.proxy.CapabilityProxy) BlockPattern(com.lowdragmc.multiblocked.api.pattern.BlockPattern) ActionResultType(net.minecraft.util.ActionResultType) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ScriptType(dev.latvian.kubejs.script.ScriptType) HashMap(java.util.HashMap) MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) ITextComponent(net.minecraft.util.text.ITextComponent) RecipeLogic(com.lowdragmc.multiblocked.api.recipe.RecipeLogic) ItemStack(net.minecraft.item.ItemStack) NIL_UUID(net.minecraft.util.Util.NIL_UUID) ImmutableList(com.google.common.collect.ImmutableList) RecipePage(com.lowdragmc.multiblocked.api.gui.controller.RecipePage) Hand(net.minecraft.util.Hand) Nonnull(javax.annotation.Nonnull) IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer) INBT(net.minecraft.nbt.INBT) Nullable(javax.annotation.Nullable) World(net.minecraft.world.World) Tuple(net.minecraft.util.Tuple) ICapabilityProxyHolder(com.lowdragmc.multiblocked.api.capability.ICapabilityProxyHolder) BlockPos(net.minecraft.util.math.BlockPos) MbdCapabilities(com.lowdragmc.multiblocked.api.registry.MbdCapabilities) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) TileEntity(net.minecraft.tileentity.TileEntity) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) StructurePageWidget(com.lowdragmc.multiblocked.api.gui.controller.structure.StructurePageWidget) TileEntityUIFactory(com.lowdragmc.lowdraglib.gui.factory.TileEntityUIFactory) Table(com.google.common.collect.Table) PacketBuffer(net.minecraft.network.PacketBuffer) ListNBT(net.minecraft.nbt.ListNBT) RecipeLogic(com.lowdragmc.multiblocked.api.recipe.RecipeLogic) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) HashMap(java.util.HashMap) MultiblockWorldSavedData(com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData)

Example 3 with MultiblockWorldSavedData

use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.

the class ControllerTileTesterEntity method setLevelAndPosition.

@Override
public void setLevelAndPosition(@Nonnull World world, @Nonnull BlockPos pos) {
    MultiblockWorldSavedData mwsd = MultiblockWorldSavedData.getOrCreate(world);
    if (mwsd.mapping.containsKey(pos)) {
        mwsd.removeMapping(mwsd.mapping.get(pos));
    }
    super.setLevelAndPosition(world, pos);
}
Also used : MultiblockWorldSavedData(com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData)

Example 4 with MultiblockWorldSavedData

use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.

the class WorldMixin method afterUpdatingEntities.

@Inject(method = "tickBlockEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;pop()V", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD)
private void afterUpdatingEntities(CallbackInfo ci, IProfiler iprofiler) {
    iprofiler.popPush("multiblocked_update");
    if (!((World) (Object) this).isClientSide) {
        List<ComponentTileEntity<?>> isRemoved = null;
        MultiblockWorldSavedData mbds = MultiblockWorldSavedData.getOrCreate((World) (Object) this);
        for (ComponentTileEntity<?> loading : mbds.getLoadings()) {
            if (loading.isRemoved()) {
                if (isRemoved == null) {
                    isRemoved = new ArrayList<>();
                }
                isRemoved.add(loading);
            } else {
                loading.update();
            }
        }
        if (isRemoved != null) {
            for (ComponentTileEntity<?> inValid : isRemoved) {
                mbds.removeLoading(inValid.getBlockPos());
            }
        }
    }
}
Also used : ComponentTileEntity(com.lowdragmc.multiblocked.api.tile.ComponentTileEntity) MultiblockWorldSavedData(com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with MultiblockWorldSavedData

use of com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData in project Multiblocked by Low-Drag-MC.

the class ControllerTileTesterEntity method setDefinition.

public void setDefinition(ControllerDefinition definition) {
    if (level != null) {
        MultiblockWorldSavedData mwsd = MultiblockWorldSavedData.getOrCreate(level);
        state = null;
        if (worldPosition != null && mwsd.mapping.containsKey(worldPosition)) {
            mwsd.removeMapping(mwsd.mapping.get(worldPosition));
        }
        if (definition == null) {
            this.definition = DEFAULT_DEFINITION;
        } else if (definition != DEFAULT_DEFINITION) {
            this.definition = definition;
            if (isRemote()) {
                scheduleChunkForRenderUpdate();
            } else {
                notifyBlockUpdate();
                if (needAlwaysUpdate()) {
                    MultiblockWorldSavedData.getOrCreate(level).addLoading(this);
                }
            }
        }
        initTrait();
    }
}
Also used : MultiblockWorldSavedData(com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData)

Aggregations

MultiblockWorldSavedData (com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData)5 ImmutableList (com.google.common.collect.ImmutableList)1 Table (com.google.common.collect.Table)1 Tables (com.google.common.collect.Tables)1 TileEntityUIFactory (com.lowdragmc.lowdraglib.gui.factory.TileEntityUIFactory)1 ModularUI (com.lowdragmc.lowdraglib.gui.modular.ModularUI)1 TabContainer (com.lowdragmc.lowdraglib.gui.widget.TabContainer)1 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)1 ICapabilityProxyHolder (com.lowdragmc.multiblocked.api.capability.ICapabilityProxyHolder)1 IO (com.lowdragmc.multiblocked.api.capability.IO)1 MultiblockCapability (com.lowdragmc.multiblocked.api.capability.MultiblockCapability)1 CapabilityProxy (com.lowdragmc.multiblocked.api.capability.proxy.CapabilityProxy)1 ControllerDefinition (com.lowdragmc.multiblocked.api.definition.ControllerDefinition)1 IOPageWidget (com.lowdragmc.multiblocked.api.gui.controller.IOPageWidget)1 RecipePage (com.lowdragmc.multiblocked.api.gui.controller.RecipePage)1 StructurePageWidget (com.lowdragmc.multiblocked.api.gui.controller.structure.StructurePageWidget)1 com.lowdragmc.multiblocked.api.kubejs.events (com.lowdragmc.multiblocked.api.kubejs.events)1 BlockPattern (com.lowdragmc.multiblocked.api.pattern.BlockPattern)1 MultiblockState (com.lowdragmc.multiblocked.api.pattern.MultiblockState)1 RecipeLogic (com.lowdragmc.multiblocked.api.recipe.RecipeLogic)1