Poertals can transfer items, possibility to build portal structure in the Overworld in Creative

This commit is contained in:
Aleksey 2020-10-30 22:03:01 +03:00
parent 98fbd6cc23
commit 37cd89d3f2
2 changed files with 25 additions and 12 deletions

View file

@ -64,7 +64,7 @@ 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) {
if (world instanceof ServerWorld && entity instanceof LivingEntity && !entity.hasVehicle() && !entity.hasPassengers() && entity.canUsePortals()) { if (world instanceof ServerWorld && !entity.hasVehicle() && !entity.hasPassengers() && entity.canUsePortals()) {
TeleportingEntity teleEntity = TeleportingEntity.class.cast(entity); TeleportingEntity teleEntity = TeleportingEntity.class.cast(entity);
if (teleEntity.hasCooldown()) return; if (teleEntity.hasCooldown()) return;
boolean isOverworld = world.getRegistryKey().equals(World.OVERWORLD); boolean isOverworld = world.getRegistryKey().equals(World.OVERWORLD);

View file

@ -1,6 +1,7 @@
package ru.betterend.util; package ru.betterend.util;
import java.awt.Point; import java.awt.Point;
import java.util.Random;
import java.util.Set; import java.util.Set;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -16,9 +17,12 @@ import net.minecraft.state.property.BooleanProperty;
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.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.feature.ConfiguredFeatures;
import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties;
import ru.betterend.blocks.EndPortalBlock; import ru.betterend.blocks.EndPortalBlock;
import ru.betterend.blocks.RunedFlavolite; import ru.betterend.blocks.RunedFlavolite;
@ -124,8 +128,8 @@ public class EternalRitual {
if (exit == null) { if (exit == null) {
this.exit = this.findPortalPos(); this.exit = this.findPortalPos();
} else { } else {
World overworld = world.getServer().getWorld(World.OVERWORLD); World targetWorld = this.getTargetWorld();
this.activatePortal(overworld, exit); this.activatePortal(targetWorld, exit);
} }
this.active = true; this.active = true;
} }
@ -162,9 +166,9 @@ public class EternalRitual {
public void removePortal() { public void removePortal() {
if (!active || !isValid()) return; if (!active || !isValid()) return;
World overworld = world.getServer().getWorld(World.OVERWORLD); World targetWorld = this.getTargetWorld();
this.removePortal(world, center); this.removePortal(world, center);
this.removePortal(overworld, exit); this.removePortal(targetWorld, exit);
} }
private void removePortal(World world, BlockPos center) { private void removePortal(World world, BlockPos center) {
@ -197,13 +201,13 @@ public class EternalRitual {
private BlockPos findPortalPos() { private BlockPos findPortalPos() {
MinecraftServer server = world.getServer(); MinecraftServer server = world.getServer();
ServerWorld overworld = server.getWorld(World.OVERWORLD); ServerWorld targetWorld = (ServerWorld) this.getTargetWorld();
Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes(); Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes();
double mult = registry.get(DimensionType.THE_END_ID).getCoordinateScale(); double mult = registry.get(DimensionType.THE_END_ID).getCoordinateScale();
BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult); BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult);
Direction.Axis portalAxis = Direction.Axis.X == axis ? Direction.Axis.Z : Direction.Axis.X; Direction.Axis portalAxis = Direction.Axis.X == axis ? Direction.Axis.Z : Direction.Axis.X;
if (checkIsAreaValid(overworld, basePos, portalAxis)) { if (checkIsAreaValid(targetWorld, basePos, portalAxis)) {
EternalRitual.generatePortal(overworld, basePos, portalAxis); EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) { if (portalAxis.equals(Direction.Axis.X)) {
return basePos.toImmutable(); return basePos.toImmutable();
} else { } else {
@ -216,8 +220,8 @@ public class EternalRitual {
for (int i = 0; i < step; i++) { for (int i = 0; i < step; i++) {
checkPos.setY(5); checkPos.setY(5);
while(checkPos.getY() < world.getHeight()) { while(checkPos.getY() < world.getHeight()) {
if(checkIsAreaValid(overworld, checkPos, portalAxis)) { if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) {
EternalRitual.generatePortal(overworld, checkPos, portalAxis); EternalRitual.generatePortal(targetWorld, checkPos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) { if (portalAxis.equals(Direction.Axis.X)) {
return checkPos.toImmutable(); return checkPos.toImmutable();
} else { } else {
@ -231,8 +235,12 @@ public class EternalRitual {
direction = direction.rotateYClockwise(); direction = direction.rotateYClockwise();
} }
} }
basePos.setY(overworld.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, basePos.getX(), basePos.getZ())); if (targetWorld.getRegistryKey() == World.END) {
EternalRitual.generatePortal(overworld, basePos, portalAxis); ConfiguredFeatures.END_ISLAND.generate(targetWorld, targetWorld.getChunkManager().getChunkGenerator(), new Random(basePos.asLong()), basePos.down());
} else {
basePos.setY(targetWorld.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, basePos.getX(), basePos.getZ()));
}
EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) { if (portalAxis.equals(Direction.Axis.X)) {
return basePos.toImmutable(); return basePos.toImmutable();
} else { } else {
@ -240,6 +248,11 @@ public class EternalRitual {
} }
} }
private World getTargetWorld() {
RegistryKey<World> target = world.getRegistryKey() == World.END ? World.OVERWORLD : World.END;
return world.getServer().getWorld(target);
}
private boolean checkIsAreaValid(World world, BlockPos pos, Direction.Axis axis) { private boolean checkIsAreaValid(World world, BlockPos pos, Direction.Axis axis) {
if (!isBaseValid(world, pos, axis)) return false; if (!isBaseValid(world, pos, axis)) return false;
return EternalRitual.checkArea(world, pos, axis); return EternalRitual.checkArea(world, pos, axis);