WIP: End portals
This commit is contained in:
parent
28d501f351
commit
1d098eb7c2
5 changed files with 129 additions and 2 deletions
Binary file not shown.
|
@ -5,6 +5,7 @@ import java.util.Random;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.NetherPortalBlock;
|
import net.minecraft.block.NetherPortalBlock;
|
||||||
|
@ -14,14 +15,17 @@ import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.registry.BuiltinRegistries;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import net.minecraft.world.Heightmap;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldAccess;
|
import net.minecraft.world.WorldAccess;
|
||||||
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
import ru.betterend.client.ERenderLayer;
|
import ru.betterend.client.ERenderLayer;
|
||||||
import ru.betterend.client.IRenderTypeable;
|
import ru.betterend.client.IRenderTypeable;
|
||||||
import ru.betterend.registry.ParticleRegistry;
|
import ru.betterend.registry.ParticleRegistry;
|
||||||
|
|
||||||
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable {
|
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable {
|
||||||
|
|
||||||
public EndPortalBlock() {
|
public EndPortalBlock() {
|
||||||
super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).luminance(state -> {
|
super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).luminance(state -> {
|
||||||
return 12;
|
return 12;
|
||||||
|
@ -58,10 +62,24 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
||||||
|
BlockPos exitPos = this.findExitPos(world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ERenderLayer getRenderLayer() {
|
public ERenderLayer getRenderLayer() {
|
||||||
return ERenderLayer.TRANSLUCENT;
|
return ERenderLayer.TRANSLUCENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BlockPos findExitPos(World world, BlockPos pos) {
|
||||||
|
if (world.getRegistryKey().equals(World.OVERWORLD)) {
|
||||||
|
BlockPos basePos = pos.mutableCopy().set(pos.getX() * 8, pos.getY() * 8, pos.getZ() * 8);
|
||||||
|
int height = world.getTopY(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, basePos.getX(), basePos.getZ());
|
||||||
|
BlockPos.iterate(basePos.add(-16, -pos.getY() + 1, -16), basePos.add(16, height, 16)).forEach(position -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
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 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
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.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;
|
||||||
|
|
||||||
|
private EndPortalFeatureConfig(String frameBlock, String axis, boolean active) {
|
||||||
|
this.frameBlock = (RunedFlavolite) Registry.BLOCK.get(new Identifier(frameBlock));
|
||||||
|
this.axis = Direction.Axis.fromName(axis);
|
||||||
|
this.activated = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EndPortalFeatureConfig(RunedFlavolite frameBlock, Direction.Axis axis, boolean active) {
|
||||||
|
this.frameBlock = frameBlock;
|
||||||
|
this.axis = axis;
|
||||||
|
this.activated = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EndPortalFeatureConfig create(RunedFlavolite block, Direction.Axis axis, boolean active) {
|
||||||
|
return new EndPortalFeatureConfig(block, axis, active);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"animation": {
|
"animation": {
|
||||||
|
"interpolate": true,
|
||||||
"frametime": 4
|
"frametime": 4
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue