Fixed names and updated gatewyas

Changes to be committed:
	modified:   src/main/java/org/dimdev/dimcore/schematic/v2/Schematic.java
	modified:   src/main/java/org/dimdev/dimcore/schematic/v2/SchematicPlacer.java
	modified:   src/main/java/org/dimdev/dimcore/schematic/v2/SchematicTest.java
	renamed:    src/main/java/org/dimdev/dimdoors/item/RayTraceHelper.java -> src/main/java/org/dimdev/dimdoors/item/RaycastHelper.java
	modified:   src/main/java/org/dimdev/dimdoors/item/RiftBladeItem.java
	modified:   src/main/java/org/dimdev/dimdoors/item/RiftConfigurationToolItem.java
	modified:   src/main/java/org/dimdev/dimdoors/item/RiftRemoverItem.java
	modified:   src/main/java/org/dimdev/dimdoors/item/RiftStabilizerItem.java
	modified:   src/main/java/org/dimdev/dimdoors/mixin/DefaultBiomeFeaturesMixin.java
	modified:   src/main/java/org/dimdev/dimdoors/mixin/ListTagAccessor.java
	modified:   src/main/java/org/dimdev/dimdoors/rift/targets/LocalReference.java
	modified:   src/main/java/org/dimdev/dimdoors/util/Location.java
	modified:   src/main/java/org/dimdev/dimdoors/util/RotatedLocation.java
	modified:   src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java
	modified:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/BaseGateway.java
	modified:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/LimboGateway.java
	modified:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/SandstonePillarsGateway.java
	modified:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/SchematicGateway.java
	modified:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/SchematicGatewayFeatureConfig.java
	new file:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/v2/SandstonePillarsV2Gateway.java
	new file:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/v2/SchematicV2Gateway.java
	new file:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/v2/SchematicV2GatewayFeature.java
	new file:   src/main/java/org/dimdev/dimdoors/world/feature/gateway/v2/SchematicV2GatewayFeatureConfig.java
	modified:   src/main/java/org/dimdev/dimdoors/world/limbo/LimboChunkGenerator.java
	new file:   src/main/resources/data/dimdoors/gateways/v2/sandstone_pillars.schem
This commit is contained in:
SD 2020-09-11 16:00:37 +05:30
parent bb98adf294
commit 5a9bf9b922
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
25 changed files with 258 additions and 58 deletions

View file

@ -4,11 +4,14 @@ import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.StructureWorldAccess;
@ -114,4 +117,20 @@ public class Schematic {
public static SchematicBlockSample blockSample(Schematic schem, StructureWorldAccess world) {
return blockSample(schem).withWorld(world);
}
public static Schematic fromTag(CompoundTag tag) {
return CODEC.decode(NbtOps.INSTANCE, tag).getOrThrow(false, System.err::println).getFirst();
}
public static CompoundTag toTag(Schematic schem) {
return (CompoundTag) CODEC.encodeStart(NbtOps.INSTANCE, schem).getOrThrow(false, System.err::println);
}
public static Schematic fromJson(JsonObject json) {
return CODEC.decode(JsonOps.INSTANCE, json).getOrThrow(false, System.err::println).getFirst();
}
public static JsonObject toJson(Schematic schem) {
return (JsonObject) CODEC.encodeStart(JsonOps.INSTANCE, schem).getOrThrow(false, System.err::println);
}
}

View file

@ -1,14 +1,16 @@
package org.dimdev.dimcore.schematic.v2;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Objects;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.mixin.ListTagAccessor;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
@ -17,6 +19,8 @@ import net.minecraft.entity.EntityType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;

View file

@ -1,6 +1,7 @@
package org.dimdev.dimcore.schematic.v2;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.IntStream;
@ -36,12 +37,12 @@ public class SchematicTest {
e.setPos(1, 1, 1);
CompoundTag eTag = new CompoundTag();
e.saveSelfToTag(eTag);
Schematic schematic = new Schematic(2, 2543, meta, (short) 5, (short) 5, (short) 5, Vec3i.ZERO, -1, ImmutableBiMap.of(Blocks.AIR.getDefaultState(), 0, Blocks.NETHERRACK.getDefaultState(), 1), IntStream.of(1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0), ImmutableList.of(beTag), ImmutableList.of(eTag));
Schematic schematic = new Schematic(2, 2543, meta, (short) 5, (short) 5, (short) 5, Vec3i.ZERO, -1, ImmutableBiMap.of(Blocks.AIR.getDefaultState(), 0, Blocks.NETHERRACK.getDefaultState(), 1), ByteBuffer.wrap(new byte[]{1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0}), ImmutableList.of(beTag), ImmutableList.of(eTag));
DataResult<Tag> result = Schematic.CODEC.encodeStart(NbtOps.INSTANCE, schematic);
Path path = FabricLoader.getInstance().getConfigDir().resolve("schematic.schem");
if (!Files.exists(path)) {
Files.createFile(path);
}
NbtIo.method_30614((CompoundTag) result.getOrThrow(false, System.err::println), path.toFile());
NbtIo.writeCompressed((CompoundTag) result.getOrThrow(false, System.err::println), path.toFile());
}
}

View file

@ -9,7 +9,7 @@ import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.world.BlockView;
public final class RayTraceHelper {
public final class RaycastHelper {
public static final int REACH_DISTANCE = 5;
public static boolean hitsDetachedRift(HitResult hit, BlockView world) {

View file

@ -38,22 +38,22 @@ public class RiftBladeItem extends SwordItem {
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
HitResult hit = player.rayTrace(16, 1.0F, false); //TODO: make the range of the Rift Blade configurable
HitResult hit = player.raycast(16, 1.0F, false); //TODO: make the range of the Rift Blade configurable
if (hit == null) {
hit = player.rayTrace(RayTraceHelper.REACH_DISTANCE, 0, false);
hit = player.raycast(RaycastHelper.REACH_DISTANCE, 0, false);
}
if (world.isClient) {
if (RayTraceHelper.hitsLivingEntity(hit) || RayTraceHelper.hitsRift(hit, world)) {
if (RaycastHelper.hitsLivingEntity(hit) || RaycastHelper.hitsRift(hit, world)) {
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else {
player.sendMessage(new TranslatableText(getTranslationKey() + ".rift_miss"), true);
player.sendMessage(new TranslatableText(this.getTranslationKey() + ".rift_miss"), true);
DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor;
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
}
if (RayTraceHelper.hitsLivingEntity(hit)) {
if (RaycastHelper.hitsLivingEntity(hit)) {
double damageMultiplier = (double) stack.getDamage() / (double) stack.getMaxDamage();
// TODO: gaussian, instead or random
double offsetDistance = Math.random() * damageMultiplier * 7 + 2; //TODO: make these offset distances configurable
@ -73,7 +73,7 @@ public class RiftBladeItem extends SwordItem {
stack.damage(1, player, a -> {
});
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else if (RayTraceHelper.hitsRift(hit, world)) {
} else if (RaycastHelper.hitsRift(hit, world)) {
RiftBlockEntity rift = (RiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos()));
rift.teleport(player);

View file

@ -34,17 +34,17 @@ public class RiftConfigurationToolItem extends Item {
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
HitResult hit = player.rayTrace(RayTraceHelper.REACH_DISTANCE, 0, false);
HitResult hit = player.raycast(RaycastHelper.REACH_DISTANCE, 0, false);
if (world.isClient) {
if (!RayTraceHelper.hitsRift(hit, world)) {
if (!RaycastHelper.hitsRift(hit, world)) {
player.sendMessage(new TranslatableText("tools.rift_miss"), true);
DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor;
}
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
if (RayTraceHelper.hitsRift(hit, world)) {
if (RaycastHelper.hitsRift(hit, world)) {
RiftBlockEntity rift = (RiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos()));
System.out.println(rift);

View file

@ -1,6 +1,7 @@
package org.dimdev.dimdoors.item;
import java.util.List;
import java.util.Objects;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
@ -22,6 +23,9 @@ import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
public class RiftRemoverItem extends Item {
public static final String ID = "rift_remover";
@ -29,38 +33,37 @@ public class RiftRemoverItem extends Item {
super(settings);
}
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
if (I18n.hasTranslation(getTranslationKey() + ".info")) {
list.add(new TranslatableText(getTranslationKey() + ".info"));
}
list.add(new TranslatableText(this.getTranslationKey() + ".info"));
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
HitResult hit = player.rayTrace(RayTraceHelper.REACH_DISTANCE, 0, false);
HitResult hit = player.raycast(RaycastHelper.REACH_DISTANCE, 0, false);
if (world.isClient) {
if (!RayTraceHelper.hitsDetachedRift(hit, world)) {
if (!RaycastHelper.hitsDetachedRift(hit, world)) {
player.sendMessage(new TranslatableText("tools.rift_miss"), true);
DetachedRiftBlockEntityRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.GRAPHICS.highlightRiftCoreFor;
}
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
if (RayTraceHelper.hitsDetachedRift(hit, world)) {
if (RaycastHelper.hitsDetachedRift(hit, world)) {
DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos()));
if (!rift.closing) {
if (!Objects.requireNonNull(rift).closing) {
rift.setClosing(true);
world.playSound(null, player.getBlockPos(), ModSoundEvents.RIFT_CLOSE, SoundCategory.BLOCKS, 0.6f, 1);
stack.damage(10, player, a -> {
});
player.sendMessage(new TranslatableText(getTranslationKey() + ".closing"), true);
player.sendMessage(new TranslatableText(this.getTranslationKey() + ".closing"), true);
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else {
player.sendMessage(new TranslatableText(getTranslationKey() + ".already_closing"), true);
player.sendMessage(new TranslatableText(this.getTranslationKey() + ".already_closing"), true);
}
}
return new TypedActionResult<>(ActionResult.FAIL, stack);

View file

@ -34,10 +34,10 @@ public class RiftStabilizerItem extends Item {
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
HitResult hit = player.rayTrace(RayTraceHelper.REACH_DISTANCE, 0, false);
HitResult hit = player.raycast(RaycastHelper.REACH_DISTANCE, 0, false);
if (world.isClient) {
if (RayTraceHelper.hitsDetachedRift(hit, world)) {
if (RaycastHelper.hitsDetachedRift(hit, world)) {
// TODO: not necessarily success, fix this and all other similar cases to make arm swing correct
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else {
@ -47,7 +47,7 @@ public class RiftStabilizerItem extends Item {
}
}
if (RayTraceHelper.hitsDetachedRift(hit, world)) {
if (RaycastHelper.hitsDetachedRift(hit, world)) {
DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos()));
if (!rift.stabilized && !rift.closing) {
rift.setStabilized(true);

View file

@ -14,6 +14,6 @@ import net.minecraft.world.gen.feature.DefaultBiomeFeatures;
public class DefaultBiomeFeaturesMixin {
@Inject(method = "addDesertLakes", at = @At("RETURN"), remap = false)
private static void addGateway(GenerationSettings.Builder builder, CallbackInfo ci) {
builder.feature(GenerationStep.Feature.TOP_LAYER_MODIFICATION, ModFeatures.SANDSTONE_PILLARS_FEATURE);
builder.feature(GenerationStep.Feature.TOP_LAYER_MODIFICATION, ModFeatures.SANDSTONE_PILLARS_FEATURE_V2);
}
}

View file

@ -11,7 +11,7 @@ import net.minecraft.nbt.Tag;
@Mixin(ListTag.class)
public interface ListTagAccessor {
@Invoker("<init>")
static ListTag invokeInit(List<Tag> list, byte type) {
static ListTag of(List<Tag> list, byte type) {
throw new AssertionError();
}
}

View file

@ -7,7 +7,7 @@ import org.dimdev.dimdoors.util.Location;
import net.minecraft.util.math.BlockPos;
public class LocalReference extends RiftReference {
public static final Codec<LocalReference> CODEC = BlockPos.field_25064.xmap(LocalReference::new, LocalReference::getTarget).fieldOf("target").codec();
public static final Codec<LocalReference> CODEC = BlockPos.CODEC.xmap(LocalReference::new, LocalReference::getTarget).fieldOf("target").codec();
@Saved
protected BlockPos target;
@ -18,11 +18,11 @@ public class LocalReference extends RiftReference {
@Override
public Location getReferencedLocation() {
return new Location(location.world, target);
return new Location(this.location.world, this.target);
}
public BlockPos getTarget() {
return target;
return this.target;
}
@Override

View file

@ -16,7 +16,7 @@ public class Location {
public static final Codec<Location> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(World.CODEC.fieldOf("world").forGetter(location -> {
return location.world;
}), BlockPos.field_25064.fieldOf("pos").forGetter(location -> {
}), BlockPos.CODEC.fieldOf("pos").forGetter(location -> {
return location.pos;
})).apply(instance, Location::new);
});

View file

@ -14,7 +14,7 @@ public class RotatedLocation extends Location {
static Codec<RotatedLocation> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(
World.CODEC.fieldOf("world").forGetter(location -> location.world),
BlockPos.field_25064.fieldOf("pos").forGetter(location -> location.pos),
BlockPos.CODEC.fieldOf("pos").forGetter(location -> location.pos),
Codec.FLOAT.fieldOf("yaw").forGetter(a -> a.yaw),
Codec.FLOAT.fieldOf("pitch").forGetter(a -> a.pitch)
).apply(instance, RotatedLocation::new);

View file

@ -6,6 +6,10 @@ import org.dimdev.dimdoors.world.feature.gateway.SchematicGateway;
import org.dimdev.dimdoors.world.feature.gateway.SchematicGatewayFeature;
import org.dimdev.dimdoors.world.feature.gateway.SchematicGatewayFeatureConfig;
import org.dimdev.dimdoors.world.feature.gateway.TwoPillarsGateway;
import org.dimdev.dimdoors.world.feature.gateway.v2.SandstonePillarsV2Gateway;
import org.dimdev.dimdoors.world.feature.gateway.v2.SchematicV2Gateway;
import org.dimdev.dimdoors.world.feature.gateway.v2.SchematicV2GatewayFeature;
import org.dimdev.dimdoors.world.feature.gateway.v2.SchematicV2GatewayFeatureConfig;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
@ -16,17 +20,24 @@ import net.minecraft.world.gen.feature.Feature;
public final class ModFeatures {
public static final Feature<SchematicGatewayFeatureConfig> GATEWAY_FEATURE = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "gateway"), new SchematicGatewayFeature(SchematicGatewayFeatureConfig.CODEC));
public static final Feature<SchematicV2GatewayFeatureConfig> GATEWAY_FEATURE_V2 = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "gateway"), new SchematicV2GatewayFeature(SchematicV2GatewayFeatureConfig.CODEC));
public static final SchematicGateway SANDSTONE_PILLARS_GATEWAY = new SandstonePillarsGateway();
public static final SchematicGateway TWO_PILLARS_GATEWAY = new TwoPillarsGateway();
public static final SchematicV2Gateway SANDSTONE_PILLARS_GATEWAY_V2 = new SandstonePillarsV2Gateway();
public static final ConfiguredFeature<?, ?> SANDSTONE_PILLARS_FEATURE_V2;
public static final ConfiguredFeature<?, ?> SANDSTONE_PILLARS_FEATURE;
public static final ConfiguredFeature<?, ?> TWO_PILLARS_FEATURE;
public static void init() {
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars_v2"), SANDSTONE_PILLARS_FEATURE_V2);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars"), SANDSTONE_PILLARS_FEATURE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "two_pillars"), TWO_PILLARS_FEATURE);
}
static {
SANDSTONE_PILLARS_FEATURE_V2 = GATEWAY_FEATURE_V2.configure(new SchematicV2GatewayFeatureConfig(SchematicGateway.SCHEMATIC_ID_MAP.get(SANDSTONE_PILLARS_GATEWAY)))
.decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP
.applyChance(ModConfig.WORLD.gatewayGenChance));
SANDSTONE_PILLARS_FEATURE = GATEWAY_FEATURE.configure(new SchematicGatewayFeatureConfig(SchematicGateway.SCHEMATIC_ID_MAP.get(SANDSTONE_PILLARS_GATEWAY)))
.decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP
.applyChance(ModConfig.WORLD.gatewayGenChance));

View file

@ -1,31 +1,29 @@
package org.dimdev.dimdoors.world.feature.gateway;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
public abstract class BaseGateway {
public abstract void generate(StructureWorldAccess world, int x, int y, int z);
public void generate(StructureWorldAccess world, int x, int y, int z) {
}
protected boolean isBiomeValid(Biome biome) {
Biome[] biomes = this.getBiomes();
if (biomes.length != 0) {
for (Biome b : biomes) {
if (b.equals(biome)) {
return true;
}
}
return false;
}
return true;
protected boolean isBiomeValid(RegistryKey<Biome> biome) {
return this.getBiomes().contains(biome);
}
public boolean isLocationValid(World world, int x, int y, int z) {
return isBiomeValid(world.getBiome(new BlockPos(x, y, z)));
return this.isBiomeValid(BuiltinRegistries.BIOME.getKey(world.getBiome(new BlockPos(x, y, z))).orElseThrow(NullPointerException::new));
}
public Biome[] getBiomes() {
return new Biome[]{};
public Set<RegistryKey<Biome>> getBiomes() {
return ImmutableSet.of();
}
}

View file

@ -24,7 +24,7 @@ public class LimboGateway extends BaseGateway {
world.setBlockState(new BlockPos(x, y + 1, z - 1), unravelledFabric, 2);
world.setBlockState(new BlockPos(x, y + 1, z + 1), unravelledFabric, 2);
placePortal(world, new BlockPos(x, y + 1, z), Direction.NORTH);
this.placePortal(world, new BlockPos(x, y + 1, z), Direction.NORTH);
}
private void placePortal(StructureWorldAccess world, BlockPos pos, Direction facing) {

View file

@ -1,6 +1,11 @@
package org.dimdev.dimdoors.world.feature.gateway;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;
@ -10,7 +15,7 @@ public class SandstonePillarsGateway extends SchematicGateway {
}
@Override
public Biome[] getBiomes() {
return new Biome[]{BuiltinRegistries.BIOME.get(BiomeKeys.DESERT), BuiltinRegistries.BIOME.get(BiomeKeys.DESERT_LAKES), BuiltinRegistries.BIOME.get(BiomeKeys.DESERT_HILLS)};
public Set<RegistryKey<Biome>> getBiomes() {
return ImmutableSet.of( BiomeKeys.DESERT, BiomeKeys.DESERT_LAKES, BiomeKeys.DESERT_HILLS);
}
}

View file

@ -40,11 +40,11 @@ public abstract class SchematicGateway extends BaseGateway {
}
CompoundTag schematicNBT;
schematic = null;
this.schematic = null;
if (streamOpened) {
try {
schematicNBT = NbtIo.readCompressed(schematicDataStream);
schematic = Schematic.fromTag(schematicNBT);
this.schematic = Schematic.fromTag(schematicNBT);
//PocketTemplate.replacePlaceholders(schematic);
schematicDataStream.close();
} catch (IOException ex) {
@ -61,8 +61,8 @@ public abstract class SchematicGateway extends BaseGateway {
@Override
public void generate(StructureWorldAccess world, int x, int y, int z) {
schematic.place(world, x, y, z);
generateRandomBits(world, x, y, z);
this.schematic.place(world, x, y, z);
this.generateRandomBits(world, x, y, z);
}
/**

View file

@ -15,7 +15,7 @@ public class SchematicGatewayFeatureConfig implements FeatureConfig {
private final String gatewayId;
public SchematicGateway getGateway() {
return gateway;
return this.gateway;
}
public SchematicGatewayFeatureConfig(String gatewayId) {

View file

@ -0,0 +1,20 @@
package org.dimdev.dimdoors.world.feature.gateway.v2;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;
public class SandstonePillarsV2Gateway extends SchematicV2Gateway {
public SandstonePillarsV2Gateway() {
super("sandstone_pillars");
}
@Override
public Set<RegistryKey<Biome>> getBiomes() {
return ImmutableSet.of( BiomeKeys.DESERT, BiomeKeys.DESERT_LAKES, BiomeKeys.DESERT_HILLS);
}
}

View file

@ -0,0 +1,81 @@
package org.dimdev.dimdoors.world.feature.gateway.v2;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimcore.schematic.v2.Schematic;
import org.dimdev.dimcore.schematic.v2.SchematicPlacer;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.world.feature.gateway.BaseGateway;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
public class SchematicV2Gateway extends BaseGateway {
private static final Logger LOGGER = LogManager.getLogger();
private Schematic schematic;
public static final BiMap<SchematicV2Gateway, String> SCHEMATIC_ID_MAP = HashBiMap.create();
public static final BiMap<String, SchematicV2Gateway> ID_SCHEMATIC_MAP = HashBiMap.create();
public SchematicV2Gateway(String id) {
String schematicJarDirectory = "/data/dimdoors/gateways/v2/";
SCHEMATIC_ID_MAP.putIfAbsent(this, id);
ID_SCHEMATIC_MAP.putIfAbsent(id, this);
InputStream schematicStream = DimensionalDoorsInitializer.class.getResourceAsStream(schematicJarDirectory + id + ".schem");
DataInputStream schematicDataStream = null;
boolean streamOpened = false;
if (schematicStream != null) {
schematicDataStream = new DataInputStream(schematicStream);
streamOpened = true;
} else {
LOGGER.warn("Schematic '" + id + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
}
CompoundTag tag;
this.schematic = null;
if (streamOpened) {
try {
tag = NbtIo.readCompressed(schematicDataStream);
this.schematic = Schematic.fromTag(tag);
schematicDataStream.close();
} catch (IOException ex) {
LOGGER.error("Schematic file for " + id + " could not be read as a valid schematic NBT file.", ex);
} finally {
try {
schematicDataStream.close();
} catch (IOException ex) {
LOGGER.error("Error occured while closing schematicDataStream", ex);
}
}
}
}
@Override
public void generate(StructureWorldAccess world, int x, int y, int z) {
SchematicPlacer.place(this.schematic, world, new BlockPos(x, y, z));
}
public void generate(StructureWorldAccess world, BlockPos pos) {
SchematicPlacer.place(this.schematic, world, pos);
}
/**
* Generates randomized portions of the gateway structure (e.g. rubble, foliage)
*
* @param world - the world in which to generate the gateway
* @param x - the x-coordinate at which to center the gateway; usually where the door is placed
* @param y - the y-coordinate of the block on which the gateway may be built
* @param z - the z-coordinate at which to center the gateway; usually where the door is placed
*/
protected void generateRandomBits(StructureWorldAccess world, int x, int y, int z) {
}
}

View file

@ -0,0 +1,28 @@
package org.dimdev.dimdoors.world.feature.gateway.v2;
import java.util.Random;
import org.dimdev.dimdoors.world.feature.gateway.SchematicGatewayFeatureConfig;
import com.mojang.serialization.Codec;
import net.minecraft.block.AirBlock;
import net.minecraft.block.FallingBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.Feature;
public class SchematicV2GatewayFeature extends Feature<SchematicV2GatewayFeatureConfig> {
public SchematicV2GatewayFeature(Codec<SchematicV2GatewayFeatureConfig> codec) {
super(codec);
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, SchematicV2GatewayFeatureConfig featureConfig) {
if (world.getBlockState(blockPos).getBlock() instanceof AirBlock && world.getBlockState(blockPos.down()).getBlock() instanceof FallingBlock) {
featureConfig.getGateway().generate(world, blockPos);
return true;
}
return false;
}
}

View file

@ -0,0 +1,30 @@
package org.dimdev.dimdoors.world.feature.gateway.v2;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.gen.feature.FeatureConfig;
public class SchematicV2GatewayFeatureConfig implements FeatureConfig {
public static final Codec<SchematicV2GatewayFeatureConfig> CODEC = RecordCodecBuilder.create((instance) -> {
return instance.group(
Codec.STRING.fieldOf("gatewayId").forGetter(SchematicV2GatewayFeatureConfig::getGatewayId)
).apply(instance, SchematicV2GatewayFeatureConfig::new);
});
private final SchematicV2Gateway gateway;
private final String gatewayId;
public SchematicV2GatewayFeatureConfig(String id) {
this.gatewayId = id;
this.gateway = SchematicV2Gateway.ID_SCHEMATIC_MAP.get(id);
}
public SchematicV2Gateway getGateway() {
return this.gateway;
}
public String getGatewayId() {
return this.gatewayId;
}
}

View file

@ -573,7 +573,7 @@ public class LimboChunkGenerator extends ChunkGenerator {
public void populateEntities(ChunkRegion region) {
int i = region.getCenterChunkX();
int j = region.getCenterChunkZ();
Biome biome = region.getBiome((new ChunkPos(i, j)).getCenterBlockPos());
Biome biome = region.getBiome((new ChunkPos(i, j)).getStartPos());
ChunkRandom chunkRandom = new ChunkRandom();
chunkRandom.setPopulationSeed(region.getSeed(), i << 4, j << 4);
SpawnHelper.populateEntities(region, biome, i, j, chunkRandom);