diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-07-07 06:33:58 +1000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-07-07 06:33:58 +1000 |
commit | 25c4b00360fd6448f2c8283051434271f05b1735 (patch) | |
tree | eff8b8836ade6dd5acb96e9f079bb84d0bd9795c /src/Java/gtPlusPlus/australia/gen/map | |
parent | df602b8f36b16fc7695c21ea66deb1a2a34aa8b3 (diff) | |
download | GT5-Unofficial-25c4b00360fd6448f2c8283051434271f05b1735.tar.gz GT5-Unofficial-25c4b00360fd6448f2c8283051434271f05b1735.tar.bz2 GT5-Unofficial-25c4b00360fd6448f2c8283051434271f05b1735.zip |
$ More work on Australia and Villages.
Diffstat (limited to 'src/Java/gtPlusPlus/australia/gen/map')
3 files changed, 460 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/australia/gen/map/MapGenExtendedVillage.java b/src/Java/gtPlusPlus/australia/gen/map/MapGenExtendedVillage.java new file mode 100644 index 0000000000..8fc6940242 --- /dev/null +++ b/src/Java/gtPlusPlus/australia/gen/map/MapGenExtendedVillage.java @@ -0,0 +1,265 @@ +package gtPlusPlus.australia.gen.map; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.australia.GTplusplus_Australia; + +import java.util.Map.Entry; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.gen.structure.MapGenStructure; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.gen.structure.StructureComponent; +import net.minecraft.world.gen.structure.StructureStart; +import net.minecraft.world.gen.structure.StructureVillagePieces; + +public class MapGenExtendedVillage extends MapGenStructure +{ + /** A list of all the biomes villages can spawn in. */ + public static List<BiomeGenBase> villageSpawnBiomes = Arrays.asList(new BiomeGenBase[] {GTplusplus_Australia.Australian_Desert_Biome_3, GTplusplus_Australia.Australian_Plains_Biome, GTplusplus_Australia.Australian_Forest_Biome, GTplusplus_Australia.Australian_Outback_Biome}); + /** World terrain type, 0 for normal, 1 for flat map */ + private int terrainType; + private int field_82665_g; + private int field_82666_h; + + public MapGenExtendedVillage(){ + this.field_82665_g = 8; + this.field_82666_h = 4; + } + + public MapGenExtendedVillage(Map<?, ?> p_i2093_1_){ + this(); + Iterator<?> iterator = p_i2093_1_.entrySet().iterator(); + + Logger.INFO("Created Extended Village Object."); + + while (iterator.hasNext()) + { + Entry<?, ?> entry = (Entry<?, ?>)iterator.next(); + + if (((String)entry.getKey()).equals("size")) + { + this.terrainType = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.terrainType, 0); + } + else if (((String)entry.getKey()).equals("distance")) + { + this.field_82665_g = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.field_82665_g, this.field_82666_h + 1); + } + } + } + + public String func_143025_a() + { + return "ExtendedVillage"; + } + + protected boolean canSpawnStructureAtCoords(int p_75047_1_, int p_75047_2_) + { + + + int k = p_75047_1_; + int l = p_75047_2_; + + if (p_75047_1_ < 0) + { + p_75047_1_ -= this.field_82665_g - 1; + } + + if (p_75047_2_ < 0) + { + p_75047_2_ -= this.field_82665_g - 1; + } + + int i1 = p_75047_1_ / this.field_82665_g; + int j1 = p_75047_2_ / this.field_82665_g; + Random random = this.worldObj.setRandomSeed(i1, j1, 10387312); + i1 *= this.field_82665_g; + j1 *= this.field_82665_g; + i1 += random.nextInt(this.field_82665_g - this.field_82666_h); + j1 += random.nextInt(this.field_82665_g - this.field_82666_h); + + if (k == i1 && l == j1) + { + boolean flag = this.worldObj.getWorldChunkManager().areBiomesViable(k * 16 + 8, l * 16 + 8, 0, villageSpawnBiomes); + + if (flag) + { + Logger.INFO("Found viable biome(s) for custom village"); + return true; + } + } + + return false; + } + + protected StructureStart getStructureStart(int p_75049_1_, int p_75049_2_) + { + return new MapGenExtendedVillage.Start(this.worldObj, this.rand, p_75049_1_, p_75049_2_, this.terrainType); + } + + public static class Start extends StructureStart + { + /** well ... thats what it does */ + private boolean hasMoreThanTwoComponents; + + public Start() { + } + + public Start(World p_i2092_1_, Random p_i2092_2_, int p_i2092_3_, int p_i2092_4_, int p_i2092_5_) + { + super(p_i2092_3_, p_i2092_4_); + Logger.INFO("Trying to Start Village Builder."); + List<?> list = StructureVillagePieces.getStructureVillageWeightedPieceList(p_i2092_2_, p_i2092_5_); + StructureVillagePieces.Start start = new StructureVillagePieces.Start(p_i2092_1_.getWorldChunkManager(), 0, p_i2092_2_, (p_i2092_3_ << 4) + 2, (p_i2092_4_ << 4) + 2, list, p_i2092_5_); + this.components.add(start); + start.buildComponent(start, this.components, p_i2092_2_); + List<?> list1 = start.field_74930_j; + List<?> list2 = start.field_74932_i; + int l; + Logger.INFO("List1: "+list1.size()+" | List2: "+list2.size()); + + while (!list1.isEmpty() || !list2.isEmpty()) + { + Logger.INFO("Iterating non empty list."); + StructureComponent structurecomponent; + + if (list1.isEmpty()) + { + l = p_i2092_2_.nextInt(list2.size()); + structurecomponent = (StructureComponent)list2.remove(l); + structurecomponent.buildComponent(start, this.components, p_i2092_2_); + } + else + { + l = p_i2092_2_.nextInt(list1.size()); + structurecomponent = (StructureComponent)list1.remove(l); + structurecomponent.buildComponent(start, this.components, p_i2092_2_); + } + } + Logger.INFO("Finished iterating lists, updating bounding box for structure."); + + this.updateBoundingBox(); + l = 0; + Iterator iterator = this.components.iterator(); + + while (iterator.hasNext()) + { + Logger.INFO("Iterating Components."); + StructureComponent structurecomponent1 = (StructureComponent)iterator.next(); + + if (!(structurecomponent1 instanceof StructureVillagePieces.Road)) + { + ++l; + } + } + + Logger.INFO("hasMoreThanTwoComponents? "+(l > 2)); + this.hasMoreThanTwoComponents = l > 2; + } + + /** + * currently only defined for Villages, returns true if Village has more than 2 non-road components + */ + public boolean isSizeableStructure() + { + //return this.hasMoreThanTwoComponents; + return true; + } + + public void func_143022_a(NBTTagCompound p_143022_1_) + { + super.func_143022_a(p_143022_1_); + p_143022_1_.setBoolean("Valid", this.hasMoreThanTwoComponents); + } + + public void func_143017_b(NBTTagCompound p_143017_1_) + { + super.func_143017_b(p_143017_1_); + this.hasMoreThanTwoComponents = p_143017_1_.getBoolean("Valid"); + } + } + + /** + * Generates structures in specified chunk next to existing structures. Does *not* generate StructureStarts. + */ + @Override + public boolean generateStructuresInChunk(World p_75051_1_, Random p_75051_2_, int p_75051_3_, int p_75051_4_){ + //Logger.INFO("Try generate Structs in chunk."); + this.callPrivateFunction1(p_75051_1_); + int k = (p_75051_3_ << 4) + 8; + int l = (p_75051_4_ << 4) + 8; + boolean flag = false; + Iterator iterator = this.structureMap.values().iterator(); + + //Logger.INFO("Iteration Size: "+this.structureMap.values().size()); + while (iterator.hasNext()) + { + //Logger.INFO("Iterating."); + StructureStart structurestart = (StructureStart)iterator.next(); + + if (structurestart.isSizeableStructure() && (structurestart.getBoundingBox().intersectsWith(k, l, k + 15, l + 15) || structurestart.getBoundingBox().intersectsWith(k, l, k - 15, l - 15))) + { + Logger.INFO("Iterating. 2"); + structurestart.generateStructure(p_75051_1_, p_75051_2_, new StructureBoundingBox(k, l, k + 15, l + 15)); + flag = true; + this.callPrivateFunction2(structurestart.func_143019_e(), structurestart.func_143018_f(), structurestart); + } + /* else { + Logger.INFO("Iterating. 3"); + Logger.INFO("structurestart.isSizeableStructure()? "+structurestart.isSizeableStructure()); + Logger.INFO("structurestart.getBoundingBox().intersectsWith(k, l, k + 15, l + 15)? "+(structurestart.getBoundingBox().intersectsWith(k, l, k + 15, l + 15) || structurestart.getBoundingBox().intersectsWith(k, l, k - 15, l - 15))); + Logger.INFO("K: "+k+" | L: "+l); + Logger.INFO("structure bounding box info: x-:"+structurestart.getBoundingBox().minX+" y-:"+structurestart.getBoundingBox().minY+" x+:"+structurestart.getBoundingBox().maxX+" y+:"+structurestart.getBoundingBox().maxY); + }*/ + } + + return flag; + } + + Method mMethod1; + Method mMethod2; + private boolean callPrivateFunction1(World aWorld) { + if (mMethod1 == null) { + try { + mMethod1 = MapGenStructure.class.getDeclaredMethod("func_143027_a", World.class); + } catch (NoSuchMethodException | SecurityException e) { + return false; + } + } + if (mMethod1 != null) { + try { + //Logger.INFO("Invoking func_143027_a"); + mMethod1.invoke(this, aWorld); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} + } + return false; + } + + private boolean callPrivateFunction2(int aInt1, int aInt2, StructureStart aStruct) { + if (mMethod2 == null) { + try { + mMethod2 = MapGenStructure.class.getDeclaredMethod("func_143026_a", int.class, int.class, StructureStart.class); + } catch (NoSuchMethodException | SecurityException e) { + return false; + } + } + if (mMethod2 != null) { + try { + Logger.INFO("Invoking func_143026_a"); + mMethod2.invoke(this, aInt1, aInt2, aStruct); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} + } + return false; + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/australia/gen/map/structure/StructureManager.java b/src/Java/gtPlusPlus/australia/gen/map/structure/StructureManager.java new file mode 100644 index 0000000000..b3238a5903 --- /dev/null +++ b/src/Java/gtPlusPlus/australia/gen/map/structure/StructureManager.java @@ -0,0 +1,20 @@ +package gtPlusPlus.australia.gen.map.structure; + +import gtPlusPlus.australia.gen.map.MapGenExtendedVillage; +import gtPlusPlus.australia.gen.map.structure.type.ComponentVillageBank; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.world.gen.structure.MapGenStructureIO; + +public class StructureManager { + + public static void registerVillageComponents() { + try { + //Register Village + MapGenStructureIO.registerStructure(MapGenExtendedVillage.Start.class, "ExtendedVillage"); + + //Register Structures within village + MapGenStructureIO.func_143031_a(ComponentVillageBank.class, CORE.MODID+":"+"Bank"); + } catch (Throwable e) {} + } + +} diff --git a/src/Java/gtPlusPlus/australia/gen/map/structure/type/ComponentVillageBank.java b/src/Java/gtPlusPlus/australia/gen/map/structure/type/ComponentVillageBank.java new file mode 100644 index 0000000000..5b7017aaf0 --- /dev/null +++ b/src/Java/gtPlusPlus/australia/gen/map/structure/type/ComponentVillageBank.java @@ -0,0 +1,175 @@ +package gtPlusPlus.australia.gen.map.structure.type; + +import static net.minecraftforge.common.ChestGenHooks.VILLAGE_BLACKSMITH; + +import java.util.List; +import java.util.Random; + +import gtPlusPlus.api.objects.Logger; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.WeightedRandomChestContent; +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.StructureVillagePieces; +import net.minecraft.world.gen.structure.StructureVillagePieces.House2; +import net.minecraftforge.common.ChestGenHooks; + +public class ComponentVillageBank extends House2 { + + /** List of items that Village's Blacksmith chest can contain. */ + public static final WeightedRandomChestContent[] villageBlacksmithChestContents = new WeightedRandomChestContent[] { + new WeightedRandomChestContent(Items.diamond, 0, 1, 3, 3), + new WeightedRandomChestContent(Items.iron_ingot, 0, 1, 5, 10), + new WeightedRandomChestContent(Items.gold_ingot, 0, 1, 3, 5), + new WeightedRandomChestContent(Items.bread, 0, 1, 3, 15), + new WeightedRandomChestContent(Items.apple, 0, 1, 3, 15), + new WeightedRandomChestContent(Items.iron_pickaxe, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_sword, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_chestplate, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_helmet, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_leggings, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_boots, 0, 1, 1, 5), + new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.obsidian), 0, 3, 7, 5), + new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.sapling), 0, 3, 7, 5), + new WeightedRandomChestContent(Items.saddle, 0, 1, 1, 3), + new WeightedRandomChestContent(Items.iron_horse_armor, 0, 1, 1, 1), + new WeightedRandomChestContent(Items.golden_horse_armor, 0, 1, 1, 1), + new WeightedRandomChestContent(Items.diamond_horse_armor, 0, 1, 1, 1) + }; + + private boolean hasMadeChest; + + public ComponentVillageBank() { + Logger.INFO("Created a Bank."); + } + + public ComponentVillageBank(StructureVillagePieces.Start aStart, int p_i2103_2_, Random aRand, + StructureBoundingBox aBox, int aCoordBaseMode) { + super(aStart, p_i2103_2_, aRand, aBox, aCoordBaseMode); + this.coordBaseMode = aCoordBaseMode; + this.boundingBox = aBox; + } + + public static StructureVillagePieces.House2 func_74915_a(StructureVillagePieces.Start p_74915_0_, List p_74915_1_, + Random p_74915_2_, int p_74915_3_, int p_74915_4_, int p_74915_5_, int p_74915_6_, int p_74915_7_) { + StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(p_74915_3_, + p_74915_4_, p_74915_5_, 0, 0, 0, 10, 6, 7, p_74915_6_); + Logger.INFO("12334453"); + return canVillageGoDeeper(structureboundingbox) + && StructureComponent.findIntersecting(p_74915_1_, structureboundingbox) == null + ? new StructureVillagePieces.House2(p_74915_0_, p_74915_7_, p_74915_2_, structureboundingbox, + p_74915_6_) + : null; + } + + protected void func_143012_a(NBTTagCompound aNBT) { + super.func_143012_a(aNBT); + aNBT.setBoolean("Chest", this.hasMadeChest); + } + + protected void func_143011_b(NBTTagCompound aNBT) { + super.func_143011_b(aNBT); + this.hasMadeChest = aNBT.getBoolean("Chest"); + } + + /** + * second Part of Structure generating, this for example places Spiderwebs, Mob + * Spawners, it closes Mineshafts at the end, it adds Fences... + */ + public boolean addComponentParts(World aWorld, Random aRand, StructureBoundingBox aBox) { + if (this.field_143015_k < 0) { + this.field_143015_k = this.getAverageGroundLevel(aWorld, aBox); + + if (this.field_143015_k < 0) { + return true; + } + + this.boundingBox.offset(0, this.field_143015_k - this.boundingBox.maxY + 6 - 1, 0); + } + + this.fillWithBlocks(aWorld, aBox, 0, 1, 0, 9, 4, 6, Blocks.air, Blocks.air, false); + this.fillWithBlocks(aWorld, aBox, 0, 0, 0, 9, 0, 6, Blocks.cobblestone, Blocks.cobblestone, false); + this.fillWithBlocks(aWorld, aBox, 0, 4, 0, 9, 4, 6, Blocks.cobblestone, Blocks.cobblestone, false); + this.fillWithBlocks(aWorld, aBox, 0, 5, 0, 9, 5, 6, Blocks.stone_slab, Blocks.stone_slab, false); + this.fillWithBlocks(aWorld, aBox, 1, 5, 1, 8, 5, 5, Blocks.air, Blocks.air, false); + this.fillWithBlocks(aWorld, aBox, 1, 1, 0, 2, 3, 0, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 0, 1, 0, 0, 4, 0, Blocks.log, Blocks.log, false); + this.fillWithBlocks(aWorld, aBox, 3, 1, 0, 3, 4, 0, Blocks.log, Blocks.log, false); + this.fillWithBlocks(aWorld, aBox, 0, 1, 6, 0, 4, 6, Blocks.log, Blocks.log, false); + this.placeBlockAtCurrentPosition(aWorld, Blocks.planks, 0, 3, 3, 1, aBox); + this.fillWithBlocks(aWorld, aBox, 3, 1, 2, 3, 3, 2, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 4, 1, 3, 5, 3, 3, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 0, 1, 1, 0, 3, 5, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 1, 1, 6, 5, 3, 6, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 5, 1, 0, 5, 3, 0, Blocks.fence, Blocks.fence, false); + this.fillWithBlocks(aWorld, aBox, 9, 1, 0, 9, 3, 0, Blocks.fence, Blocks.fence, false); + this.fillWithBlocks(aWorld, aBox, 6, 1, 4, 9, 4, 6, Blocks.cobblestone, Blocks.cobblestone, false); + this.placeBlockAtCurrentPosition(aWorld, Blocks.flowing_lava, 0, 7, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.flowing_lava, 0, 8, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.iron_bars, 0, 9, 2, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.iron_bars, 0, 9, 2, 4, aBox); + this.fillWithBlocks(aWorld, aBox, 7, 2, 4, 8, 2, 5, Blocks.air, Blocks.air, false); + this.placeBlockAtCurrentPosition(aWorld, Blocks.cobblestone, 0, 6, 1, 3, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.furnace, 0, 6, 2, 3, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.furnace, 0, 6, 3, 3, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.double_stone_slab, 0, 8, 1, 1, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 0, 2, 2, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 0, 2, 4, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 2, 2, 6, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 4, 2, 6, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.fence, 0, 2, 1, 4, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.wooden_pressure_plate, 0, 2, 2, 4, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.planks, 0, 1, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.oak_stairs, + this.getMetadataWithOffset(Blocks.oak_stairs, 3), 2, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.oak_stairs, + this.getMetadataWithOffset(Blocks.oak_stairs, 1), 1, 1, 4, aBox); + int i; + int j; + + if (!this.hasMadeChest) { + i = this.getYWithOffset(1); + j = this.getXWithOffset(5, 5); + int k = this.getZWithOffset(5, 5); + + if (aBox.isVecInside(j, i, k)) { + this.hasMadeChest = true; + this.generateStructureChestContents(aWorld, aBox, aRand, 5, 1, 5, + ChestGenHooks.getItems(VILLAGE_BLACKSMITH, aRand), + ChestGenHooks.getCount(VILLAGE_BLACKSMITH, aRand)); + } + } + + for (i = 6; i <= 8; ++i) { + if (this.getBlockAtCurrentPosition(aWorld, i, 0, -1, aBox).getMaterial() == Material.air && this + .getBlockAtCurrentPosition(aWorld, i, -1, -1, aBox).getMaterial() != Material.air) { + this.placeBlockAtCurrentPosition(aWorld, Blocks.stone_stairs, + this.getMetadataWithOffset(Blocks.stone_stairs, 3), i, 0, -1, aBox); + } + } + + for (i = 0; i < 7; ++i) { + for (j = 0; j < 10; ++j) { + this.clearCurrentPositionBlocksUpwards(aWorld, j, 6, i, aBox); + this.func_151554_b(aWorld, Blocks.cobblestone, 0, j, -1, i, aBox); + } + } + + this.spawnVillagers(aWorld, aBox, 7, 1, 1, 1); + return true; + } + + /** + * Returns the villager type to spawn in this component, based on the number of + * villagers already spawned. + */ + protected int getVillagerType(int p_74888_1_) { + return 7735; + } + +} |