Skip to content

Commit

Permalink
Fixed and improved Start In Atum teleporter
Browse files Browse the repository at this point in the history
Technically not fully working, as "Create Atum Portal" does not place the player in the portal - but that a problem with the normal Atum teleporter
  • Loading branch information
GirafiStudios committed Nov 16, 2020
1 parent d102b1f commit 7f9c4cf
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nonnull;

Expand All @@ -22,6 +24,7 @@ public AtemArmor(IArmorMaterial material, String name, EquipmentSlotType slot) {
}

@Override
@OnlyIn(Dist.CLIENT)
public <A extends BipedModel<?>> A getArmorModel(LivingEntity entityLiving, @Nonnull ItemStack stack, EquipmentSlotType armorSlot, A _default) {
return (A) new AtemArmorModel(armorSlot, StackHelper.hasFullArmorSet(entityLiving, AtumItems.EYES_OF_ATEM, AtumItems.BODY_OF_ATEM, AtumItems.LEGS_OF_ATEM, AtumItems.FEET_OF_ATEM));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.TickEvent;
Expand Down Expand Up @@ -79,8 +78,7 @@ public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
ServerWorld world = (ServerWorld) player.world;
PortalBlock.changeDimension(world, serverPlayer, new TeleporterAtumStart());
//TODO Fix setting spawn
serverPlayer.func_242111_a(Atum.ATUM, world.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverPlayer.getPosition()), serverPlayer.getRotationYawHead(), true, false); //Set players spawn point in Atum, when starting in Atum
serverPlayer.func_242111_a(Atum.ATUM, serverPlayer.getPosition(), serverPlayer.getRotationYawHead(), true, false); //Set players spawn point in Atum, when starting in Atum
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/teammetallurgy/atum/world/DimensionHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teammetallurgy.atum.world;

import com.google.common.collect.Lists;
import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.blocks.SandLayersBlock;
import com.teammetallurgy.atum.init.AtumBiomes;
Expand All @@ -14,17 +15,20 @@
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.ISeedReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.DerivedWorldInfo;
import net.minecraftforge.event.world.SleepFinishedTimeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;
import java.util.Optional;

@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class DimensionHelper {
public static final List<Block> SURFACE_BLOCKS = Lists.newArrayList(AtumBlocks.SAND, AtumBlocks.FERTILE_SOIL, AtumBlocks.LIMESTONE_GRAVEL);
public static final int GROUND_LEVEL = 63;

public static AtumDimensionData getData(ServerWorld serverWorld) {
Expand Down Expand Up @@ -62,6 +66,23 @@ public static boolean canPlaceSandLayer(ISeedReader world, BlockPos pos) {
&& !(state.getBlock() instanceof SandLayersBlock);
}

/**
* Only use when world#getHeight is not working
*
* @param world the world
* @param pos original pos
* @return surface pos
*/
public static BlockPos getSurfacePos(World world, BlockPos pos) {
while (pos.getY() > 1 && world.isAirBlock(pos.down())) {
pos = pos.down();
}
while (!world.isAirBlock(pos.up()) && (SURFACE_BLOCKS.contains(world.getBlockState(pos.down()).getBlock()) || world.getBlockState(pos.down()).getBlock() != AtumBlocks.SAND_LAYERED) || pos.getY() < 60) {
pos = pos.up();
}
return pos;
}

public static Biome getBiome(RegistryKey<Biome> key) {
return WorldGenRegistries.BIOME.getValueForKey(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.mojang.serialization.Codec;
import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.init.AtumBlocks;
import com.teammetallurgy.atum.misc.AtumConfig;
import com.teammetallurgy.atum.world.DimensionHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -39,15 +39,9 @@ public boolean generate(@Nonnull ISeedReader seedReader, @Nonnull ChunkGenerator
BlockPos rotatedPos = template.transformedSize(rotation);
int x = rand.nextInt(rotatedPos.getX()) + template.getSize().getX();
int z = rand.nextInt(rotatedPos.getZ()) + template.getSize().getZ();
BlockPos posOffset = pos.add(x, 0, z);
BlockPos posOffset = DimensionHelper.getSurfacePos(serverWorld, pos.add(x, 0, z));

while (posOffset.getY() > 1 && serverWorld.isAirBlock(posOffset.down())) {
posOffset = posOffset.down();
}
while (!serverWorld.isAirBlock(posOffset.up()) && (serverWorld.getBlockState(posOffset.down()).getBlock() != AtumBlocks.SAND || serverWorld.getBlockState(posOffset.down()).getBlock() != AtumBlocks.SAND_LAYERED) || posOffset.getY() < 60) {
posOffset = posOffset.up();
}
template.func_237146_a_(serverWorld, posOffset, posOffset, settings, rand, 20);
template.func_237146_a_(serverWorld, posOffset, posOffset.down(), settings, rand, 20);
return true;
} else {
Atum.LOG.error(AtumConfig.ATUM_START.atumStartStructure.get() + " is not a valid structure");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.teammetallurgy.atum.world.DimensionHelper;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.server.ServerWorld;
Expand All @@ -18,19 +17,16 @@ public class TeleporterAtumStart implements ITeleporter {

@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
System.out.println("HAS START STRUCTURE SPAWNED: " + DimensionHelper.getData(destWorld).hasStartStructureSpawned());
if (!DimensionHelper.getData(destWorld).hasStartStructureSpawned()) { //TODO Test in multiplayer
this.onAtumJoining(destWorld, entity, yaw);
BlockPos spawnPos = DimensionHelper.getSurfacePos(destWorld, destWorld.getSpawnPoint());
if (!DimensionHelper.getData(destWorld).hasStartStructureSpawned()) {
this.onInitialAtumJoining(destWorld, spawnPos);
DimensionHelper.getData(destWorld).setHasStartStructureSpawned(true);
return repositionEntity.apply(false);
}
return repositionEntity.apply(false);
return this.onAtumJoining(destWorld, repositionEntity.apply(false), spawnPos, yaw);
}

private void onAtumJoining(ServerWorld world, Entity entity, float yaw) {
private Entity onAtumJoining(ServerWorld world, Entity entity, BlockPos spawnPos, float yaw) {
if (world.getDimensionKey() == Atum.ATUM) {
BlockPos spawnPos = new BlockPos(world.getWorldInfo().getSpawnX(), world.getWorldInfo().getSpawnY(), world.getWorldInfo().getSpawnZ());
spawnPos = world.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, spawnPos);
if (AtumConfig.ATUM_START.startInAtumPortal.get()) {
TeleporterAtum teleporterAtum = TeleporterAtum.INSTANCE;
teleporterAtum.makePortal(world, entity);
Expand All @@ -39,6 +35,12 @@ private void onAtumJoining(ServerWorld world, Entity entity, float yaw) {
entity.rotationYaw = yaw;
entity.moveForced(spawnPos.getX(), spawnPos.getY() + 1, spawnPos.getZ());
}
}
return entity;
}

private void onInitialAtumJoining(ServerWorld world, BlockPos spawnPos) {
if (world.getDimensionKey() == Atum.ATUM) {
if (AtumConfig.ATUM_START.startInAtumPortal.get()) {
spawnPos = spawnPos.add(4, 0, 4);
}
Expand Down

0 comments on commit 7f9c4cf

Please sign in to comment.