Schematics (update 14 of 20)

This commit is contained in:
SD 2021-02-11 23:10:39 +05:30
parent 8e7628a7f4
commit 7c69995338
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
7 changed files with 46 additions and 33 deletions

View file

@ -38,7 +38,7 @@ public class DimensionalDoorsClientInitializer implements ClientModInitializer {
PlayerInventorySlotUpdateS2CPacket packet = new PlayerInventorySlotUpdateS2CPacket();
try {
packet.read(packetByteBuf);
minecraftClient.player.inventory.setStack(packet.getSlot(), packet.getStack());
minecraftClient.player.getInventory().setStack(packet.getSlot(), packet.getStack());
// TODO: remove commented out debug code
//LOGGER.info("Synced slot " + packet.getSlot() + " with item stack " + packet.getStack().toTag(new CompoundTag()));
} catch (IOException e) {

View file

@ -378,19 +378,15 @@ public class Schematic implements BlockView {
this.setBlocks(world, xBase, yBase, zBase);
// Set BlockEntity data
for (CompoundTag BlockEntityNBT : this.tileEntities) {
Vec3i schematicPos = new BlockPos(BlockEntityNBT.getInt("x"), BlockEntityNBT.getInt("y"), BlockEntityNBT.getInt("z"));
for (CompoundTag blockEntityTag : this.tileEntities) {
Vec3i schematicPos = new BlockPos(blockEntityTag.getInt("x"), blockEntityTag.getInt("y"), blockEntityTag.getInt("z"));
BlockPos pos = new BlockPos(xBase, yBase, zBase).add(schematicPos);
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity != null) {
String id = BlockEntityNBT.getString("id");
String id = blockEntityTag.getString("id");
String blockBlockEntityId = BlockEntityType.getId(blockEntity.getType()).toString();
if (id.equals(blockBlockEntityId)) {
blockEntity.fromTag(world.getBlockState(pos), BlockEntityNBT);
blockEntity.setPos(pos);
// Correct the position
blockEntity.setLocation((World) world, pos);
blockEntity.fromTag(blockEntityTag);
blockEntity.markDirty();
} else {
System.err.println("Schematic contained BlockEntity " + id + " at " + pos + " but the BlockEntity of that block (" + world.getBlockState(pos) + ") must be " + blockBlockEntityId);
@ -517,4 +513,14 @@ public class Schematic implements BlockView {
public FluidState getFluidState(BlockPos blockPos) {
return null;
}
@Override
public int getHeight() {
return this.sizeY;
}
@Override
public int getBottomY() {
return 0;
}
}

View file

@ -30,4 +30,4 @@ public class SchematicStorage {
throw new RuntimeException(e);
}
}
}
}

View file

@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -81,12 +82,13 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
@Override
public @Nullable BlockEntity getBlockEntity(BlockPos pos) {
return Optional.of(this.getBlockState(pos))
.map(BlockState::getBlock)
.filter(BlockEntityProvider.class::isInstance)
.map(BlockEntityProvider.class::cast)
.map(bep -> bep.createBlockEntity(this))
.orElse(null);
BlockState blockState = this.getBlockState(pos);
if (blockState.getBlock() instanceof BlockEntityProvider) {
return ((BlockEntityProvider) blockState.getBlock()).createBlockEntity(pos, blockState);
}
return null;
}
@Override
@ -111,9 +113,9 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
tag.remove("Id");
}
BlockEntity blockEntity = BlockEntity.createFromTag(this.getBlockState(pos), tag);
BlockEntity blockEntity = BlockEntity.createFromTag(actualPos, this.getBlockState(pos), tag);
if (blockEntity != null) {
world.toServerWorld().setBlockEntity(actualPos, blockEntity);
world.toServerWorld().addBlockEntity(blockEntity);
}
}
for (Map.Entry<CompoundTag, Vec3d> entry : this.entityContainer.entrySet()) {
@ -162,6 +164,16 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
}
public boolean hasBiomes() {
return biomeData.length != 0;
return this.biomeData.length != 0;
}
@Override
public int getHeight() {
return this.schematic.getHeight();
}
@Override
public int getBottomY() {
return 0;
}
}

View file

@ -26,6 +26,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.world.biome.Biome;
public class Schematic {
@ -43,7 +44,7 @@ public class Schematic {
Codec.BYTE_BUFFER.fieldOf("BlockData").forGetter(Schematic::getBlockData),
Codec.list(CompoundTag.CODEC).optionalFieldOf("BlockEntities", ImmutableList.of()).forGetter(Schematic::getBlockEntities),
Codec.list(CompoundTag.CODEC).optionalFieldOf("Entities", ImmutableList.of()).forGetter(Schematic::getEntities),
SchematicBiomePalette.CODEC.optionalFieldOf("BiomePalette", Collections.emptyMap()).forGetter(Schematic::getBiomePalette),
Codec.unboundedMap(BuiltinRegistries.BIOME, Codec.INT).optionalFieldOf("BiomePalette", Collections.emptyMap()).forGetter(Schematic::getBiomePalette),
Codec.BYTE_BUFFER.optionalFieldOf("BiomeData", ByteBuffer.wrap(new byte[0])).forGetter(Schematic::getBlockData)
).apply(instance, Schematic::new));

View file

@ -1,11 +0,0 @@
package org.dimdev.dimdoors.util.schematic.v2;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.UnboundedMapCodec;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.world.biome.Biome;
public class SchematicBiomePalette {
public static final UnboundedMapCodec<Biome, Integer> CODEC = Codec.unboundedMap(BuiltinRegistries.BIOME, Codec.INT);
}

View file

@ -64,7 +64,12 @@ public class WorldlyBlockSample implements BlockView, ModifiableTestableWorld {
}
@Override
public BlockPos getTopPosition(Heightmap.Type type, BlockPos pos) {
return this.world.getTopPosition(type, pos);
public int getHeight() {
return this.relativeBlockSample.getHeight();
}
@Override
public int getBottomY() {
return this.relativeBlockSample.getBottomY();
}
}