1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion.git synced 2025-04-14 05:15:42 +02:00

Blob pattern system!

This commit is contained in:
chylex 2014-10-23 09:29:38 +02:00
parent ea32488e5d
commit 5aaad79337
18 changed files with 178 additions and 47 deletions

View File

@ -120,7 +120,7 @@ public class DragonAttackManager{
EntityPlayer p = (EntityPlayer)o;
if ((nocreative && p.capabilities.isCreativeMode) || p.isDead)continue;
players.add(new ObjectWeightPair<EntityPlayer>(p,5+((int)p.getHealth()>>1)+(p.getTotalArmorValue()>>2)));
players.add(ObjectWeightPair.of(p,5+((int)p.getHealth()>>1)+(p.getTotalArmorValue()>>2)));
}
return players.getRandomItem(rand).getObject();

View File

@ -270,7 +270,7 @@ public class DragonEssenceHandler extends AltarActionHandler{
Enchantment e = Enchantment.enchantmentsList[enchants.getCompoundTagAt(a).getShort("id")];
if (e == null)continue;
list.add(new ObjectWeightPair<Enchantment>(e,e.getWeight()));
list.add(ObjectWeightPair.of(e,e.getWeight()));
}
Enchantment chosenEnchantment = list.getRandomItem(rand).getObject();

View File

@ -38,6 +38,10 @@ public final class MathUtil{
return Math.sqrt(xDiff*xDiff+yDiff*yDiff+zDiff*zDiff);
}
public static double distanceSquared(double xDiff, double yDiff, double zDiff){
return xDiff*xDiff+yDiff*yDiff+zDiff*zDiff;
}
public static boolean triangle(int xx, int yy, int x1, int y1, int x2, int y2, int x3, int y3){
int a0, a1, a2, a3;
a0 = Math.abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));

View File

@ -1,14 +1,14 @@
package chylex.hee.system.weight;
public class ObjectWeightPair<T> implements IWeightProvider{
public static <T> ObjectWeightPair<T> make(T obj, int weight){
public static <T> ObjectWeightPair<T> of(T obj, int weight){
return new ObjectWeightPair<T>(obj,weight);
}
private T obj;
private int weight;
public ObjectWeightPair(T obj, int weight){
private ObjectWeightPair(T obj, int weight){
this.obj = obj;
this.weight = weight;
}

View File

@ -1,11 +1,45 @@
package chylex.hee.world.feature;
import java.util.List;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import org.apache.commons.lang3.tuple.Pair;
import chylex.hee.system.weight.ObjectWeightPair;
import chylex.hee.system.weight.WeightedList;
import chylex.hee.world.feature.blobs.BlobGenerator;
import chylex.hee.world.feature.blobs.BlobPattern;
import chylex.hee.world.feature.blobs.BlobPopulator;
import chylex.hee.world.feature.util.DecoratorFeatureGenerator;
public class WorldGenBlob extends WorldGenerator{
private enum BlobType{
COMMON, UNCOMMON, RARE;
BlobPattern[] patterns;
}
private static final WeightedList<ObjectWeightPair<BlobType>> types = new WeightedList<>();
static{
types.add(ObjectWeightPair.of(BlobType.COMMON,20));
types.add(ObjectWeightPair.of(BlobType.UNCOMMON,4));
types.add(ObjectWeightPair.of(BlobType.RARE,1));
BlobType.COMMON.patterns = new BlobPattern[]{
};
}
private DecoratorFeatureGenerator gen = new DecoratorFeatureGenerator();
@Override
public boolean generate(World world, Random rand, int x, int y, int z){
BlobPattern[] patterns = types.getRandomItem(rand).getObject().patterns;
Pair<BlobGenerator,List<BlobPopulator>> pattern = patterns[rand.nextInt(patterns.length)].generatePattern(rand);
pattern.getLeft().generate(gen,rand);
for(BlobPopulator populator:pattern.getRight())populator.generate(gen,rand);
return false;
}
}

View File

@ -11,12 +11,12 @@ import net.minecraft.world.gen.feature.WorldGenerator;
import chylex.hee.block.BlockList;
import chylex.hee.system.logging.Log;
import chylex.hee.system.util.MathUtil;
import chylex.hee.world.feature.blobs.CavePopulator;
import chylex.hee.world.feature.blobs.FlowerPopulator;
import chylex.hee.world.feature.blobs.LakePopulator;
import chylex.hee.world.feature.blobs.ObsidianSpikePopulator;
import chylex.hee.world.feature.blobs.OrePopulator;
import chylex.hee.world.feature.blobs.Populator;
import chylex.hee.world.feature.blobs.old.CavePopulator;
import chylex.hee.world.feature.blobs.old.FlowerPopulator;
import chylex.hee.world.feature.blobs.old.LakePopulator;
import chylex.hee.world.feature.blobs.old.ObsidianSpikePopulator;
import chylex.hee.world.feature.blobs.old.OrePopulator;
import chylex.hee.world.feature.blobs.old.Populator;
import chylex.hee.world.util.BlockLocation;
import chylex.hee.world.util.WorldGeneratorBlockList;

View File

@ -0,0 +1,24 @@
package chylex.hee.world.feature.blobs;
import java.util.Random;
import net.minecraft.init.Blocks;
import chylex.hee.system.util.MathUtil;
import chylex.hee.world.feature.util.DecoratorFeatureGenerator;
public abstract class BlobGenerator{
public abstract void generate(DecoratorFeatureGenerator gen, Random rand);
protected final void genBlob(DecoratorFeatureGenerator gen, double x, double y, double z, double rad){
double radSq = MathUtil.square(rad+0.5D);
int size = (int)Math.ceil(rad), ix = (int)Math.floor(x), iy = (int)Math.floor(y), iz = (int)Math.floor(z);
for(int xx = ix-size; xx <= ix+size; xx++){
for(int yy = iy-size; yy <= iy+size; yy++){
for(int zz = iz-size; zz <= iz+size; zz++){
if (MathUtil.distanceSquared(xx-x,yy-y,zz-z) <= radSq){
gen.setBlock(xx,yy,zz,Blocks.end_stone);
}
}
}
}
}
}

View File

@ -0,0 +1,44 @@
package chylex.hee.world.feature.blobs;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang3.tuple.Pair;
import chylex.hee.system.weight.ObjectWeightPair;
import chylex.hee.system.weight.WeightedList;
public final class BlobPattern{
private final WeightedList<ObjectWeightPair<BlobGenerator>> generators = new WeightedList<>();
private final WeightedList<ObjectWeightPair<BlobPopulator>> populators = new WeightedList<>();
private IPopulatorAmountProvider populatorAmountProvider;
public BlobPattern(){}
public BlobPattern addGenerator(BlobGenerator generator, int weight){
generators.add(ObjectWeightPair.of(generator,weight));
return this;
}
public BlobPattern addPopulator(BlobPopulator populator, int weight){
populators.add(ObjectWeightPair.of(populator,weight));
return this;
}
public BlobPattern setPopulatorAmountProvider(IPopulatorAmountProvider provider){
this.populatorAmountProvider = provider;
return this;
}
public Pair<BlobGenerator,List<BlobPopulator>> generatePattern(Random rand){
List<BlobPopulator> chosenPopulators = new ArrayList<>();
for(int a = 0, amount = populatorAmountProvider.getPopulatorAmount(rand,populators.size()); a < amount; a++){
chosenPopulators.add(populators.getRandomItem(rand).getObject());
}
return Pair.of(generators.getRandomItem(rand).getObject(),chosenPopulators);
}
public static interface IPopulatorAmountProvider{
int getPopulatorAmount(Random rand, int totalAmount);
}
}

View File

@ -0,0 +1,7 @@
package chylex.hee.world.feature.blobs;
import java.util.Random;
import chylex.hee.world.feature.util.DecoratorFeatureGenerator;
public abstract class BlobPopulator{
public abstract void generate(DecoratorFeatureGenerator gen, Random rand);
}

View File

@ -0,0 +1,18 @@
package chylex.hee.world.feature.blobs.generators;
import java.util.Random;
import chylex.hee.world.feature.blobs.BlobGenerator;
import chylex.hee.world.feature.util.DecoratorFeatureGenerator;
public class BlobGeneratorSingle extends BlobGenerator{
private final double minRad, maxRad;
public BlobGeneratorSingle(double minRad, double maxRad){
this.minRad = minRad;
this.maxRad = maxRad;
}
@Override
public void generate(DecoratorFeatureGenerator gen, Random rand){
genBlob(gen,0D,0D,0D,minRad+rand.nextDouble()*(maxRad-minRad));
}
}

View File

@ -1,4 +1,4 @@
package chylex.hee.world.feature.blobs;
package chylex.hee.world.feature.blobs.old;
import java.util.Random;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

View File

@ -1,4 +1,4 @@
package chylex.hee.world.feature.blobs;
package chylex.hee.world.feature.blobs.old;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.world.World;

View File

@ -1,4 +1,4 @@
package chylex.hee.world.feature.blobs;
package chylex.hee.world.feature.blobs.old;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;

View File

@ -1,4 +1,4 @@
package chylex.hee.world.feature.blobs;
package chylex.hee.world.feature.blobs.old;
import java.util.Random;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;

View File

@ -1,4 +1,4 @@
package chylex.hee.world.feature.blobs;
package chylex.hee.world.feature.blobs.old;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.util.MathHelper;

View File

@ -1,4 +1,4 @@
package chylex.hee.world.feature.blobs;
package chylex.hee.world.feature.blobs.old;
import java.util.Random;
import net.minecraft.block.Block;

View File

@ -65,10 +65,10 @@ public final class RavagedDungeonPlacer implements ITileEntityGenerator{
}
private static final WeightedList<ObjectWeightPair<EnumDescendDesign>> descendDesignList = new WeightedList<>(
ObjectWeightPair.make(EnumDescendDesign.PILLARS_WITH_SPAWNER, 50),
ObjectWeightPair.make(EnumDescendDesign.FENCE_LIGHTS, 42),
ObjectWeightPair.make(EnumDescendDesign.GOO_CORNERS, 35),
ObjectWeightPair.make(EnumDescendDesign.CORNER_LIGHTS, 25)
ObjectWeightPair.of(EnumDescendDesign.PILLARS_WITH_SPAWNER, 50),
ObjectWeightPair.of(EnumDescendDesign.FENCE_LIGHTS, 42),
ObjectWeightPair.of(EnumDescendDesign.GOO_CORNERS, 35),
ObjectWeightPair.of(EnumDescendDesign.CORNER_LIGHTS, 25)
);
public void generateDescend(LargeStructureWorld world, Random rand, int x, int y, int z, DungeonElement descend){
@ -201,17 +201,17 @@ public final class RavagedDungeonPlacer implements ITileEntityGenerator{
}
private static final WeightedList<ObjectWeightPair<EnumHallwayDesign>> hallwayDesignList = new WeightedList<>(
ObjectWeightPair.make(EnumHallwayDesign.NONE, 88),
ObjectWeightPair.make(EnumHallwayDesign.DEAD_END_CHEST, 45),
ObjectWeightPair.make(EnumHallwayDesign.DESTROYED_WALLS, 44),
ObjectWeightPair.make(EnumHallwayDesign.EMBEDDED_CHEST, 33),
ObjectWeightPair.make(EnumHallwayDesign.STAIR_PATTERN, 32),
ObjectWeightPair.make(EnumHallwayDesign.COBWEBS, 24),
ObjectWeightPair.make(EnumHallwayDesign.SPAWNERS_IN_WALLS, 24),
ObjectWeightPair.make(EnumHallwayDesign.FLOOR_CEILING_SLABS, 21),
ObjectWeightPair.make(EnumHallwayDesign.WALL_MOUNTED_SPAWNERS, 19),
ObjectWeightPair.make(EnumHallwayDesign.FLOWER_POT, 16),
ObjectWeightPair.make(EnumHallwayDesign.LAPIS_BLOCK, 4)
ObjectWeightPair.of(EnumHallwayDesign.NONE, 88),
ObjectWeightPair.of(EnumHallwayDesign.DEAD_END_CHEST, 45),
ObjectWeightPair.of(EnumHallwayDesign.DESTROYED_WALLS, 44),
ObjectWeightPair.of(EnumHallwayDesign.EMBEDDED_CHEST, 33),
ObjectWeightPair.of(EnumHallwayDesign.STAIR_PATTERN, 32),
ObjectWeightPair.of(EnumHallwayDesign.COBWEBS, 24),
ObjectWeightPair.of(EnumHallwayDesign.SPAWNERS_IN_WALLS, 24),
ObjectWeightPair.of(EnumHallwayDesign.FLOOR_CEILING_SLABS, 21),
ObjectWeightPair.of(EnumHallwayDesign.WALL_MOUNTED_SPAWNERS, 19),
ObjectWeightPair.of(EnumHallwayDesign.FLOWER_POT, 16),
ObjectWeightPair.of(EnumHallwayDesign.LAPIS_BLOCK, 4)
);
public void generateHallway(LargeStructureWorld world, Random rand, int x, int y, int z, DungeonElement hallway){
@ -464,15 +464,15 @@ public final class RavagedDungeonPlacer implements ITileEntityGenerator{
}
private static final WeightedList<ObjectWeightPair<EnumRoomDesign>> roomDesignList = new WeightedList<>(
ObjectWeightPair.make(EnumRoomDesign.GOO_FOUNTAINS, 56),
ObjectWeightPair.make(EnumRoomDesign.RUINS, 56),
ObjectWeightPair.make(EnumRoomDesign.BOWLS, 54),
ObjectWeightPair.make(EnumRoomDesign.FOUR_SPAWNERS, 51),
ObjectWeightPair.make(EnumRoomDesign.SCATTERED_SPAWNERS_WITH_COAL, 44),
ObjectWeightPair.make(EnumRoomDesign.GLOWING_ROOM, 35),
ObjectWeightPair.make(EnumRoomDesign.CARPET_TARGET, 26),
ObjectWeightPair.make(EnumRoomDesign.ENCASED_CUBICLE, 20),
ObjectWeightPair.make(EnumRoomDesign.TERRARIUM, 17)
ObjectWeightPair.of(EnumRoomDesign.GOO_FOUNTAINS, 56),
ObjectWeightPair.of(EnumRoomDesign.RUINS, 56),
ObjectWeightPair.of(EnumRoomDesign.BOWLS, 54),
ObjectWeightPair.of(EnumRoomDesign.FOUR_SPAWNERS, 51),
ObjectWeightPair.of(EnumRoomDesign.SCATTERED_SPAWNERS_WITH_COAL, 44),
ObjectWeightPair.of(EnumRoomDesign.GLOWING_ROOM, 35),
ObjectWeightPair.of(EnumRoomDesign.CARPET_TARGET, 26),
ObjectWeightPair.of(EnumRoomDesign.ENCASED_CUBICLE, 20),
ObjectWeightPair.of(EnumRoomDesign.TERRARIUM, 17)
);
private void generateRoomLayout(LargeStructureWorld world, Random rand, int x, int y, int z){

View File

@ -14,13 +14,13 @@ public class StructureMiningSpot extends AbstractIslandStructure{
public void regenerateOreWeightList(Random rand){
oreWeights = new WeightedList<>(
ObjectWeightPair.make(Blocks.emerald_ore,8),
ObjectWeightPair.make(Blocks.lapis_ore,8),
ObjectWeightPair.make(Blocks.redstone_ore,11),
ObjectWeightPair.make(Blocks.diamond_ore,14),
ObjectWeightPair.make(Blocks.coal_ore,20),
ObjectWeightPair.make(Blocks.gold_ore,25),
ObjectWeightPair.make(Blocks.iron_ore,26)
ObjectWeightPair.of(Blocks.emerald_ore,8),
ObjectWeightPair.of(Blocks.lapis_ore,8),
ObjectWeightPair.of(Blocks.redstone_ore,11),
ObjectWeightPair.of(Blocks.diamond_ore,14),
ObjectWeightPair.of(Blocks.coal_ore,20),
ObjectWeightPair.of(Blocks.gold_ore,25),
ObjectWeightPair.of(Blocks.iron_ore,26)
);
for(int a = 0; a < 1+rand.nextInt(2); a++)oreWeights.remove(rand.nextInt(oreWeights.size()));