From e63ae52823303d88b498ab80c53995ae9c7ff6ba Mon Sep 17 00:00:00 2001 From: Waterpicker Date: Tue, 22 May 2018 04:35:54 -0500 Subject: [PATCH] Added config option to use enderpearls in crafting recipes and disable stable fabric when doing so. --- .../org/dimdev/dimdoors/shared/ModConfig.java | 4 + .../dimdev/dimdoors/shared/ModRecipes.java | 37 ++--- .../fortresses/ComponentNetherGateway.java | 4 + .../fortresses/DDNetherFortressGenerator.java | 25 +++ .../DDStructureNetherBridgeStart.java | 144 ++++++++++++++++++ .../dimdoors/advancements/dimdoor/root.json | 24 +++ 6 files changed, 221 insertions(+), 17 deletions(-) create mode 100644 src/main/java/org/dimdev/dimdoors/shared/world/fortresses/ComponentNetherGateway.java create mode 100644 src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDNetherFortressGenerator.java create mode 100644 src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDStructureNetherBridgeStart.java create mode 100644 src/main/resources/assets/dimdoors/advancements/dimdoor/root.json diff --git a/src/main/java/org/dimdev/dimdoors/shared/ModConfig.java b/src/main/java/org/dimdev/dimdoors/shared/ModConfig.java index 114498a9..32ce8f01 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/ModConfig.java +++ b/src/main/java/org/dimdev/dimdoors/shared/ModConfig.java @@ -50,6 +50,10 @@ public final class ModConfig { @Name("depthSpreadFactor") @LangKey("dimdoors.general.depthSpreadFactor") public int depthSpreadFactor = 20; + + @Name("useEnderPearlsInCrafting") + @LangKey("dimdoors.general.useEnderPearlsInCrafting") + public boolean useEnderPearlsInCrafting = false; } public static class Pockets { diff --git a/src/main/java/org/dimdev/dimdoors/shared/ModRecipes.java b/src/main/java/org/dimdev/dimdoors/shared/ModRecipes.java index fc684748..1c441fdb 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/ModRecipes.java +++ b/src/main/java/org/dimdev/dimdoors/shared/ModRecipes.java @@ -3,6 +3,7 @@ package org.dimdev.dimdoors.shared; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.*; import net.minecraft.util.NonNullList; @@ -57,60 +58,62 @@ public final class ModRecipes { @SubscribeEvent public static void registerRecipes(RegistryEvent.Register event) { + Item usedItem = ModConfig.general.useEnderPearlsInCrafting ? Items.ENDER_PEARL : ModItems.STABLE_FABRIC; + IForgeRegistry registry = event.getRegistry(); - registry.register(makeShapedRecipe(new ItemStack(ModItems.STABLE_FABRIC), - "yxy", 'x', Items.ENDER_PEARL, 'y', ModItems.WORLD_THREAD)); + + if(!ModConfig.general.useEnderPearlsInCrafting) { + registry.register(makeShapedRecipe(new ItemStack(ModItems.STABLE_FABRIC), + "yxy", 'x', Items.ENDER_PEARL, 'y', ModItems.WORLD_THREAD)); + } registry.register(makeShapedRecipe(new ItemStack(ModItems.IRON_DIMENSIONAL_DOOR), - "yxy", 'x', ModItems.STABLE_FABRIC, 'y', Items.IRON_DOOR)); + "yxy", 'x',usedItem, 'y', Items.IRON_DOOR)); registry.register(makeShapedRecipe(new ItemStack(ModItems.UNSTABLE_DIMENSIONAL_DOOR), "xyx", 'x', Items.ENDER_EYE, 'y', Items.IRON_DOOR)); registry.register(makeShapedRecipe(new ItemStack(ModItems.WOOD_DIMENSIONAL_DOOR), - "yxy", 'x', Items.ENDER_PEARL, 'y', Items.OAK_DOOR)); + "yxy", 'x', usedItem, 'y', Items.OAK_DOOR)); registry.register(makeShapedRecipe(new ItemStack(ModBlocks.WOOD_DIMENSIONAL_TRAPDOOR), - "yx", 'x', Items.ENDER_PEARL, 'y', Blocks.TRAPDOOR)); + "yx", 'x', usedItem, 'y', Blocks.TRAPDOOR)); registry.register(makeShapedRecipe(new ItemStack(ModItems.GOLD_DIMENSIONAL_DOOR), - "yxy", 'x', ModItems.STABLE_FABRIC, 'y', ModItems.GOLD_DOOR)); + "yxy", 'x', usedItem, 'y', ModItems.GOLD_DOOR)); registry.register(makeShapedRecipe(new ItemStack(ModItems.GOLD_DOOR), "yy", "yy", "yy", 'y', Items.GOLD_INGOT)); registry.register(makeShapedRecipe(new ItemStack(ModItems.QUARTZ_DIMENSIONAL_DOOR), - "yx", 'x', ModItems.STABLE_FABRIC, 'y', ModItems.QUARTZ_DOOR)); + "yx", 'x', usedItem, 'y', ModItems.QUARTZ_DOOR)); registry.register(makeShapedRecipe(new ItemStack(ModItems.QUARTZ_DOOR), "yy", "yy", "yy", 'y', Items.QUARTZ)); registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_BLADE), - "y", "y", "x", 'y', ModItems.STABLE_FABRIC, 'x', Items.IRON_SWORD)); + "y", "y", "x", 'y', usedItem, 'x', Items.IRON_SWORD)); //should not be craftable /*registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_CONFIGURATION_TOOL), " w ", "xyx", "xzx", 'z', Items.DIAMOND_SHOVEL, 'y', ModItems.STABLE_FABRIC, 'x', ModItems.WORLD_THREAD, 'w', Items.DIAMOND));*/ registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_REMOVER), - "xxx", "xyx", "xxx", 'x', Items.GOLD_INGOT, 'y', Items.ENDER_PEARL)); + "xxx", "xyx", "xxx", 'x', Items.GOLD_INGOT, 'y', usedItem)); registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_REMOVER), - "x x", " y ", "x x", 'x', Items.GOLD_INGOT, 'y', ModItems.STABLE_FABRIC)); + "x x", " y ", "x x", 'x', Items.GOLD_INGOT, 'y', usedItem)); registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_SIGNATURE), - "xxx", "xyx", "xxx", 'x', Items.IRON_INGOT, 'y', Items.ENDER_PEARL)); + "xxx", "xyx", "xxx", 'x', Items.IRON_INGOT, 'y', usedItem)); registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_SIGNATURE), - "x x", " y ", "x x", 'x', Items.IRON_INGOT, 'y', ModItems.STABLE_FABRIC)); + "x x", " y ", "x x", 'x', Items.IRON_INGOT, 'y', usedItem)); registry.register(makeShapedRecipe(new ItemStack(ModItems.STABILIZED_RIFT_SIGNATURE), - "x x", " y ", "x x", 'x', ModItems.STABLE_FABRIC, 'y', ModItems.RIFT_SIGNATURE)); + "x x", " y ", "x x", 'x', usedItem, 'y', ModItems.RIFT_SIGNATURE)); registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_STABILIZER), - "xxx", "xyx", "xxx", 'x', Items.DIAMOND, 'y', Items.ENDER_PEARL)); - - registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_STABILIZER), - "x x", " y ", "x x", 'x', Items.DIAMOND, 'y', ModItems.STABLE_FABRIC)); + "x x", " y ", "x x", 'x', Items.DIAMOND, 'y', usedItem)); registry.register(makeShapedRecipe(new ItemStack(ModItems.WOVEN_WORLD_THREAD_HELMET), "xxx", "x x", 'x', ModItems.WORLD_THREAD)); diff --git a/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/ComponentNetherGateway.java b/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/ComponentNetherGateway.java new file mode 100644 index 00000000..ab9908c5 --- /dev/null +++ b/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/ComponentNetherGateway.java @@ -0,0 +1,4 @@ +package org.dimdev.dimdoors.shared.world.fortresses; + +public class ComponentNetherGateway { +} diff --git a/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDNetherFortressGenerator.java b/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDNetherFortressGenerator.java new file mode 100644 index 00000000..ebe5c7b2 --- /dev/null +++ b/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDNetherFortressGenerator.java @@ -0,0 +1,25 @@ +package org.dimdev.dimdoors.shared.world.fortresses; + +import net.minecraft.world.gen.structure.MapGenNetherBridge; +import net.minecraft.world.gen.structure.MapGenStructureIO; +import net.minecraft.world.gen.structure.StructureStart; + +public class DDNetherFortressGenerator extends MapGenNetherBridge +{ + public DDNetherFortressGenerator() + { + super(); + + // Register our custom StructureStart class with MapGenStructureIO + // If we don't do this, Minecraft will crash when a fortress tries to generate. + // Moreover, use Fortress as our structure identifier so that if DD is removed, + // fortresses will generate properly using Vanilla code. + //MapGenStructureIO.registerStructureComponent(DDStructureNetherBridgeStart.class, "Fortress"); + } + + @Override + protected StructureStart getStructureStart(int chunkX, int chunkZ) + { + return new DDStructureNetherBridgeStart(this.world, this.rand, chunkX, chunkZ); + } +} \ No newline at end of file diff --git a/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDStructureNetherBridgeStart.java b/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDStructureNetherBridgeStart.java new file mode 100644 index 00000000..2b1cbda6 --- /dev/null +++ b/src/main/java/org/dimdev/dimdoors/shared/world/fortresses/DDStructureNetherBridgeStart.java @@ -0,0 +1,144 @@ +package org.dimdev.dimdoors.shared.world.fortresses; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.gen.structure.StructureComponent; +import net.minecraft.world.gen.structure.StructureNetherBridgePieces; +import net.minecraft.world.gen.structure.StructureStart; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Random; + +public class DDStructureNetherBridgeStart extends StructureStart +{ + public static final int MAX_GATEWAY_GENERATION_CHANCE = 100; + + private boolean hasGateway; + private int minX; + private int minY; + private int minZ; + + public DDStructureNetherBridgeStart() { } + + public DDStructureNetherBridgeStart(World world, Random random, int chunkX, int chunkZ, DDProperties properties) + { + // StructureNetherBridgeStart handles designing the fortress for us + super(chunkX, chunkZ); + + Iterator componentIterator; + StructureComponent component; + StructureBoundingBox bounds; + ArrayList spawnerRooms; + hasGateway = false; + + // Randomly decide whether to build a gateway in this fortress + if (random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.FortressGatewayGenerationChance) + { + // Search for all the blaze spawners in a fortress + spawnerRooms = new ArrayList(); + componentIterator = this.components.iterator(); + while (componentIterator.hasNext()) + { + component = (StructureComponent) componentIterator.next(); + if (component instanceof StructureNetherBridgePieces.Throne) + { + spawnerRooms.add((StructureNetherBridgePieces.Throne) component); + } + } + + // If any spawner rooms were found, choose one to randomly replace + if (!spawnerRooms.isEmpty()) + { + hasGateway = true; + component = spawnerRooms.get(random.nextInt(spawnerRooms.size())); + // Store enough data to identify the room when it's going to be built later + bounds = component.getBoundingBox(); + minX = bounds.minX; + minY = bounds.minY; + minZ = bounds.minZ; + } + } + } + + @Override + public NBTTagCompound writeStructureComponentsToNBT(int chunkX, int chunkZ) { + + + // We override the function for writing NBT data to add our own gateway data + NBTTagCompound fortressTag = super.writeStructureComponentsToNBT(chunkX, chunkZ); + + // Add a compound tag with our data + NBTTagCompound dimensionalTag = new NBTTagCompound(); + dimensionalTag.setBoolean("HasGateway", this.hasGateway); + if (hasGateway) { + dimensionalTag.setInteger("GatewayMinX", this.minX); + dimensionalTag.setInteger("GatewayMinY", this.minY); + dimensionalTag.setInteger("GatewayMinZ", this.minZ); + } + fortressTag.setTag("DimensionalDoors", dimensionalTag); + + return fortressTag; + } + + @Override + public void func_143020_a(World world, NBTTagCompound fortressTag) + { + // We override the function for reading NBT data to load gateway data + super.func_143020_a(world, fortressTag); + + NBTTagCompound dimensionalTag = fortressTag.getCompoundTag("DimensionalDoors"); + if (dimensionalTag != null) + { + this.hasGateway = dimensionalTag.getBoolean("HasGateway"); + if (hasGateway) + { + minX = dimensionalTag.getInteger("GatewayMinX"); + minY = dimensionalTag.getInteger("GatewayMinY"); + minZ = dimensionalTag.getInteger("GatewayMinZ"); + } + } + } + + /** + * Keeps iterating Structure Pieces and spawning them until the checks tell it to stop + */ + @Override + public void generateStructure(World world, Random random, StructureBoundingBox generationBounds) + { + if (hasGateway) + { + // Use a modified version of Vanilla's fortress generation code + // Try to detect the room that we intend to replace with our gateway + Iterator iterator = this.components.iterator(); + + while (iterator.hasNext()) + { + StructureComponent component = (StructureComponent)iterator.next(); + StructureBoundingBox bounds = component.getBoundingBox(); + + if (bounds.intersectsWith(generationBounds)) + { + // Check if this is our replacement target + // Checking the location is enough because structures aren't allowed to have + // intersecting bounding boxes - nothing else can have these min coordinates. + if (bounds.minX == this.minX && bounds.minY == this.minY && bounds.minZ == this.minZ) + { + component = ComponentNetherGateway.createFromComponent(component, random); + } + // Now for the last bit of Vanilla's generation code + if (!component.addComponentParts(world, random, generationBounds)) + { + iterator.remove(); + } + } + } + } + else + { + // Just run the usual structure generation + super.generateStructure(world, random, generationBounds); + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimdoors/advancements/dimdoor/root.json b/src/main/resources/assets/dimdoors/advancements/dimdoor/root.json new file mode 100644 index 00000000..7897836f --- /dev/null +++ b/src/main/resources/assets/dimdoors/advancements/dimdoor/root.json @@ -0,0 +1,24 @@ +{ + "display": { + "icon": { + "item": "dimdoors:unravelled_fabric" + }, + "title": { + "translate": "Space between Spaces" + }, + "description": { + "translate": "advancements.end.root.description" + }, + "background": "minecraft:textures/gui/advancements/backgrounds/end.png", + "show_toast": true, + "announce_to_chat": true + }, + "criteria": { + "entered_end": { + "trigger": "minecraft:changed_dimension", + "conditions": { + "to": "private_pockets" + } + } + } +} \ No newline at end of file