diff --git a/src/main/java/com/hbm/items/tool/ItemWandD.java b/src/main/java/com/hbm/items/tool/ItemWandD.java index 69fdac079..3d1c7d211 100644 --- a/src/main/java/com/hbm/items/tool/ItemWandD.java +++ b/src/main/java/com/hbm/items/tool/ItemWandD.java @@ -9,6 +9,7 @@ import com.hbm.items.ModItems; import com.hbm.items.special.ItemKitCustom; import com.hbm.lib.Library; import com.hbm.world.feature.OilSpot; +import com.hbm.world.worldgen.MapGenBunker.Start; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -19,6 +20,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; +import net.minecraft.world.gen.structure.StructureBoundingBox; public class ItemWandD extends Item { @@ -32,7 +34,14 @@ public class ItemWandD extends Item { if(pos != null) { - OilSpot.generateOilSpot(world, pos.blockX, pos.blockZ, 20, 500); + //use sparingly + int k = ((pos.blockX >> 4) << 4) + 8; + int l = ((pos.blockZ >> 4) << 4) + 8; + + Start start = new Start(world, world.rand, pos.blockX >> 4, pos.blockZ >> 4); + start.generateStructure(world, world.rand, new StructureBoundingBox(k - 100, l - 100, k + 15 + 100, l + 15 + 100)); + + /*OilSpot.generateOilSpot(world, pos.blockX, pos.blockZ, 20, 500);*/ /*EntityNukeTorex torex = new EntityNukeTorex(world); torex.setPositionAndRotation(pos.blockX, pos.blockY + 1, pos.blockZ, 0, 0); diff --git a/src/main/java/com/hbm/lib/HbmWorld.java b/src/main/java/com/hbm/lib/HbmWorld.java index fae367daf..b14484fb1 100644 --- a/src/main/java/com/hbm/lib/HbmWorld.java +++ b/src/main/java/com/hbm/lib/HbmWorld.java @@ -2,6 +2,7 @@ package com.hbm.lib; import com.hbm.world.worldgen.MapGenNTMFeatures; import com.hbm.world.worldgen.NTMWorldGenerator; +import com.hbm.world.worldgen.components.BunkerComponents.*; import com.hbm.world.worldgen.components.CivilianFeatures.*; import com.hbm.world.worldgen.components.MilitaryBaseFeatures.*; import com.hbm.world.worldgen.components.OfficeFeatures.*; @@ -49,5 +50,10 @@ public class HbmWorld { MapGenStructureIO.func_143031_a(RadioShack.class, "NTMRadioShack"); MapGenStructureIO.func_143031_a(LargeOffice.class, "NTMLargeOffice"); MapGenStructureIO.func_143031_a(LargeOfficeCorner.class, "NTMLargeOfficeCorner"); + + //bunker + MapGenStructureIO.func_143031_a(Atrium.class, "NTMBAtrium"); + MapGenStructureIO.func_143031_a(Corridor.class, "NTMBCorridor"); + MapGenStructureIO.func_143031_a(WideCorridor.class, "NTMBWideCorridor"); } } diff --git a/src/main/java/com/hbm/world/worldgen/MapGenBunker.java b/src/main/java/com/hbm/world/worldgen/MapGenBunker.java index e72ef51ea..0513e51a6 100644 --- a/src/main/java/com/hbm/world/worldgen/MapGenBunker.java +++ b/src/main/java/com/hbm/world/worldgen/MapGenBunker.java @@ -2,8 +2,14 @@ package com.hbm.world.worldgen; import java.util.Random; +import com.hbm.config.GeneralConfig; +import com.hbm.world.worldgen.components.BunkerComponents; +import com.hbm.world.worldgen.components.BunkerComponents.Atrium; + import net.minecraft.world.World; import net.minecraft.world.gen.structure.MapGenStructure; +import net.minecraft.world.gen.structure.MapGenStructureIO; +import net.minecraft.world.gen.structure.StructureComponent; import net.minecraft.world.gen.structure.StructureStart; public class MapGenBunker extends MapGenStructure { @@ -30,7 +36,19 @@ public class MapGenBunker extends MapGenStructure { public Start(World world, Random rand, int chunkX, int chunkZ) { super(chunkX, chunkZ); + BunkerComponents.prepareComponents(); + Atrium atrium = new Atrium(0, rand, (chunkX << 4) + 8, (chunkZ << 4) + 8); + this.components.add(atrium); + atrium.buildComponent(atrium, components, rand); + if(GeneralConfig.enableDebugMode) { + System.out.print("[Debug] StructureStart at " + (chunkX * 16 + 8) + ", idfk lmao, " + (chunkZ * 16 + 8) + "\n[Debug] Components: "); + this.components.forEach((component) -> { + System.out.print(MapGenStructureIO.func_143036_a((StructureComponent) component) + " "); + }); + + System.out.print("\n"); + } this.updateBoundingBox(); this.markAvailableHeight(world, rand, 10); diff --git a/src/main/java/com/hbm/world/worldgen/components/BunkerComponents.java b/src/main/java/com/hbm/world/worldgen/components/BunkerComponents.java index fb67a0d55..a85a68a7b 100644 --- a/src/main/java/com/hbm/world/worldgen/components/BunkerComponents.java +++ b/src/main/java/com/hbm/world/worldgen/components/BunkerComponents.java @@ -15,7 +15,12 @@ import net.minecraft.world.gen.structure.StructureComponent; public class BunkerComponents { - private static final Weight[] weightArray = new Weight[0]; + private static final Weight[] weightArray = new Weight[] { + new Weight(2, 50, (list, rand, x, y, z, mode, type) -> { StructureBoundingBox box = Bunker.getComponentToAddBoundingBox(x, y, z, -1, -1, 0, 5, 5, 15, type); + return box.minY > 10 && StructureComponent.findIntersecting(list, box) == null ? new Corridor(type, rand, box, mode) : null; }), + new Weight(3, -1, (list, rand, x, y, z, mode, type) -> { StructureBoundingBox box = Bunker.getComponentToAddBoundingBox(x, y, z, -3, -1, 0, 9, 5, 17, type); + return box.minY > 10 && StructureComponent.findIntersecting(list, box) == null ? new WideCorridor(type, rand, box, mode) : null; }), + }; private static List componentWeightList; static int totalWeight; @@ -29,8 +34,26 @@ public class BunkerComponents { } } + private static boolean canAddStructurePieces() { + boolean flag = false; + totalWeight = 0; + Weight weight; + + for(Iterator iterator = componentWeightList.iterator(); iterator.hasNext(); totalWeight += weight.weight) { + weight = (Weight) iterator.next(); + + if(weight.instanceLimit >= 0 && weight.instancesSpawned < weight.instanceLimit) + flag = true; + } + System.out.println(flag); + return flag; + } + private static Bunker getWeightedComponent(StructureComponent original, List components, Random rand, int minX, int minY, int minZ, int coordMode, int componentType) { + if(!canAddStructurePieces()) + return null; + for(int i = 0; i < 5; i++) { int value = rand.nextInt(totalWeight); Iterator iterator = componentWeightList.iterator(); @@ -43,7 +66,7 @@ public class BunkerComponents { if(!weight.canSpawnStructure(componentType)) break; - Bunker component = weight.lambda.findValidPlacement(components, rand, minX, minY, minZ, coordMode, componentType); + Bunker component = (Bunker) weight.lambda.findValidPlacement(components, rand, minX, minY, minZ, coordMode, componentType); if(component != null) { weight.instancesSpawned++; @@ -66,7 +89,7 @@ public class BunkerComponents { if(components.size() > 50) return null; - if(Math.abs(minX - original.getBoundingBox().minX) <= 112 && Math.abs(minZ - original.getBoundingBox().minX) <= 112) { + if(Math.abs(minX - original.getBoundingBox().minX) <= 112 && Math.abs(minZ - original.getBoundingBox().minZ) <= 112) { StructureComponent structure = getWeightedComponent(original, components, rand, minX, minY, minZ, coordMode, componentType); @@ -90,20 +113,20 @@ public class BunkerComponents { public int instancesSpawned; public int instanceLimit; - public Weight(instantiateStructure lambda, int weight, int limit) { - this.lambda = lambda; + public Weight(int weight, int limit, instantiateStructure lambda) { this.weight = weight; this.instanceLimit = limit; + this.lambda = lambda; } //Checks if another structure can be spawned based on input data public boolean canSpawnStructure(int componentAmount) { - return this.instanceLimit == 0 || this.instanceLimit < this.instanceLimit; + return this.instanceLimit < 0 || this.instanceLimit < this.instanceLimit; } //Checks if another structure can be spawned at all (used to flag for removal from the list) public boolean canSpawnMoreStructures() { - return this.instanceLimit == 0 || this.instancesSpawned < this.instanceLimit; + return this.instanceLimit < 0 || this.instancesSpawned < this.instanceLimit; } } @@ -111,7 +134,7 @@ public class BunkerComponents { /** Returns a new instance of this structureComponent, or null if not able to be placed. */ @FunctionalInterface interface instantiateStructure { - Bunker findValidPlacement(List components, Random rand, int minX, int minY, int minZ, int coordMode, int componentType); + StructureComponent findValidPlacement(List components, Random rand, int minX, int minY, int minZ, int coordMode, int componentType); } public abstract static class Bunker extends Feature { @@ -124,6 +147,7 @@ public class BunkerComponents { /** Gets next component in the direction this component is facing.
'original' refers to the initial starting component (hard distance limits), 'components' refers to the StructureStart list. */ protected StructureComponent getNextComponentNormal(StructureComponent original, List components, Random rand, int offset, int offsetY) { + switch(this.coordBaseMode) { case 0: //South return getNextValidComponent(original, components, rand, this.boundingBox.minX + offset, this.boundingBox.minY + offsetY, this.boundingBox.maxZ + 1, this.coordBaseMode, this.getComponentType()); @@ -171,7 +195,7 @@ public class BunkerComponents { } } - protected static StructureBoundingBox getComponentToAddBoundingBox(int posX, int posY, int posZ, int offsetX, int offsetY, int offsetZ, int maxX, int maxY, int maxZ, int coordMode) { + public static StructureBoundingBox getComponentToAddBoundingBox(int posX, int posY, int posZ, int offsetX, int offsetY, int offsetZ, int maxX, int maxY, int maxZ, int coordMode) { switch(coordMode) { case 0: return new StructureBoundingBox(posX + offsetX, posY + offsetY, posZ + offsetZ, posX + maxX - 1 + offsetX, posY + maxY - 1 + offsetY, posZ + maxZ - 1 + offsetZ); @@ -191,15 +215,17 @@ public class BunkerComponents { public Atrium() { } - public Atrium(int componentType, Random rand, StructureBoundingBox box, int coordBaseMode) { + public Atrium(int componentType, Random rand, int posX, int posZ) { //TODO: change basically everything about this component super(componentType); - this.coordBaseMode = coordBaseMode; - this.boundingBox = box; + this.coordBaseMode = rand.nextInt(4); + this.boundingBox = new StructureBoundingBox(posX, 64, posZ, posX + 4, 68, posZ + 4); } @Override public void buildComponent(StructureComponent original, List components, Random rand) { - + getNextComponentNormal(original, components, rand, 1, 1); + getNextComponentNX(original, components, rand, 1, 1); + getNextComponentPX(original, components, rand, 1, 1); } @Override @@ -321,7 +347,7 @@ public class BunkerComponents { @Override public void buildComponent(StructureComponent original, List components, Random rand) { - getNextComponentNormal(original, components, rand, 1, 1); + getNextComponentNormal(original, components, rand, 3, 1); if(expandsNX) getNextComponentNX(original, components, rand, 7, 1); @@ -344,7 +370,7 @@ public class BunkerComponents { //Floor fillWithBlocks(world, box, 1, 0, begin, 1, 0, end, ModBlocks.deco_titanium); fillWithBlocks(world, box, 2, 0, begin, 2, 0, end, ModBlocks.tile_lab); - fillWithBlocks(world, box, 3, 0, 0, 5, 0, 14, ModBlocks.deco_titanium); + fillWithBlocks(world, box, 3, 0, 0, 5, 0, 16, ModBlocks.deco_titanium); fillWithBlocks(world, box, 6, 0, begin, 6, 0, end, ModBlocks.tile_lab); fillWithBlocks(world, box, 7, 0, begin, 7, 0, end, ModBlocks.deco_titanium); @@ -391,21 +417,21 @@ public class BunkerComponents { } if(bulkheadNZ) { - fillWithBlocks(world, box, 0, 1, 0, 1, 1, 0, ModBlocks.reinforced_brick); - fillWithBlocks(world, box, 0, 2, 0, 1, 2, 0, ModBlocks.reinforced_stone); - fillWithBlocks(world, box, 0, 3, 0, 1, 3, 0, ModBlocks.reinforced_brick); - fillWithBlocks(world, box, 5, 1, 0, 6, 1, 0, ModBlocks.reinforced_brick); - fillWithBlocks(world, box, 5, 2, 0, 6, 2, 0, ModBlocks.reinforced_stone); - fillWithBlocks(world, box, 5, 3, 0, 6, 3, 0, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 1, 1, 0, 2, 1, 0, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 1, 2, 0, 2, 2, 0, ModBlocks.reinforced_stone); + fillWithBlocks(world, box, 1, 3, 0, 2, 3, 0, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 6, 1, 0, 7, 1, 0, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 6, 2, 0, 7, 2, 0, ModBlocks.reinforced_stone); + fillWithBlocks(world, box, 6, 3, 0, 7, 3, 0, ModBlocks.reinforced_brick); } if(bulkheadPZ) { - fillWithBlocks(world, box, 0, 1, 16, 1, 1, 16, ModBlocks.reinforced_brick); - fillWithBlocks(world, box, 0, 2, 16, 1, 2, 16, ModBlocks.reinforced_stone); - fillWithBlocks(world, box, 0, 3, 16, 1, 3, 16, ModBlocks.reinforced_brick); - fillWithBlocks(world, box, 5, 1, 16, 6, 1, 16, ModBlocks.reinforced_brick); - fillWithBlocks(world, box, 5, 2, 16, 6, 2, 16, ModBlocks.reinforced_stone); - fillWithBlocks(world, box, 5, 3, 16, 6, 3, 16, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 1, 1, 16, 2, 1, 16, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 1, 2, 16, 2, 2, 16, ModBlocks.reinforced_stone); + fillWithBlocks(world, box, 1, 3, 16, 2, 3, 16, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 6, 1, 16, 7, 1, 16, ModBlocks.reinforced_brick); + fillWithBlocks(world, box, 6, 2, 16, 7, 2, 16, ModBlocks.reinforced_stone); + fillWithBlocks(world, box, 6, 3, 16, 7, 3, 16, ModBlocks.reinforced_brick); } //Ceiling