Search in sources :

Example 6 with MultiblockState

use of com.lowdragmc.multiblocked.api.pattern.MultiblockState in project Multiblocked by Low-Drag-MC.

the class ControllerTileEntity method readState.

protected void readState(PacketBuffer buffer) {
    if (buffer.readBoolean()) {
        state = new MultiblockState(level, worldPosition);
        state.setError(null);
        int size = buffer.readVarInt();
        if (size > 0) {
            ImmutableList.Builder<BlockPos> listBuilder = new ImmutableList.Builder<>();
            for (int i = size; i > 0; i--) {
                listBuilder.add(BlockPos.of(buffer.readLong()));
            }
            MultiblockWorldSavedData.addDisableModel(state.controllerPos, listBuilder.build());
        }
    } else {
        if (state != null) {
            MultiblockWorldSavedData.removeDisableModel(state.controllerPos);
        }
        state = null;
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with MultiblockState

use of com.lowdragmc.multiblocked.api.pattern.MultiblockState in project Multiblocked by Low-Drag-MC.

the class MultiblockWorldSavedData method addMapping.

public void addMapping(MultiblockState state) {
    this.mapping.put(state.controllerPos, state);
    for (BlockPos blockPos : state.getCache()) {
        chunkPosMapping.computeIfAbsent(new ChunkPos(blockPos), c -> new HashSet<>()).add(state);
    }
    setDirty(true);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ServerWorld(net.minecraft.world.server.ServerWorld) Arrays(java.util.Arrays) ComponentTileEntity(com.lowdragmc.multiblocked.api.tile.ComponentTileEntity) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) HashMap(java.util.HashMap) Unpooled(io.netty.buffer.Unpooled) Dist(net.minecraftforge.api.distmarker.Dist) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ByteBuf(io.netty.buffer.ByteBuf) Minecraft(net.minecraft.client.Minecraft) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BlockState(net.minecraft.block.BlockState) WeakReference(java.lang.ref.WeakReference) ThreadFactory(java.util.concurrent.ThreadFactory) Nonnull(javax.annotation.Nonnull) DummyWorld(com.lowdragmc.lowdraglib.utils.DummyWorld) World(net.minecraft.world.World) Collection(java.util.Collection) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) ChunkPos(net.minecraft.util.math.ChunkPos) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) WorldSavedData(net.minecraft.world.storage.WorldSavedData) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) Collections(java.util.Collections) PacketBuffer(net.minecraft.network.PacketBuffer) ClientWorld(net.minecraft.client.world.ClientWorld) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) HashSet(java.util.HashSet)

Example 8 with MultiblockState

use of com.lowdragmc.multiblocked.api.pattern.MultiblockState in project Multiblocked by Low-Drag-MC.

the class PredicateAnyCapability method checkCapability.

private static boolean checkCapability(IO io, MultiblockCapability<?> capability, MultiblockState state) {
    if (io != null) {
        TileEntity tileEntity = state.getTileEntity();
        if (tileEntity != null && capability.isBlockHasCapability(io, tileEntity)) {
            Map<Long, EnumMap<IO, Set<MultiblockCapability<?>>>> capabilities = state.getMatchContext().getOrCreate("capabilities", Long2ObjectOpenHashMap::new);
            capabilities.computeIfAbsent(state.getPos().asLong(), l -> new EnumMap<>(IO.class)).computeIfAbsent(io, x -> new HashSet<>()).add(capability);
            return true;
        }
    }
    state.setError(new PatternStringError(LocalizationUtils.format("multiblocked.pattern.error.capability", LocalizationUtils.format(capability.getUnlocalizedName()), io == null ? "NULL" : io.name())));
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) JSONUtils(net.minecraft.util.JSONUtils) JsonObject(com.google.gson.JsonObject) LocalizationUtils(com.lowdragmc.lowdraglib.utils.LocalizationUtils) EnumMap(java.util.EnumMap) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) Set(java.util.Set) MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.block.Blocks) MbdCapabilities(com.lowdragmc.multiblocked.api.registry.MbdCapabilities) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SelectorWidget(com.lowdragmc.lowdraglib.gui.widget.SelectorWidget) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) List(java.util.List) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) Gson(com.google.gson.Gson) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Map(java.util.Map) IO(com.lowdragmc.multiblocked.api.capability.IO) TileEntity(net.minecraft.tileentity.TileEntity) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) PatternStringError(com.lowdragmc.multiblocked.api.pattern.error.PatternStringError) MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) IO(com.lowdragmc.multiblocked.api.capability.IO) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PatternStringError(com.lowdragmc.multiblocked.api.pattern.error.PatternStringError) EnumMap(java.util.EnumMap) HashSet(java.util.HashSet)

Aggregations

MultiblockState (com.lowdragmc.multiblocked.api.pattern.MultiblockState)8 BlockPos (net.minecraft.util.math.BlockPos)4 BlockPattern (com.lowdragmc.multiblocked.api.pattern.BlockPattern)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 DummyWorld (com.lowdragmc.lowdraglib.utils.DummyWorld)2 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)2 ComponentTileEntity (com.lowdragmc.multiblocked.api.tile.ComponentTileEntity)2 ByteBuf (io.netty.buffer.ByteBuf)2 Unpooled (io.netty.buffer.Unpooled)2 Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)2 WeakReference (java.lang.ref.WeakReference)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2