diff --git a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java index 6a057d8fa..a72de9fb8 100644 --- a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java +++ b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java @@ -45,6 +45,7 @@ import ellpeck.actuallyadditions.update.UpdateChecker; import ellpeck.actuallyadditions.util.FakePlayerUtil; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.Util; +import ellpeck.actuallyadditions.world.WorldTypeActAddCaves; import net.minecraft.init.Items; import net.minecraft.server.MinecraftServer; @@ -52,6 +53,8 @@ import net.minecraft.server.MinecraftServer; @Mod(modid = ModUtil.MOD_ID, name = ModUtil.NAME, version = ModUtil.VERSION, dependencies = "after:BuildCraft|Energy", canBeDeactivated = false, guiFactory = "ellpeck.actuallyadditions.config.GuiFactory") public class ActuallyAdditions{ + public static boolean isCaveMode = true; //TODO + @Instance(ModUtil.MOD_ID) public static ActuallyAdditions instance; @@ -70,6 +73,9 @@ public class ActuallyAdditions{ InitItems.init(); FuelHandler.init(); UpdateChecker.init(); + if(isCaveMode){ + new WorldTypeActAddCaves(); + } proxy.preInit(event); ModUtil.LOGGER.info("PreInitialization Finished."); diff --git a/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java b/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java index 2ba126c5b..faa2c301c 100644 --- a/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java +++ b/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java @@ -11,11 +11,13 @@ package ellpeck.actuallyadditions.event; import cpw.mods.fml.common.Loader; +import ellpeck.actuallyadditions.ActuallyAdditions; import ellpeck.actuallyadditions.config.values.ConfigBoolValues; import ellpeck.actuallyadditions.nei.NEIScreenEvents; import ellpeck.actuallyadditions.update.UpdateCheckerClientNotificationEvent; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.Util; +import ellpeck.actuallyadditions.world.ActAddCavesEvents; import net.minecraftforge.common.MinecraftForge; public class InitEvents{ @@ -30,6 +32,10 @@ public class InitEvents{ Util.registerEvent(new LogoutEvent()); Util.registerEvent(new WorldLoadingEvents()); MinecraftForge.TERRAIN_GEN_BUS.register(new WorldDecorationEvent()); + + if(ActuallyAdditions.isCaveMode){ + Util.registerEvent(new ActAddCavesEvents()); + } } public static void initClient(){ diff --git a/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java b/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java index 92cc5542f..38e085ae6 100644 --- a/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java +++ b/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java @@ -12,6 +12,7 @@ package ellpeck.actuallyadditions.misc; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.playerdata.PersistentServerData; +import ellpeck.actuallyadditions.world.ActAddCavesEvents; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.server.MinecraftServer; @@ -61,9 +62,15 @@ public class WorldData extends WorldSavedData{ public static void clearOldData(){ if(!LaserRelayConnectionHandler.getInstance().networks.isEmpty()){ ModUtil.LOGGER.info("Clearing leftover Laser Relay Connection Data from other worlds!"); + LaserRelayConnectionHandler.getInstance().networks.clear(); } if(!PersistentServerData.playerSaveData.isEmpty()){ ModUtil.LOGGER.info("Clearing leftover Persistent Server Data from other worlds!"); + PersistentServerData.playerSaveData.clear(); + } + if(!ActAddCavesEvents.cavesData.hasNoTags()){ + ModUtil.LOGGER.info("Clearing leftover Cave World Data from other worlds!"); + ActAddCavesEvents.cavesData = new NBTTagCompound(); } } @@ -82,6 +89,9 @@ public class WorldData extends WorldSavedData{ PersistentServerData.PlayerSave aSave = PersistentServerData.PlayerSave.fromNBT(playerList.getCompoundTagAt(i)); PersistentServerData.playerSaveData.add(aSave); } + + //Cave Data + ActAddCavesEvents.cavesData = compound.getCompoundTag("CaveData"); } @Override @@ -100,5 +110,8 @@ public class WorldData extends WorldSavedData{ playerList.appendTag(theSave.toNBT()); } compound.setTag("PlayerData", playerList); + + //Cave Data + compound.setTag("CaveData", ActAddCavesEvents.cavesData); } } diff --git a/src/main/java/ellpeck/actuallyadditions/world/ActAddCavesEvents.java b/src/main/java/ellpeck/actuallyadditions/world/ActAddCavesEvents.java new file mode 100644 index 000000000..c818b0f91 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/world/ActAddCavesEvents.java @@ -0,0 +1,136 @@ +/* + * This file ("ActAddCavesEvents.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.world; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import ellpeck.actuallyadditions.items.InitItems; +import ellpeck.actuallyadditions.util.Util; +import ellpeck.actuallyadditions.util.playerdata.PersistentServerData; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingEvent; + +public class ActAddCavesEvents{ + + public static NBTTagCompound cavesData = new NBTTagCompound(); + + @SubscribeEvent + public void onUpdate(LivingEvent.LivingUpdateEvent event){ + World world = event.entity.worldObj; + if(!world.isRemote && WorldTypeActAddCaves.isActAddCave(world) && event.entity instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)event.entity; + + //Create the caves + if(!cavesData.getBoolean("CavesCreated")){ + generateCaves(world); + cavesData.setBoolean("CavesCreated", true); + } + + //Spawn the player + NBTTagCompound playerData = PersistentServerData.getDataFromPlayer(player); + if(!playerData.getBoolean("SpawnedInCaves")){ + int x = cavesData.getInteger("StartX"); + int y = cavesData.getInteger("StartY"); + int z = cavesData.getInteger("StartZ"); + player.setSpawnChunk(new ChunkCoordinates(x, y, z), true); + player.setPositionAndUpdate(x+0.5, y+1, z+0.5); + player.inventory.addItemStackToInventory(new ItemStack(InitItems.itemBooklet)); + + playerData.setBoolean("SpawnedInCaves", true); + } + } + } + + private static void generateCaves(World world){ + ChunkCoordinates spawn = world.getSpawnPoint(); + + int cavesStartX = spawn.posX; + int cavesStartY = 80; + int cavesStartZ = spawn.posZ; + cavesData.setInteger("StartX", cavesStartX); + cavesData.setInteger("StartY", cavesStartY); + cavesData.setInteger("StartZ", cavesStartZ); + + //Generate initial box + for(int x = -7; x <= 7; x++){ + for(int z = -7; z <= 7; z++){ + for(int y = -5; y <= 9; y++){ + double distance = Vec3.createVectorHelper(x, y, z).distanceTo(Vec3.createVectorHelper(0, 0, 0)); + if(distance <= MathHelper.getRandomIntegerInRange(Util.RANDOM, 6, 7)){ + world.setBlockToAir(cavesStartX+x, cavesStartY+y, cavesStartZ+z); + } + } + } + } + + //Generate start tower + for(int y = -5; y < 0; y++){ + world.setBlock(cavesStartX-1, cavesStartY+y, cavesStartZ-1, Blocks.fence, 0, 2); + world.setBlock(cavesStartX+1, cavesStartY+y, cavesStartZ-1, Blocks.fence, 0, 2); + world.setBlock(cavesStartX+1, cavesStartY+y, cavesStartZ+1, Blocks.fence, 0, 2); + + world.setBlock(cavesStartX-1, cavesStartY+y, cavesStartZ+1, Blocks.planks, 1, 2); + world.setBlock(cavesStartX-1, cavesStartY+y, cavesStartZ+2, Blocks.ladder, 3, 2); + } + world.setBlock(cavesStartX-1, cavesStartY, cavesStartZ+2, Blocks.ladder, 3, 2); + for(int x = -1; x <= 1; x++){ + for(int z = -1; z <= 1; z++){ + world.setBlock(cavesStartX+x, cavesStartY, cavesStartZ+z, Blocks.planks, 1, 2); + } + } + world.setBlock(cavesStartX, cavesStartY, cavesStartZ, Blocks.glowstone, 0, 2); + + //Generate Mineshaft + for(int x = 4; x <= 12; x++){ + for(int z = -1; z <= 1; z++){ + for(int y = -5; y <= -3; y++){ + if(x%4 == 0 && z != 0){ + world.setBlock(cavesStartX+x, cavesStartY+y, cavesStartZ+z, Blocks.log, 0, 2); + } + else if(x%8 == 0 && y == -4){ + world.setBlock(cavesStartX+x, cavesStartY+y, cavesStartZ+z, Blocks.torch, 3, 2); + } + else if(y == -3){ + world.setBlock(cavesStartX+x, cavesStartY+y, cavesStartZ+z, Blocks.wooden_slab, 9, 2); + } + else{ + world.setBlockToAir(cavesStartX+x, cavesStartY+y, cavesStartZ+z); + } + } + } + } + + //Generate water + world.setBlock(cavesStartX-7, cavesStartY-3, cavesStartZ-1, Blocks.flowing_water, 0, 2); + world.setBlockToAir(cavesStartX-6, cavesStartY-3, cavesStartZ-1); + world.setBlockToAir(cavesStartX-5, cavesStartY-3, cavesStartZ-1); + world.setBlockToAir(cavesStartX-5, cavesStartY-4, cavesStartZ-1); + world.setBlockToAir(cavesStartX-5, cavesStartY-5, cavesStartZ-1); + world.setBlockToAir(cavesStartX-4, cavesStartY-5, cavesStartZ-1); + world.setBlock(cavesStartX-5, cavesStartY-6, cavesStartZ-1, Blocks.water, 0, 2); + world.setBlock(cavesStartX-4, cavesStartY-6, cavesStartZ-1, Blocks.water, 0, 2); + + //Generate dirt + for(int x = -3; x <= 3; x++){ + for(int z = -3; z <= 3; z++){ + if(Util.RANDOM.nextFloat() >= 0.5){ + world.setBlock(cavesStartX+x, cavesStartY-6, cavesStartZ+z, Blocks.dirt, 0, 2); + } + } + } + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/world/WorldTypeActAddCaves.java b/src/main/java/ellpeck/actuallyadditions/world/WorldTypeActAddCaves.java new file mode 100644 index 000000000..47bd62a25 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/world/WorldTypeActAddCaves.java @@ -0,0 +1,62 @@ +/* + * This file ("WorldTypeActAddCaves.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.world; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.util.ModUtil; +import net.minecraft.world.World; +import net.minecraft.world.WorldType; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.ChunkProviderFlat; + +public class WorldTypeActAddCaves extends WorldType{ + + public WorldTypeActAddCaves(){ + super("ActAddCaves"); + } + + public static boolean isActAddCave(World world){ + return world.provider.terrainType instanceof WorldTypeActAddCaves; + } + + @Override + @SideOnly(Side.CLIENT) + public String getTranslateName(){ + return ModUtil.MOD_ID_LOWER+".generator.caves"; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean showWorldInfoNotice(){ + return true; + } + + @Override + public float getCloudHeight(){ + return 256F; + } + + @Override + public int getSpawnFuzz(){ + return 1; + } + + @Override + public int getMinimumSpawnHeight(World world){ + return 20; + } + + @Override + public IChunkProvider getChunkGenerator(World world, String generatorOptions){ + return new ChunkProviderFlat(world, world.getSeed(), false, "7,253x1,7"); + } +}