Skip to content

Commit

Permalink
But what if you wanted to go to Gaia from anywhere?
Browse files Browse the repository at this point in the history
  • Loading branch information
Andromander committed May 17, 2021
1 parent 5c1a8d3 commit b112614
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
Expand Down Expand Up @@ -67,7 +68,7 @@ public boolean tryToCreatePortal(World worldIn, BlockPos pos) {

// This will check for creation conditions in the Overworld or Gaia
private boolean canCreatePortalByWorld(World world, BlockPos pos) {
if (world.dimension() == World.OVERWORLD) {
if (world.dimension().location().equals(ModGaiaConfig.startDimRL)) {
//Check if the portal needs to be checking
if (ModGaiaConfig.portalCheck.get()) {
Optional<RegistryKey<Biome>> biome = world.getBiomeName(pos);
Expand Down Expand Up @@ -136,7 +137,7 @@ public void entityInside(BlockState state, World world, BlockPos pos, Entity ent
if (entity.level instanceof ServerWorld) {
ServerWorld serverworld = (ServerWorld)entity.level;
MinecraftServer minecraftserver = serverworld.getServer();
RegistryKey<World> registrykey = entity.level.dimension() == ModDimensions.gaia_world ? World.OVERWORLD : ModDimensions.gaia_world;
RegistryKey<World> registrykey = entity.level.dimension() == ModDimensions.gaia_world ? ModGaiaConfig.startDimRK : ModDimensions.gaia_world;
ServerWorld serverworld1 = minecraftserver.getLevel(registrykey);
if (serverworld1 != null && !entity.isPassenger()) {
entity.setPortalCooldown();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/androsa/gaiadimension/block/GoldFireBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androsa.gaiadimension.registry.ModBlocks;
import androsa.gaiadimension.registry.ModDimensions;
import androsa.gaiadimension.registry.ModGaiaConfig;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -110,7 +111,7 @@ protected boolean canDie(World worldIn, BlockPos pos) {
@Deprecated
public void onPlace(BlockState state1, World worldIn, BlockPos pos, BlockState state2, boolean flag) {
if (state2.getBlock() != state1.getBlock()) {
if (worldIn.dimension() != World.OVERWORLD && worldIn.dimension() != ModDimensions.gaia_world || !ModBlocks.gaia_portal.get().tryToCreatePortal(worldIn, pos)) {
if (!worldIn.dimension().location().equals(ModGaiaConfig.startDimRL) && worldIn.dimension() != ModDimensions.gaia_world || !ModBlocks.gaia_portal.get().tryToCreatePortal(worldIn, pos)) {
if (!state1.canSurvive(worldIn, pos)) {
worldIn.removeBlock(pos, false);
} else {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/androsa/gaiadimension/registry/ModGaiaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
import androsa.gaiadimension.GaiaDimensionMod;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;

import java.util.Collections;
import java.util.List;

import static net.minecraftforge.common.ForgeConfigSpec.*;

@Mod.EventBusSubscriber(modid = GaiaDimensionMod.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModGaiaConfig {
private static final String config = GaiaDimensionMod.MODID + ".config.";

public static ConfigValue<List<? extends String>> starsInSky;
public static ResourceLocation startDimRL;
public static RegistryKey<World> startDimRK;

public static List<? extends String> starBiomes = Collections.singletonList("gaiadimension:purple_agate_swamp");

Expand All @@ -27,6 +36,7 @@ public ClientConfig(Builder builder) {
}
}

public static ConfigValue<? extends String> startDimension;
public static BooleanValue portalCheck;
public static EnumValue<ListType> listType;
public static EnumValue<BiomeType> biomeType;
Expand All @@ -46,6 +56,10 @@ public ClientConfig(Builder builder) {

public static class CommonConfig {
public CommonConfig(Builder builder) {
startDimension = builder
.translation(config + "start_dimension")
.comment("The Dimension that Gaia will connect to. Results may vary based on the World chosen. Existing portals will remain regardless of what is set here until they are broken, however they may no longer connect.")
.define("startDimension", "minecraft:overworld");
portalCheck = builder
.translation(config + "portal_creation")
.comment("Change how the portal can be created. If true, the portal will check where it is allowed to spawn based on the type of list and what contents are in the list.")
Expand Down Expand Up @@ -77,6 +91,31 @@ public static boolean canDisplayStars(RegistryKey<Biome> define) {
return starsInSky.get().contains(define.location().toString());
}

@SubscribeEvent
public static void onConfigLoaded(ModConfig.Loading event) {
System.out.println("Config Loading");
if (event.getConfig().getModId().equals(GaiaDimensionMod.MODID)) {
checkDimension();
}
}

@SubscribeEvent
public static void onConfigChanged(ModConfig.Reloading event) {
if (event.getConfig().getModId().equals(GaiaDimensionMod.MODID)) {
checkDimension();
}
}

private static void checkDimension() {
ResourceLocation rl = ResourceLocation.tryParse(startDimension.get());
if (rl == null) {
GaiaDimensionMod.LOGGER.warn("Could not create a ResourceLocation with the Start Dimension! Is there a typo, or is there an incorrect character?");
rl = World.OVERWORLD.location();
}
startDimRL = rl;
startDimRK = RegistryKey.create(Registry.DIMENSION_REGISTRY, startDimRL);
}

public enum ListType {
BLACKLIST,
WHITELIST
Expand Down

0 comments on commit b112614

Please sign in to comment.