Schematic entity placing
Changes to be committed: modified: src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java modified: src/main/java/org/dimdev/dimdoors/pockets/TemplateUtils.java modified: src/main/java/org/dimdev/dimdoors/util/schematic/v2/RelativeBlockSample.java modified: src/main/java/org/dimdev/dimdoors/world/feature/gateway/schematic/SchematicV2Gateway.java
This commit is contained in:
parent
b51e6a948e
commit
642924b541
4 changed files with 40 additions and 7 deletions
|
@ -27,6 +27,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
|
||||
|
@ -238,4 +239,8 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
|
|||
public RiftData getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
|
||||
public class TemplateUtils {
|
||||
static void setupEntityPlaceholders(List<CompoundTag> entities, CompoundTag entityTag) {
|
||||
|
@ -117,7 +118,7 @@ public class TemplateUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void replacePlaceholders(Schematic schematic) {
|
||||
public static void replacePlaceholders(Schematic schematic, StructureWorldAccess world) {
|
||||
// Replace placeholders (some schematics will contain them)
|
||||
List<CompoundTag> blockEntities = new ArrayList<>();
|
||||
for (CompoundTag blockEntityTag : schematic.getBlockEntities()) {
|
||||
|
@ -128,6 +129,7 @@ public class TemplateUtils {
|
|||
|
||||
CompoundTag newTag = new CompoundTag();
|
||||
EntranceRiftBlockEntity rift = Objects.requireNonNull(ModBlockEntityTypes.ENTRANCE_RIFT.instantiate());
|
||||
rift.setWorld(world.toServerWorld());
|
||||
switch (blockEntityTag.getString("placeholder")) {
|
||||
case "deeper_depth_door":
|
||||
rift.setPos(new BlockPos(x, y, z));
|
||||
|
@ -169,10 +171,10 @@ public class TemplateUtils {
|
|||
}
|
||||
schematic.setBlockEntities(blockEntities);
|
||||
|
||||
// List<CompoundTag> entities = new ArrayList<>();
|
||||
// for (CompoundTag entityTag : schematic.getEntities()) {
|
||||
// TemplateUtils.setupEntityPlaceholders(entities, entityTag);
|
||||
// }
|
||||
// schematic.setEntities(entities);
|
||||
List<CompoundTag> entities = new ArrayList<>();
|
||||
for (CompoundTag entityTag : schematic.getEntities()) {
|
||||
TemplateUtils.setupEntityPlaceholders(entities, entityTag);
|
||||
}
|
||||
schematic.setEntities(entities);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package org.dimdev.dimdoors.util.schematic.v2;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import io.github.boogiemonster1o1.libcbe.api.ConditionalBlockEntityProvider;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
@ -16,20 +18,27 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.IntArrayTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.ModifiableWorld;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
|
||||
import net.fabricmc.fabric.api.util.NbtType;
|
||||
|
||||
public class RelativeBlockSample implements BlockView, ModifiableWorld {
|
||||
public final Schematic schematic;
|
||||
private final int[][][] blockData;
|
||||
private final BiMap<BlockState, Integer> blockPalette;
|
||||
private final Map<BlockPos, BlockState> blockContainer;
|
||||
private final Map<BlockPos, CompoundTag> blockEntityContainer;
|
||||
private final BiMap<CompoundTag, Vec3d> entityContainer;
|
||||
private StructureWorldAccess world;
|
||||
|
||||
public RelativeBlockSample(Schematic schematic) {
|
||||
|
@ -67,6 +76,12 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
|
|||
BlockPos position = new BlockPos(arr[0], arr[1], arr[2]);
|
||||
this.blockEntityContainer.put(position, blockEntityTag);
|
||||
}
|
||||
|
||||
this.entityContainer = HashBiMap.create();
|
||||
for (CompoundTag entityTag : schematic.getEntities()) {
|
||||
ListTag doubles = entityTag.getList("Pos", NbtType.DOUBLE);
|
||||
this.entityContainer.put(entityTag, new Vec3d(doubles.getDouble(0), doubles.getDouble(1), doubles.getDouble(2)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,6 +124,17 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
|
|||
this.world.toServerWorld().setBlockEntity(blockEntity.getPos(), blockEntity);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<CompoundTag, Vec3d> entry : this.entityContainer.entrySet()) {
|
||||
CompoundTag tag = entry.getKey();
|
||||
ListTag doubles = tag.getList("Pos", NbtType.DOUBLE);
|
||||
Vec3d vec = entry.getValue().add(origin.getX(), origin.getY(), origin.getZ());
|
||||
doubles.set(0, NbtOps.INSTANCE.createDouble(vec.x));
|
||||
doubles.set(1, NbtOps.INSTANCE.createDouble(vec.y));
|
||||
doubles.set(2, NbtOps.INSTANCE.createDouble(vec.z));
|
||||
tag.put("Pos", doubles);
|
||||
Entity entity = EntityType.getEntityFromTag(tag, this.world.toServerWorld()).orElseThrow(NoSuchElementException::new);
|
||||
this.world.spawnEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public int[][][] getBlockData() {
|
||||
|
|
|
@ -46,7 +46,7 @@ public abstract class SchematicV2Gateway implements Gateway {
|
|||
|
||||
public final void generate(StructureWorldAccess world, BlockPos pos) {
|
||||
if (!this.replaced) {
|
||||
TemplateUtils.replacePlaceholders(this.schematic);
|
||||
TemplateUtils.replacePlaceholders(this.schematic, world);
|
||||
this.replaced = true;
|
||||
}
|
||||
SchematicPlacer.place(this.schematic, world, pos);
|
||||
|
|
Loading…
Reference in a new issue