Search in sources :

Example 1 with SchematicWorld

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;
}
Also used : SchematicWorld(com.simibubi.create.content.schematics.SchematicWorld) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) BlockPos(net.minecraft.core.BlockPos) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings)

Example 2 with SchematicWorld

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);
}
Also used : ContraptionMatrices(com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices) IItemHandler(net.minecraftforge.items.IItemHandler) Arrays(java.util.Arrays) Tag(net.minecraft.nbt.Tag) ForgeEventFactory(net.minecraftforge.event.ForgeEventFactory) Backend(com.jozufozu.flywheel.backend.Backend) Direction(net.minecraft.core.Direction) MovementBehaviour(com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) BlockState(net.minecraft.world.level.block.state.BlockState) VirtualRenderWorld(com.jozufozu.flywheel.core.virtual.VirtualRenderWorld) Inventory(net.minecraft.world.entity.player.Inventory) AllItems(com.simibubi.create.AllItems) ServerLevel(net.minecraft.server.level.ServerLevel) Mode(com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode) Pair(org.apache.commons.lang3.tuple.Pair) AllBlocks(com.simibubi.create.AllBlocks) ItemRequirement(com.simibubi.create.content.schematics.ItemRequirement) Nullable(javax.annotation.Nullable) AbstractContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity) NBTProcessors(com.simibubi.create.foundation.utility.NBTProcessors) SchematicInstances(com.simibubi.create.content.schematics.filtering.SchematicInstances) ItemHelper(com.simibubi.create.foundation.item.ItemHelper) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BlockHelper(com.simibubi.create.foundation.utility.BlockHelper) List(java.util.List) MaterialManager(com.jozufozu.flywheel.api.MaterialManager) CompoundTag(net.minecraft.nbt.CompoundTag) SchematicWorld(com.simibubi.create.content.schematics.SchematicWorld) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) ExtractionCountMode(com.simibubi.create.foundation.item.ItemHelper.ExtractionCountMode) NBTHelper(com.simibubi.create.foundation.utility.NBTHelper) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) AllBlockTags(com.simibubi.create.AllTags.AllBlockTags) Level(net.minecraft.world.level.Level) MultiBufferSource(net.minecraft.client.renderer.MultiBufferSource) ListTag(net.minecraft.nbt.ListTag) ActorInstance(com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance) IItemHandler(net.minecraftforge.items.IItemHandler) ItemRequirement(com.simibubi.create.content.schematics.ItemRequirement) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) BlockState(net.minecraft.world.level.block.state.BlockState) SchematicWorld(com.simibubi.create.content.schematics.SchematicWorld) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with SchematicWorld

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);
}
Also used : Vec3i(net.minecraft.core.Vec3i) SchematicWorld(com.simibubi.create.content.schematics.SchematicWorld) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) Level(net.minecraft.world.level.Level) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) BlockPos(net.minecraft.core.BlockPos)

Example 4 with SchematicWorld

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);
}
Also used : PoseStack(com.mojang.blaze3d.vertex.PoseStack) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) ShadeSeparatingVertexConsumer(com.jozufozu.flywheel.core.model.ShadeSeparatingVertexConsumer) BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) SchematicWorld(com.simibubi.create.content.schematics.SchematicWorld) BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) BlockPos(net.minecraft.core.BlockPos) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 5 with SchematicWorld

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;
}
Also used : SchematicWorld(com.simibubi.create.content.schematics.SchematicWorld) Nullable(javax.annotation.Nullable)

Aggregations

SchematicWorld (com.simibubi.create.content.schematics.SchematicWorld)5 BlockPos (net.minecraft.core.BlockPos)4 Nullable (javax.annotation.Nullable)2 Level (net.minecraft.world.level.Level)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 MaterialManager (com.jozufozu.flywheel.api.MaterialManager)1 Backend (com.jozufozu.flywheel.backend.Backend)1 ShadeSeparatedBufferBuilder (com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder)1 ShadeSeparatingVertexConsumer (com.jozufozu.flywheel.core.model.ShadeSeparatingVertexConsumer)1 VirtualRenderWorld (com.jozufozu.flywheel.core.virtual.VirtualRenderWorld)1 BufferBuilder (com.mojang.blaze3d.vertex.BufferBuilder)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 AllBlocks (com.simibubi.create.AllBlocks)1 AllItems (com.simibubi.create.AllItems)1 AllBlockTags (com.simibubi.create.AllTags.AllBlockTags)1 Mode (com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode)1 AbstractContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity)1 MovementBehaviour (com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour)1 MovementContext (com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)1