Start of cave world.

Whaaaat?
This commit is contained in:
Ellpeck 2016-05-17 15:59:12 +02:00
parent fd407d3983
commit b5e8cf0345
6 changed files with 197 additions and 35 deletions

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements; import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.booklet.InitBooklet; 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.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting; import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting;
import de.ellpeck.actuallyadditions.mod.crafting.InitCrafting; 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.entity.InitEntities;
import de.ellpeck.actuallyadditions.mod.event.InitEvents; import de.ellpeck.actuallyadditions.mod.event.InitEvents;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; 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.InitVillager;
import de.ellpeck.actuallyadditions.mod.gen.OreGen; import de.ellpeck.actuallyadditions.mod.gen.OreGen;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
@ -104,6 +106,11 @@ public class ActuallyAdditions{
InitEvents.init(); InitEvents.init();
InitCrafting.init(); InitCrafting.init();
DungeonLoot.init(); DungeonLoot.init();
if(ConfigValues.caveWorld){
new CaveWorldType();
}
proxy.init(event); proxy.init(event);
ModUtil.LOGGER.info("Initialization Finished."); ModUtil.LOGGER.info("Initialization Finished.");

View file

@ -41,6 +41,8 @@ public class ConfigValues{
public static boolean lessParticles; public static boolean lessParticles;
public static boolean lessBlockBreakingEffects; public static boolean lessBlockBreakingEffects;
public static boolean caveWorld = true; //TODO Make this proper
public static void defineConfigValues(Configuration config){ public static void defineConfigValues(Configuration config){
for(ConfigCrafting currConf : craftingConfig){ for(ConfigCrafting currConf : craftingConfig){

View file

@ -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();
}
}
}
}
}
}

View file

@ -21,7 +21,9 @@ import net.minecraft.world.WorldSavedData;
public class WorldData extends WorldSavedData{ public class WorldData extends WorldSavedData{
public static final String DATA_TAG = ModUtil.MOD_ID+"WorldData"; 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){ public WorldData(String tag){
super(tag); super(tag);
@ -40,13 +42,13 @@ public class WorldData extends WorldSavedData{
clearOldData(); clearOldData();
ModUtil.LOGGER.info("Loading WorldData!"); 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 //Generate new SavedData
if(savedData == null){ if(savedData == null){
ModUtil.LOGGER.info("No WorldData found, creating..."); ModUtil.LOGGER.info("No WorldData found, creating...");
savedData = new WorldData(WorldData.DATA_TAG); savedData = new WorldData(DATA_TAG);
world.setItemData(WorldData.DATA_TAG, savedData); world.setItemData(DATA_TAG, savedData);
} }
else{ else{
ModUtil.LOGGER.info("WorldData sucessfully received!"); ModUtil.LOGGER.info("WorldData sucessfully received!");
@ -67,6 +69,10 @@ public class WorldData extends WorldSavedData{
ModUtil.LOGGER.info("Clearing leftover Persistent Server Data from other worlds!"); ModUtil.LOGGER.info("Clearing leftover Persistent Server Data from other worlds!");
PersistentServerData.playerSaveData.clear(); PersistentServerData.playerSaveData.clear();
} }
if(!additionalData.hasNoTags()){
ModUtil.LOGGER.info("Clearing leftover Additional Data from other worlds!");
additionalData = new NBTTagCompound();
}
} }
@Override @Override
@ -84,6 +90,9 @@ public class WorldData extends WorldSavedData{
PersistentServerData.PlayerSave aSave = PersistentServerData.PlayerSave.fromNBT(playerList.getCompoundTagAt(i)); PersistentServerData.PlayerSave aSave = PersistentServerData.PlayerSave.fromNBT(playerList.getCompoundTagAt(i));
PersistentServerData.playerSaveData.add(aSave); PersistentServerData.playerSaveData.add(aSave);
} }
//Additional Data
additionalData = compound.getCompoundTag("Additional");
} }
@Override @Override
@ -102,5 +111,8 @@ public class WorldData extends WorldSavedData{
playerList.appendTag(theSave.toNBT()); playerList.appendTag(theSave.toNBT());
} }
compound.setTag("PlayerData", playerList); compound.setTag("PlayerData", playerList);
//Additional Data
compound.setTag("Additional", additionalData);
} }
} }

View file

@ -59,7 +59,6 @@ public class ClientProxy implements IProxy{
private static List<Item> colorProdividingItemsForRegistering = new ArrayList<Item>(); private static List<Item> colorProdividingItemsForRegistering = new ArrayList<Item>();
private static Map<ItemStack, ModelResourceLocation> modelLocationsForRegistering = new HashMap<ItemStack, ModelResourceLocation>(); private static Map<ItemStack, ModelResourceLocation> modelLocationsForRegistering = new HashMap<ItemStack, ModelResourceLocation>();
private static Map<Item, ResourceLocation[]> modelVariantsForRegistering = new HashMap<Item, ResourceLocation[]>();
private static void countBookletWords(){ private static void countBookletWords(){
bookletWordCount = 0; bookletWordCount = 0;
@ -100,9 +99,6 @@ public class ClientProxy implements IProxy{
for(Map.Entry<ItemStack, ModelResourceLocation> entry : modelLocationsForRegistering.entrySet()){ for(Map.Entry<ItemStack, ModelResourceLocation> entry : modelLocationsForRegistering.entrySet()){
ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue()); ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue());
} }
for(Map.Entry<Item, ResourceLocation[]> entry : modelVariantsForRegistering.entrySet()){
ModelBakery.registerItemVariants(entry.getKey(), entry.getValue());
}
this.registerCustomFluidBlockRenderer(InitFluids.fluidCanolaOil); this.registerCustomFluidBlockRenderer(InitFluids.fluidCanolaOil);
this.registerCustomFluidBlockRenderer(InitFluids.fluidOil); this.registerCustomFluidBlockRenderer(InitFluids.fluidOil);

View file

@ -142,10 +142,10 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
return level*17; return level*17;
} }
else if(level > 15 && level < 31){ 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{ 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; return 0;