diff --git a/StevenDimDoors/mod_pocketDim/CraftingManager.java b/StevenDimDoors/mod_pocketDim/CraftingManager.java new file mode 100644 index 0000000..065ae05 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/CraftingManager.java @@ -0,0 +1,135 @@ +package StevenDimDoors.mod_pocketDim; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.registry.GameRegistry; +import static StevenDimDoors.mod_pocketDim.mod_pocketDim.*; + +public class CraftingManager +{ + + public static void registerRecipies() + { + Item coreCraftingItem = Item.enderPearl; + + if(properties.enableServerMode) + { + coreCraftingItem = itemWorldThread; + } + if (properties.CraftingDimensionalDoorAllowed) + { + GameRegistry.addRecipe(new ItemStack(itemDimDoor, 1), new Object[] + { + " ", "yxy", " ", 'x', coreCraftingItem, 'y', Item.doorIron + }); + + GameRegistry.addRecipe(new ItemStack(itemDimDoor, 1), new Object[] + { + " ", "yxy", " ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorIron + }); + } + if(properties.CraftingUnstableDoorAllowed) + { + GameRegistry.addRecipe(new ItemStack(itemChaosDoor, 1), new Object[] + { + " ", "yxy", " ", 'x', Item.eyeOfEnder, 'y', mod_pocketDim.itemDimDoor + }); + } + if(properties.CraftingWarpDoorAllowed) + { + GameRegistry.addRecipe(new ItemStack(itemExitDoor, 1), new Object[] + { + " ", "yxy", " ", 'x', coreCraftingItem, 'y', Item.doorWood + }); + + GameRegistry.addRecipe(new ItemStack(itemExitDoor, 1), new Object[] + { + " ", "yxy", " ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorWood + }); + } + if(properties.CraftingTransTrapdoorAllowed) + { + GameRegistry.addRecipe(new ItemStack(transTrapdoor, 1), new Object[] + { + " y ", " x ", " y ", 'x', coreCraftingItem, 'y', Block.trapdoor + }); + + GameRegistry.addRecipe(new ItemStack(transTrapdoor, 1), new Object[] + { + " y ", " x ", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Block.trapdoor + }); + } + if(properties.CraftingRiftSignatureAllowed) + { + GameRegistry.addRecipe(new ItemStack(itemLinkSignature, 1), new Object[] + { + " y ", "yxy", " y ", 'x', coreCraftingItem, 'y', Item.ingotIron + }); + + GameRegistry.addRecipe(new ItemStack(itemLinkSignature, 1), new Object[] + { + " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron + }); + } + + if(properties.CraftingRiftRemoverAllowed) + { + GameRegistry.addRecipe(new ItemStack(itemRiftRemover, 1), new Object[] + { + " y ", "yxy", " y ", 'x', coreCraftingItem, 'y', Item.ingotGold + }); + GameRegistry.addRecipe(new ItemStack(itemRiftRemover, 1), new Object[] + { + "yyy", "yxy", "yyy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotGold + }); + } + + if (properties.CraftingRiftBladeAllowed) + { + + GameRegistry.addRecipe(new ItemStack(itemRiftBlade, 1), new Object[] + { + " x ", " x ", " y ", 'x', coreCraftingItem, 'y',mod_pocketDim.itemRiftRemover + }); + } + + if (properties.CraftingStableFabricAllowed) + { + GameRegistry.addRecipe(new ItemStack(itemStableFabric, 1), new Object[] + { + " y ", "yxy", " y ", 'x', coreCraftingItem, 'y', mod_pocketDim.itemWorldThread + }); + } + + if (properties.CraftingStabilizedRiftSignatureAllowed) + { + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStabilizedLinkSignature,1), new Object[] + { + " y ", "yxy", " y ", 'x', mod_pocketDim.itemLinkSignature, 'y', mod_pocketDim.itemStableFabric + }); + } + if (properties.CraftingGoldDimDoorAllowed) + { + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldDimDoor,1), new Object[] + { + " x ", " y ", " x ", 'x', mod_pocketDim.itemGoldDoor, 'y', Item.eyeOfEnder + }); + } + if (properties.CraftingGoldDoorAllowed) + { + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldDoor,1), new Object[] + { + "yy ", "yy ", "yy ", 'y', Item.ingotGold + }); + + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldDoor,1), new Object[] + { + " yy", " yy", " yy", 'y', Item.ingotGold + }); + } + + } + + +} diff --git a/StevenDimDoors/mod_pocketDim/DDProperties.java b/StevenDimDoors/mod_pocketDim/DDProperties.java index 18e3218..182dde2 100644 --- a/StevenDimDoors/mod_pocketDim/DDProperties.java +++ b/StevenDimDoors/mod_pocketDim/DDProperties.java @@ -43,6 +43,8 @@ public class DDProperties public final int DimensionalDoorItemID; public final int UnstableDoorItemID; public final int WarpDoorItemID; + public final int ItemWorldThreadID; + /** * Other IDs @@ -91,6 +93,7 @@ public class DDProperties * Other Flags */ + public final boolean enableServerMode; public final boolean WorldRiftGenerationEnabled; public final boolean RiftSpreadEnabled; public final boolean RiftGriefingEnabled; @@ -100,6 +103,7 @@ public class DDProperties public final boolean LimboReturnsInventoryEnabled; public final boolean DoorRenderingEnabled; public final boolean TNFREAKINGT_Enabled; + /** * Other @@ -112,11 +116,13 @@ public class DDProperties public final int LimboReturnRange; public final String CustomSchematicDirectory; + //Singleton instance private static DDProperties instance = null; //Path for custom dungeons within configuration directory private final String CUSTOM_SCHEMATIC_SUBDIRECTORY = "/DimDoors_Custom_schematics"; //Names of categories + private final String CATEGORY_SERVERMODE = "server mode"; private final String CATEGORY_CRAFTING = "crafting"; private final String CATEGORY_ENTITY = "entity"; private final String CATEGORY_DIMENSION = "dimension"; @@ -178,6 +184,11 @@ public class DDProperties "Weighs the chance that a block will not be TNT. Must be greater than or equal to 0. " + "EXPLOSIONS must be set to true for this to have any effect.").getInt(); + enableServerMode = config.get(CATEGORY_SERVERMODE, "Server Mode", false, + "Enables servermode, changing all crafting recipies to require stabilized fabric. " + + "Stabilized fabric, in turn, requires the item World Thread, which is not craftable or obtainable at all. "+ + "It is up to the server manager on how to distribute it.").getBoolean(false); + DoorRenderEntityID=config.get(CATEGORY_ENTITY, "Door Render Entity ID", 89).getInt(); MonolithEntityID = config.get(CATEGORY_ENTITY, "Monolith Entity ID", 125).getInt(); @@ -201,7 +212,8 @@ public class DDProperties StabilizedRiftSignatureItemID = config.getItem("Stabilized Rift Signature Item ID", 5677).getInt(); GoldDoorItemID = config.getItem("Gold Door Item ID", 5678).getInt(); GoldDimDoorItemID = config.getItem("Gold Dim Door Item ID", 5679).getInt(); - + ItemWorldThreadID = config.getItem("World Thread Item ID", 5680).getInt(); + LimboBlockID = config.getTerrainBlock("World Generation Block IDs - must be less than 256", "Limbo Block ID", 217, "Blocks used for the terrain in Limbo").getInt(); PermaFabricBlockID = config.getTerrainBlock("World Generation Block IDs - must be less than 256", diff --git a/StevenDimDoors/mod_pocketDim/DimData.java b/StevenDimDoors/mod_pocketDim/DimData.java index 7bf4ed0..7648161 100644 --- a/StevenDimDoors/mod_pocketDim/DimData.java +++ b/StevenDimDoors/mod_pocketDim/DimData.java @@ -10,7 +10,7 @@ import java.util.Iterator; import net.minecraft.util.MathHelper; import net.minecraft.world.World; - +@Deprecated public class DimData implements Serializable { public int dimID; diff --git a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java index e8ec50c..021f679 100644 --- a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java +++ b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java @@ -9,6 +9,7 @@ import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; +@Deprecated public class DungeonGenerator implements Serializable { //This static field is hax so that I don't have to add an instance field to DungeonGenerator to support DungeonType. diff --git a/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 37201ea..26fe687 100644 --- a/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -1,14 +1,12 @@ package StevenDimDoors.mod_pocketDim; import paulscode.sound.SoundSystem; -import net.minecraft.client.audio.SoundPool; import net.minecraft.client.audio.SoundPoolEntry; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; -import net.minecraftforge.client.event.sound.PlaySoundEffectEvent; import net.minecraftforge.client.event.sound.SoundLoadEvent; import net.minecraftforge.event.EventPriority; import net.minecraftforge.event.ForgeSubscribe; diff --git a/StevenDimDoors/mod_pocketDim/LinkData.java b/StevenDimDoors/mod_pocketDim/LinkData.java index 6213029..04a0bd6 100644 --- a/StevenDimDoors/mod_pocketDim/LinkData.java +++ b/StevenDimDoors/mod_pocketDim/LinkData.java @@ -1,7 +1,7 @@ package StevenDimDoors.mod_pocketDim; import java.io.Serializable; - +@Deprecated public class LinkData implements Serializable { diff --git a/StevenDimDoors/mod_pocketDim/core/DimLink.java b/StevenDimDoors/mod_pocketDim/core/DimLink.java index 8c11bb7..9f1369d 100644 --- a/StevenDimDoors/mod_pocketDim/core/DimLink.java +++ b/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -4,7 +4,7 @@ import java.util.LinkedList; import java.util.List; import StevenDimDoors.mod_pocketDim.util.Point4D; - +@Deprecated public abstract class DimLink { protected Point4D source; diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 79b1130..63eec3b 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -372,6 +372,18 @@ public class PocketManager } } } + for(Integer dimID : dimensionIDBlackList) + { + try + { + DimensionManager.unregisterDimension(dimID); + } + catch (Exception e) + { + System.err.println("An unexpected error occurred while unregistering blacklisted dim #" + dimID + ":"); + e.printStackTrace(); + } + } } /** @@ -384,7 +396,8 @@ public class PocketManager File saveDir = DimensionManager.getCurrentSaveRootDirectory(); if (saveDir != null) { - // Load and register blacklisted dimension IDs + //Try to import data from old DD versions + //TODO - remove this code in a few versions File oldSaveData = new File(saveDir+"/DimensionalDoorsData"); if(oldSaveData.exists()) { @@ -395,7 +408,6 @@ public class PocketManager oldSaveData.delete(); System.out.println("Import Succesful!"); - } catch (Exception e) { @@ -436,7 +448,7 @@ public class PocketManager try { System.out.println("Writing Dimensional Doors save data..."); - if ( DDSaveHandler.saveAll(dimensionData.values()) ) + if ( DDSaveHandler.saveAll(dimensionData.values(),dimensionIDBlackList) ) { System.out.println("Saved successfully!"); } @@ -648,6 +660,15 @@ public class PocketManager return dimensionData.containsKey(dimensionID); } + public static void createAndRegisterBlacklist(List blacklist) + { + //TODO - create a special blacklist provider + for(Integer dimID : blacklist) + { + PocketManager.dimensionIDBlackList.add(dimID); + DimensionManager.registerDimension(dimID, DDProperties.instance().PocketProviderID); + } + } public static void readPacket(DataInputStream input) throws IOException { if (isLoaded) diff --git a/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java b/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java index 825f13e..1e368ec 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java @@ -1,17 +1,23 @@ package StevenDimDoors.mod_pocketDim.helpers; +import java.io.File; import java.util.List; import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.LoadingCallback; import net.minecraftforge.common.ForgeChunkManager.Ticket; import StevenDimDoors.mod_pocketDim.IChunkLoader; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoorGold; import com.google.common.collect.Lists; +import cpw.mods.fml.common.event.FMLServerStartingEvent; + public class ChunkLoaderHelper implements LoadingCallback { @@ -29,4 +35,25 @@ public class ChunkLoaderHelper implements LoadingCallback } } + + public static void loadChunkForcedWorlds(FMLServerStartingEvent event) + { + for(NewDimData data : PocketManager.getDimensions()) + { + if(data.isPocketDimension()) + { + String chunkDir = DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoors/pocketDimID" + data.id(); + + File file = new File(chunkDir); + + if(file.exists()) + { + if(ForgeChunkManager.savedWorldHasForcedChunkTickets(file)) + { + PocketManager.loadDimension(data.id()); + } + } + } + } + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/ItemWorldThread.java b/StevenDimDoors/mod_pocketDim/items/ItemWorldThread.java new file mode 100644 index 0000000..0f5a10e --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/items/ItemWorldThread.java @@ -0,0 +1,19 @@ +package StevenDimDoors.mod_pocketDim.items; + +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.item.Item; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; + +public class ItemWorldThread extends Item +{ + public ItemWorldThread(int itemID) + { + super(itemID); + this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + } + + public void registerIcons(IconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); + } +} diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index bb9d173..570b2b1 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -44,6 +44,7 @@ import StevenDimDoors.mod_pocketDim.items.ItemStabilizedRiftSignature; import StevenDimDoors.mod_pocketDim.items.ItemStableFabric; import StevenDimDoors.mod_pocketDim.items.ItemUnstableDoor; import StevenDimDoors.mod_pocketDim.items.ItemWarpDoor; +import StevenDimDoors.mod_pocketDim.items.ItemWorldThread; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDim.ticking.LimboDecay; @@ -117,6 +118,8 @@ public class mod_pocketDim public static Item itemGoldDimDoor; public static Item itemGoldDoor; + public static Item itemWorldThread; + public static Item itemRiftBlade; public static Item itemDimDoor; public static Item itemExitDoor; @@ -201,7 +204,9 @@ public class mod_pocketDim itemChaosDoor = (new ItemUnstableDoor(properties.UnstableDoorItemID, Material.iron)).setUnlocalizedName("itemChaosDoor"); itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID, EnumToolMaterial.GOLD, properties)).setUnlocalizedName("ItemRiftBlade"); itemStabilizedLinkSignature = (new ItemStabilizedRiftSignature(properties.StabilizedRiftSignatureItemID)).setUnlocalizedName("itemStabilizedRiftSig"); + itemWorldThread = (new ItemWorldThread(properties.ItemWorldThreadID)).setUnlocalizedName("itemWorldThread"); + mod_pocketDim.limboBiome= (new BiomeGenLimbo(properties.LimboBiomeID)); mod_pocketDim.pocketBiome= (new BiomeGenPocket(properties.PocketBiomeID)); @@ -246,6 +251,8 @@ public class mod_pocketDim LanguageRegistry.addName(itemChaosDoor , "Unstable Door"); LanguageRegistry.addName(itemDimDoor, "Dimensional Door"); LanguageRegistry.addName(itemRiftBlade , "Rift Blade"); + LanguageRegistry.addName(itemWorldThread, "World Thread"); + /** * Add names for multiblock inventory item @@ -266,120 +273,8 @@ public class mod_pocketDim EntityList.entityEggs.put(properties.MonolithEntityID, new EntityEggInfo(properties.MonolithEntityID, 0, 0xffffff)); LanguageRegistry.instance().addStringLocalization("entity.DimDoors.Obelisk.name", "Monolith"); - //GameRegistry.addBiome(this.limboBiome); - //GameRegistry.addBiome(this.pocketBiome); - if (properties.CraftingDimensionalDoorAllowed) - { - GameRegistry.addRecipe(new ItemStack(itemDimDoor, 1), new Object[] - { - " ", "yxy", " ", 'x', Item.enderPearl, 'y', Item.doorIron - }); - - GameRegistry.addRecipe(new ItemStack(itemDimDoor, 1), new Object[] - { - " ", "yxy", " ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorIron - }); - } - if(properties.CraftingUnstableDoorAllowed) - { - GameRegistry.addRecipe(new ItemStack(itemChaosDoor, 1), new Object[] - { - " ", "yxy", " ", 'x', Item.eyeOfEnder, 'y', mod_pocketDim.itemDimDoor - }); - } - if(properties.CraftingWarpDoorAllowed) - { - GameRegistry.addRecipe(new ItemStack(itemExitDoor, 1), new Object[] - { - " ", "yxy", " ", 'x', Item.enderPearl, 'y', Item.doorWood - }); - - GameRegistry.addRecipe(new ItemStack(itemExitDoor, 1), new Object[] - { - " ", "yxy", " ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorWood - }); - } - if(properties.CraftingTransTrapdoorAllowed) - { - GameRegistry.addRecipe(new ItemStack(transTrapdoor, 1), new Object[] - { - " y ", " x ", " y ", 'x', Item.enderPearl, 'y', Block.trapdoor - }); - - GameRegistry.addRecipe(new ItemStack(transTrapdoor, 1), new Object[] - { - " y ", " x ", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Block.trapdoor - }); - } - if(properties.CraftingRiftSignatureAllowed) - { - GameRegistry.addRecipe(new ItemStack(itemLinkSignature, 1), new Object[] - { - " y ", "yxy", " y ", 'x', Item.enderPearl, 'y', Item.ingotIron - }); - - GameRegistry.addRecipe(new ItemStack(itemLinkSignature, 1), new Object[] - { - " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron - }); - } - - if(properties.CraftingRiftRemoverAllowed) - { - GameRegistry.addRecipe(new ItemStack(itemRiftRemover, 1), new Object[] - { - " y ", "yxy", " y ", 'x', Item.enderPearl, 'y', Item.ingotGold - }); - GameRegistry.addRecipe(new ItemStack(itemRiftRemover, 1), new Object[] - { - "yyy", "yxy", "yyy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotGold - }); - } - - if (properties.CraftingRiftBladeAllowed) - { - - GameRegistry.addRecipe(new ItemStack(itemRiftBlade, 1), new Object[] - { - " x ", " x ", " y ", 'x', Item.enderPearl, 'y',mod_pocketDim.itemRiftRemover - }); - } - - if (properties.CraftingStableFabricAllowed) - { - GameRegistry.addRecipe(new ItemStack(itemStableFabric, 4), new Object[] - { - " y ", "yxy", " y ", 'x', Item.enderPearl, 'y', mod_pocketDim.blockDimWall - }); - } - - if (properties.CraftingStabilizedRiftSignatureAllowed) - { - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStabilizedLinkSignature,1), new Object[] - { - " y ", "yxy", " y ", 'x', mod_pocketDim.itemLinkSignature, 'y', mod_pocketDim.itemStableFabric - }); - } - if (properties.CraftingGoldDimDoorAllowed) - { - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldDimDoor,1), new Object[] - { - " x ", " y ", " x ", 'x', mod_pocketDim.itemGoldDoor, 'y', Item.eyeOfEnder - }); - } - if (properties.CraftingGoldDoorAllowed) - { - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldDoor,1), new Object[] - { - "yy ", "yy ", "yy ", 'y', Item.ingotGold - }); - - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldDoor,1), new Object[] - { - " yy", " yy", " yy", 'y', Item.ingotGold - }); - } + CraftingManager.registerRecipies(); DungeonHelper.initialize(); proxy.loadTextures(); @@ -424,5 +319,7 @@ public class mod_pocketDim CommandCreatePocket.instance().register(event); CommandTeleportPlayer.instance().register(event); + + ChunkLoaderHelper.loadChunkForcedWorlds(event); } } diff --git a/StevenDimDoors/mod_pocketDim/saving/BlacklistProcessor.java b/StevenDimDoors/mod_pocketDim/saving/BlacklistProcessor.java new file mode 100644 index 0000000..da1cb3b --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/saving/BlacklistProcessor.java @@ -0,0 +1,76 @@ +package StevenDimDoors.mod_pocketDim.saving; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; + +import StevenDimDoors.mod_pocketDim.util.BaseConfigurationProcessor; +import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException; + +public class BlacklistProcessor extends BaseConfigurationProcessor> +{ + + @Override + public List readFromStream(InputStream inputStream) throws ConfigurationProcessingException + { + try + { + JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); + List data = this.createBlacklistFromJson(reader); + return data; + } + catch (IOException e) + { + e.printStackTrace(); + throw new ConfigurationProcessingException("Could not read blacklist"); + } + } + + private List createBlacklistFromJson(JsonReader reader) throws IOException + { + List blacklist; + blacklist = this.createIntListFromJson(reader); + return blacklist; + } + + @Override + public void writeToStream(OutputStream outputStream, List data) throws ConfigurationProcessingException + { + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.setPrettyPrinting().create(); + + try + { + outputStream.write(gson.toJson(data).getBytes("UTF-8")); + outputStream.close(); + } + catch (IOException e) + { + // not sure if this is kosher, we need it to explode, but not by throwing the IO exception. + throw new ConfigurationProcessingException("Incorrectly formatted save data"); + } + + } + + private List createIntListFromJson(JsonReader reader) throws IOException + { + List list = new ArrayList(); + reader.beginArray(); + + while(reader.peek()!= JsonToken.END_ARRAY) + { + list.add(reader.nextInt()); + } + reader.endArray(); + return list; + } + +} diff --git a/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java b/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java index efdf19c..e821b57 100644 --- a/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java +++ b/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java @@ -2,6 +2,7 @@ package StevenDimDoors.mod_pocketDim.saving; import java.io.File; import java.io.FileFilter; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -9,12 +10,14 @@ import java.util.List; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; +import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException; import StevenDimDoors.mod_pocketDim.util.FileFilters; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -45,7 +48,14 @@ public class DDSaveHandler } // Load the dimension blacklist - // --insert code here-- + File blacklistFile = new File(basePath+"blacklist.txt"); + + if(blacklistFile.exists()) + { + BlacklistProcessor blacklistReader = new BlacklistProcessor(); + List blacklist = readBlacklist(blacklistFile,blacklistReader); + PocketManager.createAndRegisterBlacklist(blacklist); + } // List any dimension data files and read each dimension DimDataProcessor reader = new DimDataProcessor(); @@ -127,7 +137,14 @@ public class DDSaveHandler if(packedLink.parent.equals(fakePoint)) { NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension()); - DimLink link = data.createLink(packedLink.source, packedLink.tail.linkType, packedLink.orientation); + int linkType = packedLink.tail.linkType; + + if((linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) && linkType != LinkTypes.CLIENT_SIDE) + { + linkType = LinkTypes.NORMAL; + } + + DimLink link = data.createLink(packedLink.source, linkType, packedLink.orientation); Point4D destination = packedLink.tail.destination; if(destination!=null) { @@ -171,7 +188,7 @@ public class DDSaveHandler } } - public static boolean saveAll(Iterable> dimensions) throws IOException + public static boolean saveAll(Iterable> dimensions, List blacklist) throws IOException { // Create the data directory for our dimensions // Don't catch exceptions here. If we can't create this folder, @@ -181,6 +198,9 @@ public class DDSaveHandler File basePathFile = new File(basePath); Files.createParentDirs(basePathFile); basePathFile.mkdir(); + + BlacklistProcessor blacklistReader = new BlacklistProcessor(); + writeBlacklist(blacklist, blacklistReader,basePath); FileFilter dataFileFilter = new FileFilters.RegexFileFilter("dim_-?\\d+\\.txt"); @@ -204,6 +224,25 @@ public class DDSaveHandler return succeeded; } + private static boolean writeBlacklist(List blacklist, BlacklistProcessor writer, String basePath) + { + try + { + File tempFile = new File(basePath + "blacklist.tmp"); + File saveFile = new File(basePath + "blacklist.txt"); + writer.writeToFile(tempFile, blacklist); + saveFile.delete(); + tempFile.renameTo(saveFile); + return true; + } + catch (Exception e) + { + System.err.println("Could not save blacklist. The following error occurred:"); + printException(e, true); + return false; + } + + } private static boolean writeDimension(IPackable dimension, DimDataProcessor writer, String basePath) { try @@ -253,17 +292,29 @@ public class DDSaveHandler //TODO - make this more robust public static DungeonData unpackDungeonData(PackedDungeonData packedDungeon) - { - DungeonPack pack; - DungeonType type; - + { for(DungeonData data : DungeonHelper.instance().getRegisteredDungeons()) { if(data.schematicName().equals(packedDungeon.SchematicName)) { - //return data; + return data; } } return null; } + + public static List readBlacklist(File blacklistFile, BlacklistProcessor reader) + { + + try + { + return reader.readFromFile(blacklistFile); + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + + } } diff --git a/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java b/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java index 7be35fa..55a01d9 100644 --- a/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java +++ b/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java @@ -67,9 +67,7 @@ public class DimDataProcessor extends BaseConfigurationProcessor { // not sure if this is kosher, we need it to explode, but not by throwing the IO exception. throw new ConfigurationProcessingException("Incorrectly formatted save data"); - } - // TODO Auto-generated method stub - + } } /** * Nightmare method that takes a JsonReader pointed at a serialized instance of PackedDimData diff --git a/StevenDimDoors/mod_pocketDim/util/gson-2.2.4-sources.jar b/StevenDimDoors/mod_pocketDim/util/gson-2.2.4-sources.jar deleted file mode 100644 index 30b13f6..0000000 Binary files a/StevenDimDoors/mod_pocketDim/util/gson-2.2.4-sources.jar and /dev/null differ diff --git a/StevenDimDoors/mod_pocketDim/util/gson-2.2.4.jar b/StevenDimDoors/mod_pocketDim/util/gson-2.2.4.jar deleted file mode 100644 index 9478253..0000000 Binary files a/StevenDimDoors/mod_pocketDim/util/gson-2.2.4.jar and /dev/null differ diff --git a/build.xml b/build.xml index c6bed13..13e1c3c 100644 --- a/build.xml +++ b/build.xml @@ -14,6 +14,9 @@ + + + @@ -41,8 +44,6 @@ - - @@ -56,6 +57,7 @@ + @@ -65,17 +67,27 @@ - + - - + + + + + + + + + + + - + + @@ -138,9 +150,18 @@ - + + + + + + + + + + @@ -155,17 +176,17 @@ --> - - - - - - - - - - - + + + + + + + + + + + diff --git a/buildOLD.xml b/buildOLD.xml new file mode 100644 index 0000000..c6bed13 --- /dev/null +++ b/buildOLD.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/mods/DimDoors/textures/items/ItemWorldThread.png b/resources/mods/DimDoors/textures/items/ItemWorldThread.png new file mode 100644 index 0000000..8af4bf8 Binary files /dev/null and b/resources/mods/DimDoors/textures/items/ItemWorldThread.png differ diff --git a/resources/mods/DimDoors/textures/other/RIFT.png b/resources/mods/DimDoors/textures/other/RIFT.png new file mode 100644 index 0000000..ae24e83 Binary files /dev/null and b/resources/mods/DimDoors/textures/other/RIFT.png differ diff --git a/resources/mods/DimDoors/textures/other/WARP.png b/resources/mods/DimDoors/textures/other/WARP.png new file mode 100644 index 0000000..fd8efb2 Binary files /dev/null and b/resources/mods/DimDoors/textures/other/WARP.png differ diff --git a/resources/mods/DimDoors/textures/other/dimdoors_logo.png b/resources/mods/DimDoors/textures/other/dimdoors_logo.png new file mode 100644 index 0000000..6828be8 Binary files /dev/null and b/resources/mods/DimDoors/textures/other/dimdoors_logo.png differ