Add a new decorator
This commit is contained in:
parent
18b1f998e5
commit
1d3a46a7b1
4 changed files with 81 additions and 48 deletions
|
@ -20,6 +20,10 @@ public class EternalFluidBlock extends FluidBlock {
|
|||
|
||||
@Override
|
||||
public void onEntityCollision(BlockState blockState, World world, BlockPos blockPos, Entity entity) {
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
TARGET.receiveEntity(entity, entity.yaw);
|
||||
} catch (Throwable e) {
|
||||
|
|
|
@ -14,58 +14,56 @@ import org.dimdev.dimdoors.world.pocket.VirtualLocation;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import static org.dimdev.dimdoors.util.EntityUtils.chat;
|
||||
|
||||
public class EscapeTarget extends VirtualTarget implements EntityTarget { // TODO: createRift option
|
||||
public static final Codec<EscapeTarget> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
Codec.BOOL.fieldOf("canEscapeLimbo").forGetter(target -> target.canEscapeLimbo)
|
||||
).apply(instance, EscapeTarget::new));
|
||||
public static final Codec<EscapeTarget> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
Codec.BOOL.fieldOf("canEscapeLimbo").forGetter(target -> target.canEscapeLimbo)
|
||||
).apply(instance, EscapeTarget::new));
|
||||
|
||||
protected boolean canEscapeLimbo;
|
||||
protected boolean canEscapeLimbo;
|
||||
|
||||
public EscapeTarget(boolean canEscapeLimbo) {
|
||||
this.canEscapeLimbo = canEscapeLimbo;
|
||||
}
|
||||
public EscapeTarget(boolean canEscapeLimbo) {
|
||||
this.canEscapeLimbo = canEscapeLimbo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receiveEntity(Entity entity, float yawOffset) {
|
||||
if (!ModDimensions.isDimDoorsPocketDimension(entity.world) && !(ModDimensions.isLimboDimension(entity.world))) {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.not_in_pocket_dim"));
|
||||
return false;
|
||||
}
|
||||
if (ModDimensions.isLimboDimension(entity.world) && !this.canEscapeLimbo) {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.cannot_escape_limbo"));
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean receiveEntity(Entity entity, float yawOffset) {
|
||||
if (!ModDimensions.isDimDoorsPocketDimension(entity.world) && !(ModDimensions.isLimboDimension(entity.world))) {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.not_in_pocket_dim"));
|
||||
return false;
|
||||
}
|
||||
if (ModDimensions.isLimboDimension(entity.world) && !this.canEscapeLimbo) {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.cannot_escape_limbo"));
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID uuid = entity.getUuid();
|
||||
if (uuid != null) {
|
||||
Location destLoc = RiftRegistry.instance().getOverworldRift(uuid);
|
||||
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || this.canEscapeLimbo) {
|
||||
Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos())).projectToWorld(false);
|
||||
TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), 0);
|
||||
} else {
|
||||
if (destLoc == null) {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.did_not_use_rift"));
|
||||
} else {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.rift_has_closed"));
|
||||
}
|
||||
if (!entity.getEntityWorld().isClient) {
|
||||
if (ModDimensions.LIMBO_DIMENSION != null) {
|
||||
Entity newEntity = entity.moveToWorld(ModDimensions.LIMBO_DIMENSION);
|
||||
newEntity.setPos(this.location.getX(), this.location.getY(), this.location.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false; // No escape info for that entity
|
||||
}
|
||||
}
|
||||
UUID uuid = entity.getUuid();
|
||||
if (uuid != null) {
|
||||
Location destLoc = RiftRegistry.instance().getOverworldRift(uuid);
|
||||
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || this.canEscapeLimbo) {
|
||||
Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos())).projectToWorld(false);
|
||||
TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), 0);
|
||||
} else {
|
||||
if (destLoc == null) {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.did_not_use_rift"));
|
||||
} else {
|
||||
chat(entity, new TranslatableText("rifts.destinations.escape.rift_has_closed"));
|
||||
}
|
||||
if (ModDimensions.LIMBO_DIMENSION != null) {
|
||||
TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, new BlockPos(this.location.getX(), this.location.getY(), this.location.getZ()), 0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false; // No escape info for that entity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualTargetType<? extends VirtualTarget> getType() {
|
||||
return VirtualTargetType.ESCAPE;
|
||||
}
|
||||
@Override
|
||||
public VirtualTargetType<? extends VirtualTarget> getType() {
|
||||
return VirtualTargetType.ESCAPE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.function.Supplier;
|
|||
import org.dimdev.dimdoors.ModConfig;
|
||||
import org.dimdev.dimdoors.block.ModBlocks;
|
||||
import org.dimdev.dimdoors.mixin.GenerationSettingsAccessor;
|
||||
import org.dimdev.dimdoors.world.feature.decorator.EternalFluidLakeDecorator;
|
||||
import org.dimdev.dimdoors.world.feature.gateway.LimboGatewayFeature;
|
||||
import org.dimdev.dimdoors.world.feature.gateway.schematic.SandstonePillarsV2Gateway;
|
||||
import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicV2Gateway;
|
||||
|
@ -19,6 +20,7 @@ import net.minecraft.util.registry.BuiltinRegistries;
|
|||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
import net.minecraft.world.gen.decorator.RangeDecoratorConfig;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
|
@ -30,21 +32,24 @@ import net.minecraft.world.gen.feature.SingleStateFeatureConfig;
|
|||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
public final class ModFeatures {
|
||||
public static final Feature<SchematicV2GatewayFeatureConfig> SCHEMATIC_GATEWAY_FEATURE = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "schematic_gateway"), new SchematicV2GatewayFeature(SchematicV2GatewayFeatureConfig.CODEC));
|
||||
public static final Feature<SchematicV2GatewayFeatureConfig> SCHEMATIC_GATEWAY_FEATURE = new SchematicV2GatewayFeature(SchematicV2GatewayFeatureConfig.CODEC);
|
||||
public static final Feature<DefaultFeatureConfig> LIMBO_GATEWAY_FEATURE = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "limbo_gateway"), new LimboGatewayFeature());
|
||||
public static final SchematicV2Gateway SANDSTONE_PILLARS_GATEWAY = new SandstonePillarsV2Gateway();
|
||||
public static final SchematicV2Gateway TWO_PILLARS_GATEWAY = new TwoPillarsV2Gateway();
|
||||
public static final Decorator<ChanceDecoratorConfig> ETERNAL_FLUID_LAKE_DECORATOR = new EternalFluidLakeDecorator(ChanceDecoratorConfig.CODEC);
|
||||
public static final ConfiguredFeature<?, ?> SANDSTONE_PILLARS_FEATURE;
|
||||
public static final ConfiguredFeature<?, ?> TWO_PILLARS_FEATURE;
|
||||
public static final ConfiguredFeature<?, ?> LIMBO_GATEWAY_CONFIGURED_FEATURE;
|
||||
public static ConfiguredFeature<?, ?> ETERNAL_FLUID_LAKE;
|
||||
public static final ConfiguredFeature<?, ?> ETERNAL_FLUID_LAKE = Feature.LAKE.configure(new SingleStateFeatureConfig(ModBlocks.ETERNAL_FLUID.getDefaultState())).decorate(ETERNAL_FLUID_LAKE_DECORATOR.configure(new ChanceDecoratorConfig(20)));
|
||||
|
||||
public static void init() {
|
||||
SANDSTONE_PILLARS_GATEWAY.init();
|
||||
TWO_PILLARS_GATEWAY.init();
|
||||
Registry.register(Registry.FEATURE, new Identifier("dimdoors", "schematic_gateway"), SCHEMATIC_GATEWAY_FEATURE);
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars"), SANDSTONE_PILLARS_FEATURE);
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "limbo_gateway"), LIMBO_GATEWAY_CONFIGURED_FEATURE);
|
||||
ETERNAL_FLUID_LAKE = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "eternal_fluid_lake"), Feature.LAKE.configure(new SingleStateFeatureConfig(ModBlocks.ETERNAL_FLUID.getDefaultState())).decorate(Decorator.RANGE.configure(new RangeDecoratorConfig(5, 70, 128)).applyChance(20)));
|
||||
Registry.register(Registry.DECORATOR, new Identifier("dimdoors", "eternal_fluid_lake"), ETERNAL_FLUID_LAKE_DECORATOR);
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "eternal_fluid_lake"), ETERNAL_FLUID_LAKE);
|
||||
synchronized (BuiltinRegistries.BIOME) {
|
||||
BuiltinRegistries.BIOME.stream()
|
||||
.filter(biome ->
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.dimdev.dimdoors.world.feature.decorator;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
import net.minecraft.world.gen.decorator.DecoratorContext;
|
||||
|
||||
public class EternalFluidLakeDecorator extends Decorator<ChanceDecoratorConfig> {
|
||||
public EternalFluidLakeDecorator(Codec<ChanceDecoratorConfig> configCodec) {
|
||||
super(configCodec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<BlockPos> getPositions(DecoratorContext context, Random random, ChanceDecoratorConfig config, BlockPos pos) {
|
||||
if (random.nextInt(config.chance) == 0) {
|
||||
return Stream.of(new BlockPos(random.nextInt(16) + pos.getX(), random.nextInt(context.getMaxY()), random.nextInt(16) + pos.getZ()));
|
||||
}
|
||||
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue