geforkt von Mirrors/Paper
#1327: Add methods to place structures with block/entity transformers
By: Jishuna <joshl5324@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
48a803d3ec
Commit
93df3d859c
@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.structure;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -9,6 +10,8 @@ import java.util.stream.Collectors;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.GeneratorAccessSeed;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.EnumBlockMirror;
|
||||
import net.minecraft.world.level.block.EnumBlockRotation;
|
||||
@ -25,12 +28,16 @@ import org.bukkit.craftbukkit.CraftRegionAccessor;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.util.CraftBlockVector;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftStructureTransformer;
|
||||
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
|
||||
import org.bukkit.craftbukkit.util.TransformerGeneratorAccess;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.structure.Palette;
|
||||
import org.bukkit.structure.Structure;
|
||||
import org.bukkit.util.BlockTransformer;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.EntityTransformer;
|
||||
|
||||
public class CraftStructure implements Structure {
|
||||
|
||||
@ -42,19 +49,31 @@ public class CraftStructure implements Structure {
|
||||
|
||||
@Override
|
||||
public void place(Location location, boolean includeEntities, StructureRotation structureRotation, Mirror mirror, int palette, float integrity, Random random) {
|
||||
place(location, includeEntities, structureRotation, mirror, palette, integrity, random, Collections.emptyList(), Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(Location location, boolean includeEntities, StructureRotation structureRotation, Mirror mirror, int palette, float integrity, Random random, Collection<BlockTransformer> blockTransformers, Collection<EntityTransformer> entityTransformers) {
|
||||
Preconditions.checkArgument(location != null, "Location cannot be null");
|
||||
location.checkFinite();
|
||||
World world = location.getWorld();
|
||||
Preconditions.checkArgument(world != null, "The World of Location cannot be null");
|
||||
|
||||
BlockVector blockVector = new BlockVector(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
place(world, blockVector, includeEntities, structureRotation, mirror, palette, integrity, random);
|
||||
place(world, blockVector, includeEntities, structureRotation, mirror, palette, integrity, random, blockTransformers, entityTransformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(RegionAccessor regionAccessor, BlockVector location, boolean includeEntities, StructureRotation structureRotation, Mirror mirror, int palette, float integrity, Random random) {
|
||||
place(regionAccessor, location, includeEntities, structureRotation, mirror, palette, integrity, random, Collections.emptyList(), Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(RegionAccessor regionAccessor, BlockVector location, boolean includeEntities, StructureRotation structureRotation, Mirror mirror, int palette, float integrity, Random random, Collection<BlockTransformer> blockTransformers, Collection<EntityTransformer> entityTransformers) {
|
||||
Preconditions.checkArgument(location != null, "Location cannot be null");
|
||||
Preconditions.checkArgument(regionAccessor != null, "RegionAccessor cannot be null");
|
||||
Preconditions.checkArgument(blockTransformers != null, "BlockTransformers cannot be null");
|
||||
Preconditions.checkArgument(entityTransformers != null, "EntityTransformers cannot be null");
|
||||
location.checkFinite();
|
||||
|
||||
Preconditions.checkArgument(integrity >= 0F && integrity <= 1F, "Integrity value (%S) must be between 0 and 1 inclusive", integrity);
|
||||
@ -69,7 +88,14 @@ public class CraftStructure implements Structure {
|
||||
definedstructureinfo.palette = palette;
|
||||
|
||||
BlockPosition blockPosition = CraftBlockVector.toBlockPosition(location);
|
||||
structure.placeInWorld(((CraftRegionAccessor) regionAccessor).getHandle(), blockPosition, blockPosition, definedstructureinfo, randomSource, 2);
|
||||
GeneratorAccessSeed handle = ((CraftRegionAccessor) regionAccessor).getHandle();
|
||||
|
||||
TransformerGeneratorAccess access = new TransformerGeneratorAccess();
|
||||
access.setHandle(handle);
|
||||
access.setStructureTransformer(new CraftStructureTransformer(handle, new ChunkCoordIntPair(blockPosition), blockTransformers, entityTransformers));
|
||||
|
||||
structure.placeInWorld(access, blockPosition, blockPosition, definedstructureinfo, randomSource, 2);
|
||||
access.getStructureTransformer().discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
@ -70,6 +71,12 @@ public class CraftStructureTransformer {
|
||||
this.limitedRegion = new CraftLimitedRegion(generatoraccessseed, chunkcoordintpair);
|
||||
}
|
||||
|
||||
public CraftStructureTransformer(GeneratorAccessSeed generatoraccessseed, ChunkCoordIntPair chunkcoordintpair, Collection<BlockTransformer> blockTransformers, Collection<EntityTransformer> entityTransformers) {
|
||||
this.blockTransformers = blockTransformers.toArray(BlockTransformer[]::new);
|
||||
this.entityTransformers = entityTransformers.toArray(EntityTransformer[]::new);
|
||||
this.limitedRegion = new CraftLimitedRegion(generatoraccessseed, chunkcoordintpair);
|
||||
}
|
||||
|
||||
public boolean transformEntity(Entity entity) {
|
||||
EntityTransformer[] transformers = entityTransformers;
|
||||
if (transformers == null || transformers.length == 0) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren