use of com.simibubi.create.content.schematics.SchematicWorld in project Create by Creators-of-Create.
the class SchematicInstances method loadWorld.
private static SchematicWorld loadWorld(Level wrapped, ItemStack schematic) {
if (schematic == null || !schematic.hasTag())
return null;
if (!schematic.getTag().getBoolean("Deployed"))
return null;
StructureTemplate activeTemplate = SchematicItem.loadSchematic(schematic);
if (activeTemplate.getSize().equals(Vec3i.ZERO))
return null;
BlockPos anchor = NbtUtils.readBlockPos(schematic.getTag().getCompound("Anchor"));
SchematicWorld world = new SchematicWorld(anchor, wrapped);
StructurePlaceSettings settings = SchematicItem.getSettings(schematic);
activeTemplate.placeInWorld(world, anchor, anchor, settings, wrapped.getRandom(), Block.UPDATE_CLIENTS);
return world;
}
use of com.simibubi.create.content.schematics.SchematicWorld in project Create by Creators-of-Create.
the class DeployerMovementBehaviour method activateAsSchematicPrinter.
protected void activateAsSchematicPrinter(MovementContext context, BlockPos pos, DeployerFakePlayer player, Level world, ItemStack filter) {
if (!filter.hasTag())
return;
if (!world.getBlockState(pos).getMaterial().isReplaceable())
return;
CompoundTag tag = filter.getTag();
if (!tag.getBoolean("Deployed"))
return;
SchematicWorld schematicWorld = SchematicInstances.get(world, filter);
if (schematicWorld == null)
return;
if (!schematicWorld.getBounds().isInside(pos.subtract(schematicWorld.anchor)))
return;
BlockState blockState = schematicWorld.getBlockState(pos);
ItemRequirement requirement = ItemRequirement.of(blockState, schematicWorld.getBlockEntity(pos));
if (requirement.isInvalid() || requirement.isEmpty())
return;
if (AllBlocks.BELT.has(blockState))
return;
List<ItemRequirement.StackRequirement> requiredItems = requirement.getRequiredItems();
ItemStack firstRequired = requiredItems.isEmpty() ? ItemStack.EMPTY : requiredItems.get(0).item;
if (!context.contraption.hasUniversalCreativeCrate) {
IItemHandler iItemHandler = context.contraption.inventory;
for (ItemRequirement.StackRequirement required : requiredItems) {
int amountFound = ItemHelper.extract(iItemHandler, s -> ItemRequirement.validate(required.item, s), ExtractionCountMode.UPTO, required.item.getCount(), true).getCount();
if (amountFound < required.item.getCount())
return;
}
for (ItemRequirement.StackRequirement required : requiredItems) ItemHelper.extract(iItemHandler, s -> ItemRequirement.validate(required.item, s), ExtractionCountMode.UPTO, required.item.getCount(), false);
}
CompoundTag data = null;
if (AllBlockTags.SAFE_NBT.matches(blockState)) {
BlockEntity tile = schematicWorld.getBlockEntity(pos);
if (tile != null) {
data = tile.saveWithFullMetadata();
data = NBTProcessors.process(tile, data, true);
}
}
BlockSnapshot blocksnapshot = BlockSnapshot.create(world.dimension(), world, pos);
BlockHelper.placeSchematicBlock(world, blockState, pos, firstRequired, data);
if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP))
blocksnapshot.restore(true, false);
}
use of com.simibubi.create.content.schematics.SchematicWorld in project Create by Creators-of-Create.
the class SchematicHandler method setupRenderer.
private void setupRenderer() {
StructureTemplate schematic = SchematicItem.loadSchematic(activeSchematicItem);
Vec3i size = schematic.getSize();
if (size.equals(Vec3i.ZERO))
return;
Level clientWorld = Minecraft.getInstance().level;
SchematicWorld w = new SchematicWorld(clientWorld);
SchematicWorld wMirroredFB = new SchematicWorld(clientWorld);
SchematicWorld wMirroredLR = new SchematicWorld(clientWorld);
StructurePlaceSettings placementSettings = new StructurePlaceSettings();
BlockPos pos;
pos = BlockPos.ZERO;
schematic.placeInWorld(w, pos, pos, placementSettings, w.getRandom(), Block.UPDATE_CLIENTS);
placementSettings.setMirror(Mirror.FRONT_BACK);
pos = BlockPos.ZERO.east(size.getX() - 1);
schematic.placeInWorld(wMirroredFB, pos, pos, placementSettings, wMirroredFB.getRandom(), Block.UPDATE_CLIENTS);
placementSettings.setMirror(Mirror.LEFT_RIGHT);
pos = BlockPos.ZERO.south(size.getZ() - 1);
schematic.placeInWorld(wMirroredLR, pos, pos, placementSettings, wMirroredFB.getRandom(), Block.UPDATE_CLIENTS);
renderers.get(0).display(w);
renderers.get(1).display(wMirroredFB);
renderers.get(2).display(wMirroredLR);
}
use of com.simibubi.create.content.schematics.SchematicWorld in project Create by Creators-of-Create.
the class SchematicRenderer method drawLayer.
protected SuperByteBuffer drawLayer(RenderType layer) {
BlockRenderDispatcher dispatcher = ModelUtil.VANILLA_RENDERER;
ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get();
PoseStack poseStack = objects.poseStack;
Random random = objects.random;
BlockPos.MutableBlockPos mutableBlockPos = objects.mutableBlockPos;
SchematicWorld renderWorld = schematic;
BoundingBox bounds = renderWorld.getBounds();
ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper;
ShadeSeparatedBufferBuilder builder = new ShadeSeparatedBufferBuilder(512);
BufferBuilder unshadedBuilder = objects.unshadedBuilder;
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
unshadedBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
shadeSeparatingWrapper.prepare(builder, unshadedBuilder);
ForgeHooksClient.setRenderType(layer);
ModelBlockRenderer.enableCaching();
for (BlockPos localPos : BlockPos.betweenClosed(bounds.minX(), bounds.minY(), bounds.minZ(), bounds.maxX(), bounds.maxY(), bounds.maxZ())) {
BlockPos pos = mutableBlockPos.setWithOffset(localPos, anchor);
BlockState state = renderWorld.getBlockState(pos);
poseStack.pushPose();
poseStack.translate(localPos.getX(), localPos.getY(), localPos.getZ());
if (state.getRenderShape() == RenderShape.MODEL && ItemBlockRenderTypes.canRenderInLayer(state, layer)) {
BlockEntity tileEntity = renderWorld.getBlockEntity(localPos);
dispatcher.renderBatched(state, pos, renderWorld, poseStack, shadeSeparatingWrapper, true, random, tileEntity != null ? tileEntity.getModelData() : EmptyModelData.INSTANCE);
}
poseStack.popPose();
}
ModelBlockRenderer.clearCache();
ForgeHooksClient.setRenderType(null);
shadeSeparatingWrapper.clear();
unshadedBuilder.end();
builder.appendUnshadedVertices(unshadedBuilder);
builder.end();
return new SuperByteBuffer(builder);
}
use of com.simibubi.create.content.schematics.SchematicWorld in project Create by Creators-of-Create.
the class SchematicInstances method get.
@Nullable
public static SchematicWorld get(Level world, ItemStack schematic) {
Cache<Integer, SchematicWorld> map = loadedSchematics.get(world);
int hash = getHash(schematic);
SchematicWorld ifPresent = map.getIfPresent(hash);
if (ifPresent != null)
return ifPresent;
SchematicWorld loadWorld = loadWorld(world, schematic);
if (loadWorld == null)
return null;
map.put(hash, loadWorld);
return loadWorld;
}
Aggregations