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