Search in sources :

Example 1 with BlockPattern

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

the class PatternWidget method loadControllerFormed.

private void loadControllerFormed(Collection<BlockPos> poses, ControllerTileEntity controllerBase) {
    controllerBase.state = new MultiblockState(world, controllerBase.getBlockPos());
    BlockPattern pattern = controllerBase.getPattern();
    if (pattern != null && pattern.checkPatternAt(controllerBase.state, true)) {
        controllerBase.onStructureFormed();
    }
    if (controllerBase.isFormed()) {
        LongSet set = controllerBase.state.getMatchContext().getOrDefault("renderMask", LongSets.EMPTY_SET);
        Set<BlockPos> modelDisabled = set.stream().map(BlockPos::of).collect(Collectors.toSet());
        if (!modelDisabled.isEmpty()) {
            sceneWidget.setRenderedCore(poses.stream().filter(pos -> !modelDisabled.contains(pos)).collect(Collectors.toList()), null);
        } else {
            sceneWidget.setRenderedCore(poses, null);
        }
    } else {
        Multiblocked.LOGGER.warn("Pattern formed checking failed: {}", controllerBase.getDefinition().location);
    }
}
Also used : BlockPattern(com.lowdragmc.multiblocked.api.pattern.BlockPattern) LongSet(it.unimi.dsi.fastutil.longs.LongSet) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with BlockPattern

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

the class ItemMultiblockBuilder method onItemUseFirst.

@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
    PlayerEntity player = context.getPlayer();
    if (player != null) {
        if (!player.level.isClientSide) {
            TileEntity tileEntity = player.level.getBlockEntity(context.getClickedPos());
            ItemStack hold = player.getItemInHand(context.getHand());
            if (isItemMultiblockBuilder(hold) && tileEntity instanceof ControllerTileEntity) {
                if (isRaw(hold)) {
                    BlockPattern pattern = ((ControllerTileEntity) tileEntity).getPattern();
                    if (pattern != null) {
                        pattern.autoBuild(player, new MultiblockState(player.level, context.getClickedPos()));
                    }
                    return ActionResultType.SUCCESS;
                } else {
                    String json = hold.getOrCreateTagElement("pattern").getString("json");
                    String controller = hold.getOrCreateTagElement("pattern").getString("controller");
                    if (!json.isEmpty() && !controller.isEmpty()) {
                        if (controller.equals(((ControllerTileEntity) tileEntity).getDefinition().location.toString())) {
                            JsonBlockPattern jsonBlockPattern = Multiblocked.GSON.fromJson(json, JsonBlockPattern.class);
                            jsonBlockPattern.build().autoBuild(player, new MultiblockState(player.level, context.getClickedPos()));
                            return ActionResultType.SUCCESS;
                        }
                    }
                }
            }
        }
    }
    return ActionResultType.PASS;
}
Also used : ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) BlockPattern(com.lowdragmc.multiblocked.api.pattern.BlockPattern) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Example 3 with BlockPattern

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

the class ControllerTileEntity method asyncThreadLogic.

@Override
public void asyncThreadLogic(long periodID) {
    if (!isFormed() && getDefinition().catalyst == null && (getOffset() + periodID) % 4 == 0) {
        BlockPattern pattern = getPattern();
        if (pattern != null && pattern.checkPatternAt(new MultiblockState(level, worldPosition), false)) {
            ServerLifecycleHooks.getCurrentServer().execute(() -> {
                if (state == null)
                    state = new MultiblockState(level, worldPosition);
                if (checkPattern()) {
                    // formed
                    MultiblockWorldSavedData.getOrCreate(level).addMapping(state);
                    onStructureFormed();
                }
            });
        }
    }
    try {
        if (hasProxies()) {
            // should i add locks for proxies?
            for (Long2ObjectOpenHashMap<CapabilityProxy<?>> map : getCapabilitiesProxy().values()) {
                if (map != null) {
                    for (CapabilityProxy<?> proxy : map.values()) {
                        if (proxy != null) {
                            proxy.updateChangedState(periodID);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Multiblocked.LOGGER.error("something run while checking proxy changes");
    }
}
Also used : BlockPattern(com.lowdragmc.multiblocked.api.pattern.BlockPattern) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) CapabilityProxy(com.lowdragmc.multiblocked.api.capability.proxy.CapabilityProxy)

Aggregations

BlockPattern (com.lowdragmc.multiblocked.api.pattern.BlockPattern)3 MultiblockState (com.lowdragmc.multiblocked.api.pattern.MultiblockState)3 CapabilityProxy (com.lowdragmc.multiblocked.api.capability.proxy.CapabilityProxy)1 JsonBlockPattern (com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern)1 ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)1 LongSet (it.unimi.dsi.fastutil.longs.LongSet)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1