diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index be9d2d245..a5bebb08e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.booklet.InitBooklet; +import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler; import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting; import de.ellpeck.actuallyadditions.mod.crafting.InitCrafting; @@ -21,6 +22,7 @@ import de.ellpeck.actuallyadditions.mod.crafting.ItemCrafting; import de.ellpeck.actuallyadditions.mod.entity.InitEntities; import de.ellpeck.actuallyadditions.mod.event.InitEvents; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; +import de.ellpeck.actuallyadditions.mod.gen.CaveWorldType; import de.ellpeck.actuallyadditions.mod.gen.InitVillager; import de.ellpeck.actuallyadditions.mod.gen.OreGen; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; @@ -104,6 +106,11 @@ public class ActuallyAdditions{ InitEvents.init(); InitCrafting.init(); DungeonLoot.init(); + + if(ConfigValues.caveWorld){ + new CaveWorldType(); + } + proxy.init(event); ModUtil.LOGGER.info("Initialization Finished."); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java index e8143c8c2..fd5ef7651 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java @@ -41,6 +41,8 @@ public class ConfigValues{ public static boolean lessParticles; public static boolean lessBlockBreakingEffects; + public static boolean caveWorld = true; //TODO Make this proper + public static void defineConfigValues(Configuration config){ for(ConfigCrafting currConf : craftingConfig){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/CaveWorldType.java b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/CaveWorldType.java new file mode 100644 index 000000000..9395fbd4e --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/CaveWorldType.java @@ -0,0 +1,145 @@ +/* + * This file ("CaveWorldType.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://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.gen; + +import de.ellpeck.actuallyadditions.mod.config.ConfigValues; +import de.ellpeck.actuallyadditions.mod.items.InitItems; +import de.ellpeck.actuallyadditions.mod.misc.WorldData; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import de.ellpeck.actuallyadditions.mod.util.Util; +import de.ellpeck.actuallyadditions.mod.util.playerdata.PersistentServerData; +import net.minecraft.block.BlockPlanks; +import net.minecraft.block.BlockSlab; +import net.minecraft.block.BlockWoodSlab; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraft.world.WorldType; +import net.minecraft.world.chunk.IChunkGenerator; +import net.minecraft.world.gen.ChunkProviderFlat; +import net.minecraft.world.gen.feature.WorldGenTrees; +import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class CaveWorldType extends WorldType{ + + public CaveWorldType(){ + //Name can't be longer than 16 :'( + super("actaddcaveworld"); + + Util.registerEvent(this); + } + + public static boolean isCave(World world){ + return ConfigValues.caveWorld && world.getWorldType() instanceof CaveWorldType; + } + + @Override + public IChunkGenerator getChunkGenerator(World world, String generatorOptions){ + return new ChunkProviderFlat(world, world.getSeed(), false, "3;minecraft:bedrock,254*minecraft:stone,minecraft:bedrock;2;"); + } + + @Override + public int getSpawnFuzz(WorldServer world, MinecraftServer server){ + return 1; + } + + private void generateCave(World world, BlockPos center){ + this.makeSphere(world, center, 8); + this.makeSphere(world, center.add(-3, 4, 3), 4); + this.makeSphere(world, center.add(4, 6, 1), 4); + this.makeSphere(world, center.add(3, 4, -3), 6); + this.makeSphere(world, center.add(4, -2, -3), 2); + this.makeSphere(world, center.add(5, 0, -3), 4); + this.makeSphere(world, center.add(1, 4, 3), 6); + this.makeSphere(world, center.add(-5, 1, 1), 4); + this.makeSphere(world, center.add(-1, 1, -7), 6); + this.makeSphere(world, center.add(-2, -1, 8), 3); + + world.setBlockState(center.add(-1, -5, -8), Blocks.DIRT.getStateFromMeta(1)); + WorldGenTrees trees = new WorldGenTrees(true); + trees.generate(world, Util.RANDOM, center.add(-1, -4, -8)); + + for(int z = 0; z <= 24; z++){ + for(int x = 0; x < 5; x++){ + for(int y = 0; y < 4; y++){ + BlockPos pos = center.add(x-3, y-4, 11+z); + + if(z%4 == 0 && (x == 0 || x == 4)){ + world.setBlockState(pos, Blocks.LOG2.getStateFromMeta(1)); + } + else if((z%4 == 0 || x == 0 || x == 4) && y == 3){ + world.setBlockState(pos, Blocks.PLANKS.getStateFromMeta(1)); + } + else if(!((y == 0 || y == 3) && Util.RANDOM.nextInt(5) <= 0)){ + world.setBlockToAir(pos); + } + } + } + } + + world.setBlockState(center.down(1), Blocks.GLOWSTONE.getDefaultState()); + } + + private void makeSphere(World world, BlockPos center, int radius){ + for(double x = -radius; x < radius; x++){ + for(double y = -radius; y < radius; y++){ + for(double z = -radius; z < radius; z++){ + if(Math.sqrt((x*x)+(y*y)+(z*z)) < radius){ + world.setBlockToAir(center.add(x, y, z)); + } + } + } + } + } + + @SubscribeEvent + public void onUpdate(LivingEvent.LivingUpdateEvent event){ + if(event.getEntity() != null){ + World world = event.getEntity().getEntityWorld(); + if(world != null && isCave(world) && !world.isRemote){ + BlockPos spawn = world.getSpawnPoint(); + BlockPos center = new BlockPos(spawn.getX(), 100, spawn.getZ()); + + NBTTagCompound data = WorldData.additionalData; + if(!data.getBoolean("GeneratedCave")){ + + ModUtil.LOGGER.info("Starting to generate cave world..."); + this.generateCave(world, center); + ModUtil.LOGGER.info("Generating cave world completed!"); + + data.setBoolean("GeneratedCave", true); + WorldData.makeDirty(); + } + + if(event.getEntity() instanceof EntityPlayerMP){ + EntityPlayerMP player = (EntityPlayerMP)event.getEntity(); + if(player.posY >= world.getHeight()){ + player.playerNetServerHandler.setPlayerLocation(center.getX()+0.5, center.getY()+1, center.getZ()+0.5, player.rotationYaw, player.rotationPitch); + } + + NBTTagCompound playerData = PersistentServerData.getDataFromPlayer(player); + if(!playerData.getBoolean("SpawnedFirst")){ + player.inventory.addItemStackToInventory(new ItemStack(InitItems.itemBooklet)); + + playerData.setBoolean("SpawnedFirst", true); + WorldData.makeDirty(); + } + } + } + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java index a2e04be56..8ea3d4c88 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java @@ -21,7 +21,9 @@ import net.minecraft.world.WorldSavedData; public class WorldData extends WorldSavedData{ public static final String DATA_TAG = ModUtil.MOD_ID+"WorldData"; - public static WorldData instance; + private static WorldData instance; + + public static NBTTagCompound additionalData = new NBTTagCompound(); public WorldData(String tag){ super(tag); @@ -40,13 +42,13 @@ public class WorldData extends WorldSavedData{ clearOldData(); ModUtil.LOGGER.info("Loading WorldData!"); - WorldData savedData = (WorldData)world.loadItemData(WorldData.class, WorldData.DATA_TAG); + WorldData savedData = (WorldData)world.loadItemData(WorldData.class, DATA_TAG); //Generate new SavedData if(savedData == null){ ModUtil.LOGGER.info("No WorldData found, creating..."); - savedData = new WorldData(WorldData.DATA_TAG); - world.setItemData(WorldData.DATA_TAG, savedData); + savedData = new WorldData(DATA_TAG); + world.setItemData(DATA_TAG, savedData); } else{ ModUtil.LOGGER.info("WorldData sucessfully received!"); @@ -67,40 +69,50 @@ public class WorldData extends WorldSavedData{ ModUtil.LOGGER.info("Clearing leftover Persistent Server Data from other worlds!"); PersistentServerData.playerSaveData.clear(); } + if(!additionalData.hasNoTags()){ + ModUtil.LOGGER.info("Clearing leftover Additional Data from other worlds!"); + additionalData = new NBTTagCompound(); + } } @Override public void readFromNBT(NBTTagCompound compound){ - //Laser World Data - NBTTagList networkList = compound.getTagList("Networks", 10); - for(int i = 0; i < networkList.tagCount(); i++){ - LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().readNetworkFromNBT(networkList.getCompoundTagAt(i)); - LaserRelayConnectionHandler.getInstance().networks.add(network); - } + //Laser World Data + NBTTagList networkList = compound.getTagList("Networks", 10); + for(int i = 0; i < networkList.tagCount(); i++){ + LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().readNetworkFromNBT(networkList.getCompoundTagAt(i)); + LaserRelayConnectionHandler.getInstance().networks.add(network); + } - //Player Data - NBTTagList playerList = compound.getTagList("PlayerData", 10); - for(int i = 0; i < playerList.tagCount(); i++){ - PersistentServerData.PlayerSave aSave = PersistentServerData.PlayerSave.fromNBT(playerList.getCompoundTagAt(i)); - PersistentServerData.playerSaveData.add(aSave); - } + //Player Data + NBTTagList playerList = compound.getTagList("PlayerData", 10); + for(int i = 0; i < playerList.tagCount(); i++){ + PersistentServerData.PlayerSave aSave = PersistentServerData.PlayerSave.fromNBT(playerList.getCompoundTagAt(i)); + PersistentServerData.playerSaveData.add(aSave); + } + + //Additional Data + additionalData = compound.getCompoundTag("Additional"); } @Override public void writeToNBT(NBTTagCompound compound){ - //Laser World Data - NBTTagList networkList = new NBTTagList(); - for(LaserRelayConnectionHandler.Network network : LaserRelayConnectionHandler.getInstance().networks){ - networkList.appendTag(LaserRelayConnectionHandler.getInstance().writeNetworkToNBT(network)); - } - compound.setTag("Networks", networkList); + //Laser World Data + NBTTagList networkList = new NBTTagList(); + for(LaserRelayConnectionHandler.Network network : LaserRelayConnectionHandler.getInstance().networks){ + networkList.appendTag(LaserRelayConnectionHandler.getInstance().writeNetworkToNBT(network)); + } + compound.setTag("Networks", networkList); - //Player Data - NBTTagList playerList = new NBTTagList(); - for(int i = 0; i < PersistentServerData.playerSaveData.size(); i++){ - PersistentServerData.PlayerSave theSave = PersistentServerData.playerSaveData.get(i); - playerList.appendTag(theSave.toNBT()); - } - compound.setTag("PlayerData", playerList); + //Player Data + NBTTagList playerList = new NBTTagList(); + for(int i = 0; i < PersistentServerData.playerSaveData.size(); i++){ + PersistentServerData.PlayerSave theSave = PersistentServerData.playerSaveData.get(i); + playerList.appendTag(theSave.toNBT()); + } + compound.setTag("PlayerData", playerList); + + //Additional Data + compound.setTag("Additional", additionalData); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java index 5388fc3a1..1b7807a1e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java @@ -59,7 +59,6 @@ public class ClientProxy implements IProxy{ private static List colorProdividingItemsForRegistering = new ArrayList(); private static Map modelLocationsForRegistering = new HashMap(); - private static Map modelVariantsForRegistering = new HashMap(); private static void countBookletWords(){ bookletWordCount = 0; @@ -100,9 +99,6 @@ public class ClientProxy implements IProxy{ for(Map.Entry entry : modelLocationsForRegistering.entrySet()){ ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue()); } - for(Map.Entry entry : modelVariantsForRegistering.entrySet()){ - ModelBakery.registerItemVariants(entry.getKey(), entry.getValue()); - } this.registerCustomFluidBlockRenderer(InitFluids.fluidCanolaOil); this.registerCustomFluidBlockRenderer(InitFluids.fluidOil); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityXPSolidifier.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityXPSolidifier.java index 26c9b797c..6b087fb41 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityXPSolidifier.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityXPSolidifier.java @@ -142,10 +142,10 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I return level*17; } else if(level > 15 && level < 31){ - return (int)(1.5*Math.pow(level, 2)-29.5*level+360); + return (int)(1.5*(level*level)-29.5*level+360); } else{ - return (int)(3.5*Math.pow(level, 2)-151.5*level+2220); + return (int)(3.5*(level*level)-151.5*level+2220); } } return 0;