use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.
the class PartBuilderWidget method initScene.
@OnlyIn(Dist.CLIENT)
private void initScene() {
TrackedDummyWorld world = new TrackedDummyWorld();
world.addBlock(BlockPos.ZERO, BlockInfo.fromBlockState(MbdComponents.DummyComponentBlock.defaultBlockState()));
tileEntity = (DummyComponentTileEntity) world.getBlockEntity(BlockPos.ZERO);
this.addWidget(new ImageWidget(30, 59, 138, 138, new GuiTextureGroup(new ColorBorderTexture(3, -1), new ColorRectTexture(0xaf444444))));
this.addWidget(new SceneWidget(30, 59, 138, 138, world).setRenderedCore(Collections.singleton(BlockPos.ZERO), null).setRenderSelect(false).setRenderFacing(false));
this.addWidget(new ImageWidget(30, 65, 138, 15, textTexture = new TextTexture("", 0xff00ff00).setDropShadow(true).setWidth(138).setType(TextTexture.TextType.ROLL)));
}
use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.
the class TemplateBuilderWidget method onSelected.
@OnlyIn(Dist.CLIENT)
public void onSelected(ItemStack itemStack, int slot) {
if (this.selected != itemStack) {
this.selected = itemStack;
this.selectedSlot = slot;
if (selected != null && isRemote()) {
this.pos = null;
this.facing = null;
templateButton.setVisible(true);
if (ItemBlueprint.isRaw(itemStack)) {
BlockPos[] poses = ItemBlueprint.getPos(itemStack);
World world = table.getLevel();
sceneWidget.createScene(world);
if (poses != null && world.hasChunksAt(poses[0], poses[1])) {
Set<BlockPos> rendered = new HashSet<>();
for (int x = poses[0].getX(); x <= poses[1].getX(); x++) {
for (int y = poses[0].getY(); y <= poses[1].getY(); y++) {
for (int z = poses[0].getZ(); z <= poses[1].getZ(); z++) {
if (!world.isEmptyBlock(new BlockPos(x, y, z))) {
rendered.add(new BlockPos(x, y, z));
}
}
}
}
sceneWidget.setRenderedCore(rendered, null);
}
} else if (itemStack.getTagElement("pattern") != null) {
String json = itemStack.getTagElement("pattern").getString("json");
JsonBlockPattern pattern = Multiblocked.GSON.fromJson(json, JsonBlockPattern.class);
int[] centerOffset = pattern.getCenterOffset();
String[][] patternString = pattern.pattern;
Set<BlockPos> rendered = new HashSet<>();
TrackedDummyWorld world = new TrackedDummyWorld();
sceneWidget.createScene(world);
int offset = Math.max(patternString.length, Math.max(patternString[0].length, patternString[0][0].length()));
for (int i = 0; i < patternString.length; i++) {
for (int j = 0; j < patternString[0].length; j++) {
for (int k = 0; k < patternString[0][0].length(); k++) {
char symbol = patternString[i][j].charAt(k);
BlockPos pos = pattern.getActualPosOffset(k - centerOffset[2], j - centerOffset[1], i - centerOffset[0], Direction.NORTH).offset(offset, offset, offset);
world.addBlock(pos, BlockInfo.fromBlockState(MbdComponents.DummyComponentBlock.defaultBlockState()));
DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getBlockEntity(pos);
ComponentDefinition definition = null;
assert tileEntity != null;
if (pattern.symbolMap.containsKey(symbol)) {
Set<BlockInfo> candidates = new HashSet<>();
for (String s : pattern.symbolMap.get(symbol)) {
SimplePredicate predicate = pattern.predicates.get(s);
if (predicate instanceof PredicateComponent && ((PredicateComponent) predicate).definition != null) {
definition = ((PredicateComponent) predicate).definition;
break;
} else if (predicate != null && predicate.candidates != null) {
candidates.addAll(Arrays.asList(predicate.candidates.get()));
}
}
definition = getComponentDefinition(definition, candidates);
}
if (definition != null) {
tileEntity.setDefinition(definition);
}
tileEntity.isFormed = false;
tileEntity.setLevelAndPosition(world, pos);
rendered.add(pos);
}
}
}
sceneWidget.setRenderedCore(rendered, null);
}
}
}
}
use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.
the class FEMultiblockCapability method getCandidates.
@Override
public BlockInfo[] getCandidates() {
List<BlockInfo> list = new ArrayList<>();
TrackedDummyWorld dummyWorld = new TrackedDummyWorld();
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
if (block.getRegistryName() != null) {
String path = block.getRegistryName().getPath();
if (path.contains("energy") || path.contains("rf")) {
try {
if (block.hasTileEntity(block.defaultBlockState())) {
TileEntity tileEntity = block.createTileEntity(block.defaultBlockState(), dummyWorld);
if (tileEntity != null && isBlockHasCapability(IO.BOTH, tileEntity)) {
list.add(new BlockInfo(block.defaultBlockState(), tileEntity));
}
}
} catch (Throwable ignored) {
}
}
}
}
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "energy_input"))));
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "energy_output"))));
return list.toArray(new BlockInfo[0]);
}
use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.
the class FluidMultiblockCapability method getCandidates.
@Override
public BlockInfo[] getCandidates() {
List<BlockInfo> list = new ArrayList<>();
TrackedDummyWorld dummyWorld = new TrackedDummyWorld();
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
if (block.getRegistryName() != null) {
String path = block.getRegistryName().getPath();
if (path.contains("tank") || path.contains("fluid") || path.contains("liquid")) {
try {
if (block.hasTileEntity(block.defaultBlockState())) {
TileEntity tileEntity = block.createTileEntity(block.defaultBlockState(), dummyWorld);
if (tileEntity != null && isBlockHasCapability(IO.BOTH, tileEntity)) {
list.add(new BlockInfo(block.defaultBlockState(), tileEntity));
}
}
} catch (Throwable ignored) {
}
}
}
}
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "fluid_input"))));
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "fluid_output"))));
return list.toArray(new BlockInfo[0]);
}
use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.
the class MultiblockPreviewRenderer method renderControllerInList.
public static void renderControllerInList(ControllerTileEntity controllerBase, MultiblockShapeInfo shapeInfo, int layer) {
Direction frontFacing;
previewFacing = Direction.NORTH;
controllerPos = BlockPos.ZERO;
mte = null;
BlockInfo[][][] blocks = shapeInfo.getBlocks();
blockMap = new HashMap<>();
int maxY = 0;
for (int x = 0; x < blocks.length; x++) {
BlockInfo[][] aisle = blocks[x];
maxY = Math.max(maxY, aisle.length);
for (int y = 0; y < aisle.length; y++) {
BlockInfo[] column = aisle[y];
for (int z = 0; z < column.length; z++) {
blockMap.put(new BlockPos(x, y, z), column[z]);
ControllerTileEntity metaTE = column[z].getTileEntity() instanceof ControllerTileEntity ? (ControllerTileEntity) column[z].getTileEntity() : null;
if (metaTE != null) {
if (metaTE.getDefinition().location.equals(controllerBase.getDefinition().location)) {
controllerPos = new BlockPos(x, y, z);
mte = metaTE;
}
}
}
}
}
world = new TrackedDummyWorld();
world.addBlocks(blockMap);
int finalMaxY = layer % (maxY + 1);
world.setRenderFilter(pos -> pos.getY() + 1 == finalMaxY || finalMaxY == 0);
facing = controllerBase.getFrontFacing();
spin = Direction.NORTH;
frontFacing = facing.getStepY() == 0 ? facing : facing.getStepY() < 0 ? spin : spin.getOpposite();
rotatePreviewBy = Rotation.values()[(4 + frontFacing.get2DDataValue() - previewFacing.get2DDataValue()) % 4];
if (mte != null) {
mbpPos = controllerBase.getBlockPos();
}
}
Aggregations