Portal fixes and optimization

This commit is contained in:
Aleksey 2020-10-30 21:19:02 +03:00
parent 81e4098a72
commit 31f057eca5
11 changed files with 151 additions and 471 deletions

View file

@ -1,65 +0,0 @@
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.EndBlocks;
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 = EndBlocks.END_PORTAL_BLOCK.getDefaultState().with(EndPortalBlock.AXIS, config.axis);
BlockPos bottomCorner = pos;
BlockPos topCorner;
int width = config.width - 1;
int height = config.height - 1;
if (config.axis.equals(Direction.Axis.X)) {
topCorner = bottomCorner.add(width, height, 0);
} else {
topCorner = bottomCorner.add(0, height, width);
}
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

@ -1,26 +0,0 @@
package ru.betterend.world.features;
import net.minecraft.util.math.Direction;
import net.minecraft.world.gen.GenerationStep;
import ru.betterend.blocks.RunedFlavolite;
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;
}
public EndPortalFeature configure(Direction.Axis axis, int width, int height, boolean active) {
this.featureConfigured = ((DefaultEndPortalFeature) this.feature).configure(EndPortalFeatureConfig.create(frameBlock, axis, width, height, active));
return this;
}
public EndPortalFeature configure(Direction.Axis axis, boolean active) {
this.featureConfigured = ((DefaultEndPortalFeature) this.feature).configure(EndPortalFeatureConfig.create(frameBlock, axis, 4, 5, active));
return this;
}
}

View file

@ -1,52 +0,0 @@
package ru.betterend.world.features;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.gen.feature.FeatureConfig;
import ru.betterend.blocks.RunedFlavolite;
public class EndPortalFeatureConfig implements FeatureConfig {
public static final Codec<EndPortalFeatureConfig> CODEC = RecordCodecBuilder.create((instance) -> {
return instance.group(Codec.STRING.fieldOf("frame_block").forGetter(endPortalFeatureConfig -> {
return Registry.BLOCK.getId(endPortalFeatureConfig.frameBlock).toString();
}), Codec.STRING.fieldOf("axis").forGetter(endPortalFeatureConfig -> {
return endPortalFeatureConfig.axis.getName();
}), Codec.INT.fieldOf("width").forGetter(endPortalFeatureConfig -> {
return endPortalFeatureConfig.width;
}), Codec.INT.fieldOf("heigth").forGetter(endPortalFeatureConfig -> {
return endPortalFeatureConfig.height;
}), Codec.BOOL.fieldOf("activated").forGetter(endPortalFeatureConfig -> {
return endPortalFeatureConfig.activated;
})).apply(instance, EndPortalFeatureConfig::new);
});
public final RunedFlavolite frameBlock;
public final Direction.Axis axis;
public final boolean activated;
public final int width;
public final int height;
private EndPortalFeatureConfig(String frameBlock, String axis, int width, int height, boolean active) {
this.frameBlock = (RunedFlavolite) Registry.BLOCK.get(new Identifier(frameBlock));
this.axis = Direction.Axis.fromName(axis);
this.activated = active;
this.width = width;
this.height = height;
}
private EndPortalFeatureConfig(RunedFlavolite frameBlock, Direction.Axis axis, int width, int height, boolean active) {
this.frameBlock = frameBlock;
this.axis = axis;
this.activated = active;
this.width = width;
this.height = height;
}
public static EndPortalFeatureConfig create(RunedFlavolite block, Direction.Axis axis, int width, int height, boolean active) {
return new EndPortalFeatureConfig(block, axis, width, height, active);
}
}