diff --git a/.gitignore b/.gitignore index 75508b3..e166c34 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ Workspace/* 1.12.2/src/.DS_Store 5.5.15/ + +.DS_Store diff --git a/1.12.2/build.gradle b/1.12.2/build.gradle index 87c8778..670235c 100644 --- a/1.12.2/build.gradle +++ b/1.12.2/build.gradle @@ -29,7 +29,7 @@ minecraft { // stable_# stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // simply re-run your setup task after changing the mappings to update your workspace. - mappings = "snapshot_20171003" + mappings = "stable_39" // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaConfig.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaConfig.java index 0f89cd1..9f3568f 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaConfig.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaConfig.java @@ -128,6 +128,9 @@ public static class VolcanoSettings { @Config.Comment("How far in should biome filler blocks go? Set to 0 to disable use of filler blocks") public int fillerSize = 2; + + @Config.Comment("How far down should biome meshing start?") + public int biomeStart = 3; } public static class WorldSmeltingOptions { diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaDynamics.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaDynamics.java index ecc9178..d3ead91 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaDynamics.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/LavaDynamics.java @@ -123,7 +123,6 @@ public static void items(RegistryEvent.Register event) { //Register VolcanoBlock Item, cause why not ItemBlock itemblock = new ItemBlock(VolcanoBlock); itemblock.setRegistryName(VolcanoBlock.getRegistryName()); - itemblock.setUnlocalizedName(VolcanoBlock.getUnlocalizedName()); registry.register(itemblock); Item item = Item.getItemFromBlock(VolcanoBlock); proxy.registerItemModels(item, 0, "Inventory"); diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/Volcano.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/Volcano.java index 0e83581..18cad03 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/Volcano.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/Volcano.java @@ -261,7 +261,7 @@ public static WorldGenerator getGenerator(World world, BlockPos pos) { public static boolean hasTileEntity(World world, Chunk chunk){ for(BlockPos pos : chunk.getTileEntityMap().keySet()){ - if(world.getChunkFromBlockCoords(pos).equals(chunk)){ + if(world.getChunk(pos).equals(chunk)){ return true; } } diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/VolcanoBlock.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/VolcanoBlock.java index a525439..35b1f38 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/VolcanoBlock.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/VolcanoBlock.java @@ -20,7 +20,6 @@ public class VolcanoBlock extends Block { public VolcanoBlock() { super(Material.ROCK); this.setRegistryName(new ResourceLocation(Reference.MODID, "VolcanoBlock")); - this.setUnlocalizedName(Reference.MODID + ":VolcanoBlock"); //Needed to receive random ticks this.setTickRandomly(true); } @@ -30,7 +29,7 @@ public void randomTick(World world, BlockPos pos, IBlockState state, Random rand for(EntityPlayer player : world.playerEntities){ System.out.println(pos.getDistance((int)player.posX, (int)player.posY, (int)player.posZ)); if(pos.getDistance((int)player.posX, (int)player.posY, (int)player.posZ) >= LavaConfig.volcano.minimumDistance) { - Volcano.genVolcano(world.getChunkFromBlockCoords(pos), world); + Volcano.genVolcano(world.getChunk(pos), world); } } } @@ -53,7 +52,7 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, } public void forceSpawn(World world, BlockPos pos) { - Volcano.genVolcano(world.getChunkFromBlockCoords(pos), world); + Volcano.genVolcano(world.getChunk(pos), world); } public EnumBlockRenderType getRenderType(IBlockState state) diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/EntityVolcanoArrow.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/EntityVolcanoArrow.java index a53b213..5a54513 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/EntityVolcanoArrow.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/EntityVolcanoArrow.java @@ -1,57 +1,57 @@ -package com.eleksploded.lavadynamics.arrow; - -import com.eleksploded.lavadynamics.LavaDynamics; -import com.eleksploded.lavadynamics.Volcano; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.fml.common.FMLCommonHandler; - -public class EntityVolcanoArrow extends EntityArrow { - - public EntityVolcanoArrow(World world) { - super(world); - } - - public EntityVolcanoArrow(World world, EntityLivingBase shooter) { - super(world, shooter); - } - - @Override - protected ItemStack getArrowStack() { - // TODO Auto-generated method stub - return null; - } - - protected void onHit(RayTraceResult raytraceResultIn) - { - if(shootingEntity == null || !(this.shootingEntity instanceof EntityPlayer)) { - super.onHit(raytraceResultIn); - return; - } - - Entity entity = raytraceResultIn.entityHit; - EntityPlayer player = (EntityPlayer) shootingEntity; - - if(entity == null) { - if(FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile()) != null) { - BlockPos blockpos = raytraceResultIn.getBlockPos(); - world.setBlockState(blockpos, LavaDynamics.VolcanoBlock.getDefaultState()); - Chunk chunk = world.getChunkFromBlockCoords(blockpos); - Volcano.genVolcano(chunk, world); - this.setDead(); - } else { - super.onHit(raytraceResultIn); - } - } else { - super.onHit(raytraceResultIn); - } - } +package com.eleksploded.lavadynamics.arrow; + +import com.eleksploded.lavadynamics.LavaDynamics; +import com.eleksploded.lavadynamics.Volcano; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.fml.common.FMLCommonHandler; + +public class EntityVolcanoArrow extends EntityArrow { + + public EntityVolcanoArrow(World world) { + super(world); + } + + public EntityVolcanoArrow(World world, EntityLivingBase shooter) { + super(world, shooter); + } + + @Override + protected ItemStack getArrowStack() { + // TODO Auto-generated method stub + return null; + } + + protected void onHit(RayTraceResult raytraceResultIn) + { + if(shootingEntity == null || !(this.shootingEntity instanceof EntityPlayer)) { + super.onHit(raytraceResultIn); + return; + } + + Entity entity = raytraceResultIn.entityHit; + EntityPlayer player = (EntityPlayer) shootingEntity; + + if(entity == null) { + if(FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile()) != null) { + BlockPos blockpos = raytraceResultIn.getBlockPos(); + world.setBlockState(blockpos, LavaDynamics.VolcanoBlock.getDefaultState()); + Chunk chunk = world.getChunk(blockpos); + Volcano.genVolcano(chunk, world); + this.setDead(); + } else { + super.onHit(raytraceResultIn); + } + } else { + super.onHit(raytraceResultIn); + } + } } \ No newline at end of file diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/RenderVolcanoArrow.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/RenderVolcanoArrow.java index a3da332..aa9a1d1 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/RenderVolcanoArrow.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/RenderVolcanoArrow.java @@ -1,37 +1,37 @@ -package com.eleksploded.lavadynamics.arrow; - -import com.eleksploded.lavadynamics.Reference; - -import net.minecraft.client.renderer.entity.Render; -import net.minecraft.client.renderer.entity.RenderArrow; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.client.registry.IRenderFactory; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class RenderVolcanoArrow extends RenderArrow -{ - public static final ResourceLocation texture = new ResourceLocation(Reference.MODID, "textures/volcanoarrow.png"); - - public RenderVolcanoArrow(RenderManager manager) - { - super(manager); - } - - @Override - protected ResourceLocation getEntityTexture(EntityVolcanoArrow entity) { - return texture; - } - - public static class VolcanoArrowRenderFactory implements IRenderFactory { - - public static final VolcanoArrowRenderFactory INSTANCE = new VolcanoArrowRenderFactory(); - - @Override - public Render createRenderFor(RenderManager manager) { - return new RenderVolcanoArrow(manager); - } - } +package com.eleksploded.lavadynamics.arrow; + +import com.eleksploded.lavadynamics.Reference; + +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderArrow; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.client.registry.IRenderFactory; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderVolcanoArrow extends RenderArrow +{ + public static final ResourceLocation texture = new ResourceLocation(Reference.MODID, "textures/volcanoarrow.png"); + + public RenderVolcanoArrow(RenderManager manager) + { + super(manager); + } + + @Override + protected ResourceLocation getEntityTexture(EntityVolcanoArrow entity) { + return texture; + } + + public static class VolcanoArrowRenderFactory implements IRenderFactory { + + public static final VolcanoArrowRenderFactory INSTANCE = new VolcanoArrowRenderFactory(); + + @Override + public Render createRenderFor(RenderManager manager) { + return new RenderVolcanoArrow(manager); + } + } } \ No newline at end of file diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/VolcanoArrow.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/VolcanoArrow.java index 7c541a8..3c10768 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/VolcanoArrow.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/arrow/VolcanoArrow.java @@ -1,25 +1,24 @@ -package com.eleksploded.lavadynamics.arrow; - -import com.eleksploded.lavadynamics.Reference; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.item.ItemArrow; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -public class VolcanoArrow extends ItemArrow { - - public VolcanoArrow() { - this.setRegistryName(Reference.MODID, "VolcanoArrow"); - this.setUnlocalizedName(this.getRegistryName().toString()); - this.setCreativeTab(CreativeTabs.MISC); - } - - public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter) - { - EntityVolcanoArrow arrow = new EntityVolcanoArrow(worldIn, shooter); - return arrow; - } -} +package com.eleksploded.lavadynamics.arrow; + +import com.eleksploded.lavadynamics.Reference; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.item.ItemArrow; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class VolcanoArrow extends ItemArrow { + + public VolcanoArrow() { + this.setRegistryName(Reference.MODID, "VolcanoArrow"); + this.setCreativeTab(CreativeTabs.MISC); + } + + public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter) + { + EntityVolcanoArrow arrow = new EntityVolcanoArrow(worldIn, shooter); + return arrow; + } +} diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedAddCommand.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedAddCommand.java index 2577209..1b901b0 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedAddCommand.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedAddCommand.java @@ -28,7 +28,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args } try{ - StorageManager.getCheckedStorage(sender.getEntityWorld().provider.getDimension()).addChecked(sender.getEntityWorld().getChunkFromChunkCoords(Integer.valueOf(args[0]), Integer.valueOf(args[1]))); + StorageManager.getCheckedStorage(sender.getEntityWorld().provider.getDimension()).addChecked(sender.getEntityWorld().getChunk(Integer.valueOf(args[0]), Integer.valueOf(args[1]))); sender.sendMessage(new TextComponentString("Added chunk [" + Integer.valueOf(args[0]) + "," + Integer.valueOf(args[1]) + "]")); } catch(NumberFormatException e){ throw new WrongUsageException(getUsage(sender), new Object[0]); diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedChunkCommand.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedChunkCommand.java index 58d1aa9..f9acd01 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedChunkCommand.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/CheckedChunkCommand.java @@ -23,7 +23,7 @@ public String getUsage(ICommandSender sender) { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - Chunk chunk = sender.getEntityWorld().getChunkFromBlockCoords(sender.getPosition()); + Chunk chunk = sender.getEntityWorld().getChunk(sender.getPosition()); if(StorageManager.getCheckedStorage(sender.getEntityWorld().provider.getDimension()).isChecked(chunk)){ sender.sendMessage(new TextComponentString("Chunk [" + chunk.x + "," + chunk.z + "] has been checked")); } else { diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/ForcePostGenEffect.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/ForcePostGenEffect.java index a85a237..a820298 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/ForcePostGenEffect.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/ForcePostGenEffect.java @@ -32,7 +32,7 @@ public String getUsage(ICommandSender sender) { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - Chunk chunk = sender.getEntityWorld().getChunkFromBlockCoords(sender.getPosition()); + Chunk chunk = sender.getEntityWorld().getChunk(sender.getPosition()); if(!StorageManager.getVolcanoStorage(sender.getEntityWorld().provider.getDimension()).isVolcano(chunk)){ sender.sendMessage(new TextComponentString("Chunk does not contain a volcano. Please run this in a chunk that contains a volcamo.")); diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/VolcanoCommand.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/VolcanoCommand.java index 022e65b..4868ec1 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/VolcanoCommand.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/commands/VolcanoCommand.java @@ -29,7 +29,7 @@ public String getUsage(ICommandSender sender) { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - Chunk chunk = sender.getEntityWorld().getChunkFromBlockCoords(sender.getPosition()); + Chunk chunk = sender.getEntityWorld().getChunk(sender.getPosition()); boolean bypass; if(args.length == 1){ try { diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/generators/ConeVolcanoGen.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/generators/ConeVolcanoGen.java index 3331ee3..556a43e 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/generators/ConeVolcanoGen.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/generators/ConeVolcanoGen.java @@ -141,8 +141,12 @@ public void circle(int radius, World world, BlockPos fill1, int j) { for(float i1 = 0; i1 < radius; i1 += 0.5) { for(float j1 = 0; j1 < 2 * Math.PI * i1; j1 += 0.5) { - if(LavaConfig.volcano.useBiome && i1 == radius-.5) { - setBlockWithBiomeTop(world,new BlockPos((int)Math.floor(x1 + Math.sin(j1) * i1), y1, (int)Math.floor(z1 + Math.cos(j1) * i1))); + if(LavaConfig.volcano.useBiome && i1 == radius-.5 && radius > LavaConfig.volcano.biomeStart) { + if(radius == LavaConfig.volcano.biomeStart && world.rand.nextBoolean()) { + setBlockWithOre(world,new BlockPos((int)Math.floor(x1 + Math.sin(j1) * i1), y1, (int)Math.floor(z1 + Math.cos(j1) * i1)), false); + } else { + setBlockWithBiomeTop(world,new BlockPos((int)Math.floor(x1 + Math.sin(j1) * i1), y1, (int)Math.floor(z1 + Math.cos(j1) * i1))); + } } else { setBlockWithOre(world,new BlockPos((int)Math.floor(x1 + Math.sin(j1) * i1), y1, (int)Math.floor(z1 + Math.cos(j1) * i1)), LavaConfig.volcano.useBiome && i1 >= (radius-((LavaConfig.volcano.fillerSize) + .5F))); } diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/postgen/RunEffects.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/postgen/RunEffects.java index 7d0cf4d..df439af 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/postgen/RunEffects.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/postgen/RunEffects.java @@ -3,6 +3,7 @@ import java.util.Random; import com.eleksploded.lavadynamics.LavaConfig; +import com.eleksploded.lavadynamics.Reference; import com.eleksploded.lavadynamics.storage.StorageManager; import com.eleksploded.lavadynamics.storage.VolcanoStorage; @@ -10,8 +11,9 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent; +import net.minecraftforge.fml.relauncher.Side; -@Mod.EventBusSubscriber +@Mod.EventBusSubscriber(modid = Reference.MODID, value = Side.SERVER) public class RunEffects { static int timer = 0; @@ -29,8 +31,9 @@ public static void load(WorldTickEvent event){ if(rand.nextInt(999)+1 <= LavaConfig.postgen.chance){ VolcanoStorage storage = StorageManager.getVolcanoStorage(event.world.provider.getDimension()); if(storage != null){ - if(storage.getList().size() != 0){ - Chunk chunk = storage.getList().get(rand.nextInt(storage.getList().size())); + int num = storage.getNum(); + if(num != 0){ + Chunk chunk = storage.get(rand.nextInt(num)+1, event.world); PostGenEffectRegistry.runEffect(chunk, storage.getTop(chunk)); timer = (int)Math.floor(LavaConfig.postgen.effectTime * 1200); } diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/CheckedStorage.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/CheckedStorage.java index 83b65d2..cca70a9 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/CheckedStorage.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/CheckedStorage.java @@ -1,15 +1,18 @@ package com.eleksploded.lavadynamics.storage; +import java.io.BufferedReader; import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; +import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import org.apache.commons.io.FileUtils; + +import com.google.common.io.Files; + import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.event.world.WorldEvent; public class CheckedStorage { List chunks = new CopyOnWriteArrayList(); @@ -18,6 +21,15 @@ public class CheckedStorage { public CheckedStorage(int dimIDin){ dimID = dimIDin; + + if(!getFile().exists()) { + try { + getFile().createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error creating CheckedStorage. Please report this on the github page."); + } + } } File getFile() { @@ -31,56 +43,33 @@ File getFile() { return new File(tmp); } - public void load(WorldEvent.Load event){ - if(event.getWorld().provider.getDimension() != dimID){ return; } - - try{ - if(getFile().exists()){ - Path path = getFile().toPath(); - for(String in : Files.readAllLines(path)){ - String[] tmp = in.split("\\|"); - chunks.add(event.getWorld().getChunkFromChunkCoords(Integer.valueOf(tmp[0]), Integer.valueOf(tmp[1]))); - } - } else { - getFile().createNewFile(); - } - } catch(Exception e){ - - e.printStackTrace(); - throw new RuntimeException("Error loading CheckedStorage. Please report this on the github page."); - } - } - - public void save(WorldEvent.Save event){ - if(event.getWorld().provider.getDimension() != dimID){ return; } - - try{ - if(getFile().exists()){ - Path path = getFile().toPath(); - List list = new ArrayList(); - for(Chunk chunk : chunks){ - String tmp = chunk.x + "|" + chunk.z; - if(!list.contains(tmp)){ - list.add(tmp); - } - getFile().delete(); - getFile().createNewFile(); - Files.write(path, list); + public boolean isChecked(Chunk c) { + try { + String chunk = c.x + "|" + c.z; + BufferedReader r = Files.newReader(getFile(), StandardCharsets.UTF_8); + String line; + while((line = r.readLine()) != null) { + if(line.contentEquals(chunk)) { + return true; } } - } catch(Exception e){ + return false; + } catch (IOException e) { e.printStackTrace(); - throw new RuntimeException("Error saving CheckedStorage. Please report this on the github page."); + throw new RuntimeException("Error checking CheckedStorage. Please report this on the github page."); } } - public boolean isChecked(Chunk chunk) { - return chunks.contains(chunk); - } - public void addChecked(Chunk chunk) { if(!chunks.contains(chunk)) { - chunks.add(chunk); + String toWrite = "\r\n" + chunk.x + "|" + chunk.z; + + try { + FileUtils.writeStringToFile(getFile(), toWrite, StandardCharsets.UTF_8, true); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error creating CheckedStorage. Please report this on the github page."); + } } } } \ No newline at end of file diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/StorageManager.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/StorageManager.java index 5cc32d6..6e5784d 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/StorageManager.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/StorageManager.java @@ -8,9 +8,6 @@ import com.eleksploded.lavadynamics.LavaConfig; import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class StorageManager { static Map checked = new HashMap(); @@ -32,34 +29,4 @@ public static void init(){ } } } - - @SubscribeEvent(priority = EventPriority.HIGHEST) - static void load(WorldEvent.Load event){ - - if(event.getWorld().isRemote) { - return; - } - - for(CheckedStorage store : checked.values()) { - store.load(event); - } - for(VolcanoStorage vol : volcano.values()){ - vol.load(event); - } - } - - @SubscribeEvent - static void save(WorldEvent.Save event){ - - if(event.getWorld().isRemote) { - return; - } - - for(CheckedStorage store : checked.values()) { - store.save(event); - } - for(VolcanoStorage vol : volcano.values()){ - vol.save(event); - } - } } diff --git a/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/VolcanoStorage.java b/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/VolcanoStorage.java index dcefbc0..7cfa657 100644 --- a/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/VolcanoStorage.java +++ b/1.12.2/src/main/java/com/eleksploded/lavadynamics/storage/VolcanoStorage.java @@ -1,29 +1,37 @@ package com.eleksploded.lavadynamics.storage; +import java.io.BufferedReader; import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import javax.annotation.Nullable; + +import org.apache.commons.io.FileUtils; import com.eleksploded.lavadynamics.LavaConfig; +import com.google.common.io.Files; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.event.world.WorldEvent; public class VolcanoStorage { - List chunks = new CopyOnWriteArrayList(); - Map tops = new HashMap(); String fileName = "LD_VolcanoStorage"; int dimID; - + public VolcanoStorage(int dimid){ dimID = dimid; + + if(!getFile().exists()) { + try { + getFile().createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error creating VolcanoStorage. Please report this on the github page."); + } + } } File getFile() { @@ -37,95 +45,131 @@ File getFile() { return new File(tmp); } - public void load(WorldEvent.Load event){ - if(event.getWorld().provider.getDimension() != dimID){ return; } - - try{ - if(getFile().exists()){ - Path path = getFile().toPath(); - for(String in : Files.readAllLines(path)){ - String[] tmp = in.split("\\|"); - Chunk chunk = event.getWorld().getChunkFromChunkCoords(Integer.valueOf(tmp[0]), Integer.valueOf(tmp[1])); - chunks.add(chunk); - tops.put(chunk, Integer.valueOf(tmp[2])); + + + public boolean isVolcano(Chunk c) { + try { + String chunk = c.x + "|" + c.z + "|"; + BufferedReader r = Files.newReader(getFile(), StandardCharsets.UTF_8); + String line; + while((line = r.readLine()) != null) { + if(line.startsWith(chunk)) { + return true; } - } else { - getFile().createNewFile(); } - } catch(Exception e){ + return false; + } catch (IOException e) { e.printStackTrace(); - throw new RuntimeException("Error loading VolcanoStorage. Please report this on the github page."); + throw new RuntimeException("Error checking VolcanoStorage. Please report this on the github page."); } } - - public void save(WorldEvent.Save event){ - if(event.getWorld().provider.getDimension() != dimID){ return; } - - try{ - if(getFile().exists()){ - Path path = getFile().toPath(); - List list = new ArrayList(); - for(Chunk chunk : chunks){ - String tmp = chunk.x + "|" + chunk.z + "|" + tops.get(chunk); - if(!list.contains(tmp)){ - list.add(tmp); + + @SuppressWarnings("null") + @Nullable + public int getTop(Chunk c){ + try { + String chunk = c.x + "|" + c.z + "|"; + BufferedReader r = Files.newReader(getFile(), StandardCharsets.UTF_8); + String line; + while((line = r.readLine()) != null) { + if(line.startsWith(chunk)) { + String s[] = line.split("\\|"); + try { + return Integer.valueOf(s[2]); + } catch(NumberFormatException e) { + e.printStackTrace(); + throw new RuntimeException("Error reading VolcanoStorage. Please report this on the github page."); } - getFile().delete(); - getFile().createNewFile(); - Files.write(path, list); } } - } catch(Exception e){ + return (Integer) null; + } catch (IOException e) { e.printStackTrace(); - throw new RuntimeException("Error saving VolcanoStorage. Please report this on the github page."); - } - } - - public boolean isVolcano(Chunk chunk) { - if(!chunks.isEmpty()){ - return chunks.contains(chunk); - } else { - return false; + throw new RuntimeException("Error checking VolcanoStorage. Please report this on the github page."); } } - - public int getTop(Chunk chunk){ - if(tops.containsKey(chunk)){ - return tops.get(chunk); - } else { - return 0; + + public void addVolcano(Chunk chunk, int top) { + String toWrite = "\r\n" + chunk.x + "|" + chunk.z + "|" + top; + + try { + FileUtils.writeStringToFile(getFile(), toWrite, StandardCharsets.UTF_8, true); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error creating VolcanoStorage. Please report this on the github page."); } } - - public void addVolcano(Chunk chunk, int top) { - chunks.add(chunk); - tops.put(chunk, top); - } - + public boolean isVolcanoInRange(Chunk chunk){ int xIn = (chunk.getPos().getXEnd() - chunk.getPos().getXStart())/2 + chunk.getPos().getXStart(); int zIn = (chunk.getPos().getZEnd() - chunk.getPos().getZStart())/2 + chunk.getPos().getZStart(); - + if(!LavaConfig.volcano.spawnChunks) { BlockPos spawnpos = new BlockPos(chunk.getWorld().getSpawnPoint().getX(), 70, chunk.getWorld().getSpawnPoint().getZ()); if(spawnpos.getDistance(xIn, 70, zIn) <= LavaConfig.volcano.spawnDistance) { return true; } } - - for(Chunk chunkIn : chunks){ - int x = (chunkIn.getPos().getXEnd() - chunkIn.getPos().getXStart())/2 + chunkIn.getPos().getXStart(); - int z = (chunkIn.getPos().getZEnd() - chunkIn.getPos().getZStart())/2 + chunkIn.getPos().getZStart(); - BlockPos pos = new BlockPos(x,70,z); - - if(pos.getDistance(xIn, 70, zIn) <= LavaConfig.volcano.distance){ - return true; + + try { + BufferedReader r = Files.newReader(getFile(), StandardCharsets.UTF_8); + String line; + while((line = r.readLine()) != null) { + String s[] = line.split("\\|"); + Chunk chunkIn; + try { + chunkIn = chunk.getWorld().getChunk(Integer.valueOf(s[0]), Integer.valueOf(s[1])); + } catch(NumberFormatException e) { + e.printStackTrace(); + throw new RuntimeException("Error checking VolcanoStorage. Please report this on the github page."); + } + + int x = (chunkIn.getPos().getXEnd() - chunkIn.getPos().getXStart())/2 + chunkIn.getPos().getXStart(); + int z = (chunkIn.getPos().getZEnd() - chunkIn.getPos().getZStart())/2 + chunkIn.getPos().getZStart(); + BlockPos pos = new BlockPos(x,70,z); + + if(pos.getDistance(xIn, 70, zIn) <= LavaConfig.volcano.distance){ + return true; + } } + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error checking VolcanoStorage. Please report this on the github page."); } return false; } - - public List getList() { - return chunks; + + public Chunk get(int n, World world) { + try { + String line = ""; + BufferedReader r = Files.newReader(getFile(), StandardCharsets.UTF_8); + for (int i = 0; i < n; i++) r.readLine(); + line = r.readLine(); + + String s[] = line.split("\\|"); + try { + return world.getChunk(Integer.valueOf(s[0]), Integer.valueOf(s[1])); + } catch(NumberFormatException e) { + e.printStackTrace(); + throw new RuntimeException("Error checking VolcanoStorage. Please report this on the github page."); + } + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error checking VolcanoStorage. Please report this on the github page."); + } + } + + public int getNum() { + try { + BufferedReader r = Files.newReader(getFile(), StandardCharsets.UTF_8); + int lines = 0; + while (r.readLine() != null) lines++; + r.close(); + return lines; + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error reading VolcanoStorage. Please report this on the github page."); + } + } }