WIP: portals

This commit is contained in:
Aleksey 2020-10-22 18:01:07 +03:00
parent 433ff01304
commit 9372d0ca02
12 changed files with 501 additions and 72 deletions

View file

@ -0,0 +1,64 @@
package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.Feature;
import ru.betterend.blocks.EndPortalBlock;
import ru.betterend.blocks.RunedFlavolite;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.util.BlocksHelper;
public class DefaultEndPortalFeature extends Feature<EndPortalFeatureConfig> {
public DefaultEndPortalFeature() {
super(EndPortalFeatureConfig.CODEC);
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
EndPortalFeatureConfig config) {
BlockState portalFrame = config.frameBlock.getDefaultState().with(RunedFlavolite.ACTIVATED, config.activated);
BlockState portalBlock = BlockRegistry.END_PORTAL_BLOCK.getDefaultState().with(EndPortalBlock.AXIS, config.axis);
BlockPos bottomCorner = pos;
BlockPos topCorner;
if (config.axis.equals(Direction.Axis.X)) {
topCorner = bottomCorner.add(3, 4, 0);
} else {
topCorner = bottomCorner.add(0, 4, 3);
}
for(BlockPos position : BlockPos.iterate(bottomCorner, topCorner)) {
if (position.equals(bottomCorner) || position.equals(topCorner) ||
position.getX() == bottomCorner.getX() && position.getZ() == bottomCorner.getZ() ||
position.getX() == topCorner.getX() && position.getZ() == topCorner.getZ()) {
BlocksHelper.setWithoutUpdate(world, position, portalFrame);
} else if (config.axis.equals(Direction.Axis.X)) {
if (position.getZ() == bottomCorner.getZ() && position.getY() == bottomCorner.getY() ||
position.getZ() == topCorner.getZ() && position.getY() == topCorner.getY()) {
BlocksHelper.setWithoutUpdate(world, position, portalFrame);
} else if (config.activated) {
BlocksHelper.setWithoutUpdate(world, position, portalBlock);
}
} else {
if (position.getX() == bottomCorner.getX() && position.getY() == bottomCorner.getY() ||
position.getX() == topCorner.getX() && position.getY() == topCorner.getY()) {
BlocksHelper.setWithoutUpdate(world, position, portalFrame);
} else if (config.activated) {
BlocksHelper.setWithoutUpdate(world, position, portalBlock);
}
}
}
return true;
}
}

View file

@ -26,8 +26,7 @@ public abstract class DefaultFeature extends Feature<DefaultFeatureConfig> {
}
protected BlockPos getPosOnSurfaceRaycast(StructureWorldAccess world, BlockPos pos) {
int h = BlocksHelper.downRay(world, pos, 256);
return pos.down(h);
return this.getPosOnSurfaceRaycast(world, pos, 256);
}
protected BlockPos getPosOnSurfaceRaycast(StructureWorldAccess world, BlockPos pos, int dist) {

View file

@ -22,11 +22,11 @@ import ru.betterend.BetterEnd;
import ru.betterend.blocks.complex.StoneMaterial;
public class EndFeature {
private Feature<?> feature;
private ConfiguredFeature<?, ?> featureConfigured;
private GenerationStep.Feature featureStep;
protected Feature<?> feature;
protected ConfiguredFeature<?, ?> featureConfigured;
protected GenerationStep.Feature featureStep;
private EndFeature() {}
protected EndFeature() {}
public EndFeature(String name, Feature<DefaultFeatureConfig> feature, GenerationStep.Feature featureStep, ConfiguredFeature<?, ?> configuredFeature) {
Identifier id = BetterEnd.makeID(name);

View file

@ -1,64 +1,22 @@
package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.Feature;
import ru.betterend.blocks.EndPortalBlock;
import net.minecraft.world.gen.GenerationStep;
import ru.betterend.blocks.RunedFlavolite;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.util.BlocksHelper;
public class EndPortalFeature extends Feature<EndPortalFeatureConfig> {
public EndPortalFeature(Block frameBlock) {
super(EndPortalFeatureConfig.CODEC);
public class EndPortalFeature extends EndFeature {
private final RunedFlavolite frameBlock;
public EndPortalFeature(DefaultEndPortalFeature feature, RunedFlavolite frameBlock) {
this.feature = feature;
this.featureStep = GenerationStep.Feature.UNDERGROUND_STRUCTURES;
this.frameBlock = frameBlock;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
EndPortalFeatureConfig config) {
BlockState portalFrame = config.frameBlock.getDefaultState().with(RunedFlavolite.ACTIVATED, config.activated);
BlockState portalBlock = BlockRegistry.END_PORTAL_BLOCK.getDefaultState().with(EndPortalBlock.AXIS, config.axis);
BlockPos bottomCorner = pos;
BlockPos topCorner;
if (config.axis.equals(Direction.Axis.X)) {
topCorner = bottomCorner.add(0, 4, 3);
} else {
topCorner = bottomCorner.add(3, 4, 0);
}
for(BlockPos position : BlockPos.iterate(bottomCorner, topCorner)) {
if (position.equals(bottomCorner) || position.equals(topCorner) ||
position.getX() == bottomCorner.getX() && position.getZ() == bottomCorner.getZ() ||
position.getX() == topCorner.getX() && position.getZ() == topCorner.getZ()) {
BlocksHelper.setWithoutUpdate(world, position, portalFrame);
} else if (config.axis.equals(Direction.Axis.X)) {
if (position.getX() == bottomCorner.getX() && position.getY() == bottomCorner.getY() ||
position.getX() == topCorner.getX() && position.getY() == topCorner.getY()) {
BlocksHelper.setWithoutUpdate(world, position, portalFrame);
} else if (config.activated) {
BlocksHelper.setWithoutUpdate(world, position, portalBlock);
}
} else {
if (position.getZ() == bottomCorner.getZ() && position.getY() == bottomCorner.getY() ||
position.getZ() == topCorner.getZ() && position.getY() == topCorner.getY()) {
BlocksHelper.setWithoutUpdate(world, position, portalFrame);
} else if (config.activated) {
BlocksHelper.setWithoutUpdate(world, position, portalBlock);
}
}
}
return true;
public EndPortalFeature configure(Direction.Axis axis, boolean active) {
this.featureConfigured = ((DefaultEndPortalFeature) this.feature).configure(EndPortalFeatureConfig.create(frameBlock, axis, active));
return this;
}
}