Update to 1.16.3

Changes to be committed:
	modified:   build.gradle
	modified:   gradle.properties
	modified:   src/main/java/org/dimdev/dimcore/schematic/v2/Schematic.java
	modified:   src/main/java/org/dimdev/dimcore/schematic/v2/SchematicBlockSample.java
	modified:   src/main/java/org/dimdev/dimcore/schematic/v2/SchematicPlacer.java
This commit is contained in:
SD 2020-09-11 14:23:30 +05:30
parent 3000286f87
commit 4d41a00933
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
5 changed files with 37 additions and 19 deletions

View file

@ -12,7 +12,8 @@ repositories {
maven { url = 'https://maven.fabricmc.net/' }
maven { url 'https://jitpack.io' }
mavenCentral()
maven { url = 'https://dl.bintray.com/boogiemonster1o1/cool-mods/' }
maven { url = 'https://dl.bintray.com/boogiemonster1o1/cool-mods/' }
maven { url = 'https://www.cursemaven.com' }
}
dependencies {
@ -32,7 +33,8 @@ dependencies {
include 'com.github.Waterpicker:OpenWorlds:c5a1ced'
compileOnly 'com.google.code.findbugs:jsr305:+'
modImplementation("io.github.boogiemonster1o1:libcbe:${libcbe_version}")
include("io.github.boogiemonster1o1:libcbe:${libcbe_version}") // Includes LibCBE as a Jar-in-Jar embedded dependency
include("io.github.boogiemonster1o1:libcbe:${libcbe_version}") // Includes LibCBE as a Jar-in-Jar embedded dependency
modImplementation("curse.maven:worldedit:3039223") // For saving schematics
}
version "4.0.0+alpha.3"

View file

@ -1,8 +1,8 @@
minecraft_version=1.16.2
yarn_mappings=1.16.2+build.9
loader_version=0.9.1+build.205
minecraft_version=1.16.3
yarn_mappings=1.16.3+build.1
loader_version=0.9.3+build.207
fabric_version=0.18.0+build.397-1.16
fabric_version=0.20.2+build.402-1.16
libcbe_version = 1.1.0

View file

@ -1,5 +1,6 @@
package org.dimdev.dimcore.schematic.v2;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
@ -10,6 +11,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.StructureWorldAccess;
@SuppressWarnings("CodeBlock2Expr")
public class Schematic {
@ -24,9 +26,9 @@ public class Schematic {
Vec3i.field_25123.fieldOf("Offset").forGetter(Schematic::getOffset),
Codec.INT.fieldOf("PaletteMax").forGetter(Schematic::getPaletteMax),
SchematicBlockPalette.CODEC.fieldOf("Palette").forGetter(Schematic::getBlockPalette),
Codec.INT_STREAM.fieldOf("BlockData").forGetter(Schematic::getBlockData),
Codec.list(CompoundTag.field_25128).fieldOf("BlockEntities").forGetter(Schematic::getBlockEntities),
Codec.list(CompoundTag.field_25128).fieldOf("Entities").forGetter(Schematic::getEntities)
Codec.BYTE_BUFFER.fieldOf("BlockData").forGetter(Schematic::getBlockData),
Codec.list(CompoundTag.CODEC).fieldOf("BlockEntities").forGetter(Schematic::getBlockEntities),
Codec.list(CompoundTag.CODEC).fieldOf("Entities").forGetter(Schematic::getEntities)
).apply(instance, Schematic::new);
});
@ -39,11 +41,11 @@ public class Schematic {
private final Vec3i offset;
private final int paletteMax;
private final Map<BlockState, Integer> blockPalette;
private final IntStream blockData;
private final ByteBuffer blockData;
private final List<CompoundTag> blockEntities;
private final List<CompoundTag> entities;
public Schematic(int version, int dataVersion, SchematicMetadata metadata, short width, short height, short length, Vec3i offset, int paletteMax, Map<BlockState, Integer> blockPalette, IntStream blockData, List<CompoundTag> blockEntities, List<CompoundTag> entities) {
public Schematic(int version, int dataVersion, SchematicMetadata metadata, short width, short height, short length, Vec3i offset, int paletteMax, Map<BlockState, Integer> blockPalette, ByteBuffer blockData, List<CompoundTag> blockEntities, List<CompoundTag> entities) {
this.version = version;
this.dataVersion = dataVersion;
this.metadata = metadata;
@ -94,7 +96,7 @@ public class Schematic {
return this.blockPalette;
}
public IntStream getBlockData() {
public ByteBuffer getBlockData() {
return this.blockData;
}
@ -105,4 +107,12 @@ public class Schematic {
public List<CompoundTag> getEntities() {
return this.entities;
}
public static SchematicBlockSample blockSample(Schematic schem) {
return new SchematicBlockSample(schem);
}
public static SchematicBlockSample blockSample(Schematic schem, StructureWorldAccess world) {
return blockSample(schem).withWorld(world);
}
}

View file

@ -22,11 +22,10 @@ public class SchematicBlockSample implements BlockView {
private final int[][][] blockData;
private final BiMap<BlockState, Integer> palette;
private final Map<BlockPos, BlockState> container;
private final StructureWorldAccess world;
private StructureWorldAccess world;
public SchematicBlockSample(Schematic schematic, StructureWorldAccess world) {
public SchematicBlockSample(Schematic schematic) {
this.schematic = schematic;
this.world = world;
this.blockData = SchematicPlacer.getBlockData(schematic, schematic.getWidth(), schematic.getHeight(), schematic.getLength());
this.palette = ImmutableBiMap.copyOf(schematic.getBlockPalette());
this.container = Maps.newHashMap();
@ -66,6 +65,9 @@ public class SchematicBlockSample implements BlockView {
}
public void place(BlockPos origin) {
if (this.world == null) {
throw new UnsupportedOperationException("Can not place in a null world!");
}
for (Map.Entry<BlockPos, BlockState> entry : this.container.entrySet()) {
BlockPos pos = entry.getKey();
BlockState state = entry.getValue();
@ -91,4 +93,9 @@ public class SchematicBlockSample implements BlockView {
public StructureWorldAccess getWorld() {
return this.world;
}
public SchematicBlockSample withWorld(StructureWorldAccess world) {
this.world = world;
return this;
}
}

View file

@ -42,16 +42,15 @@ public final class SchematicPlacer {
int originY = origin.getY();
int originZ = origin.getZ();
int[][][] blockData = SchematicPlacer.getBlockData(schematic, width, height, length);
SchematicBlockSample blockSample = new SchematicBlockSample(schematic, world);
SchematicBlockSample blockSample = Schematic.blockSample(schematic, world);
BiMap<BlockState, Integer> palette = ImmutableBiMap.copyOf(schematic.getBlockPalette());
// SchematicPlacer.placeBlocks(width, height, length, originX, originY, originZ, blockData);
blockSample.place(origin);
SchematicPlacer.placeEntities(originX, originY, originZ, schematic, world);
SchematicPlacer.placeBlockEntities(originX, originY, originZ, schematic, blockSample);
}
static int[][][] getBlockData(Schematic schematic, int width, int height, int length) {
int[] blockDataIntArray = schematic.getBlockData().toArray();
byte[] blockDataIntArray = schematic.getBlockData().array();
int[][][] blockData = new int[width][height][length];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
@ -103,7 +102,7 @@ public final class SchematicPlacer {
BlockEntity blockEntity = blockSample.getBlockEntity(pos);
// TODO: fail with an exception
if (blockEntity != null) {
blockEntity.fromTag(blockSample.getBlockState(pos), tag);
blockEntity.fromTag(blockSample.getWorld().getBlockState(pos), tag);
blockSample.getWorld().getChunk(pos).setBlockEntity(pos, blockEntity);
}
}