mirror of
https://github.com/chylex/Hardcore-Ender-Expansion.git
synced 2025-04-14 05:15:42 +02:00
Keep populator order, tweak stuff
This commit is contained in:
parent
83c3a22aeb
commit
c4425fa542
src/main/java/chylex/hee
system/weight
world/feature
@ -1,5 +1,6 @@
|
||||
package chylex.hee.system.weight;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
public class WeightedList<T extends IWeightProvider> extends ArrayList<T>{
|
||||
@ -24,6 +25,13 @@ public class WeightedList<T extends IWeightProvider> extends ArrayList<T>{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> collection){
|
||||
boolean b = super.addAll(collection);
|
||||
recalculateWeight();
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index){
|
||||
T is = super.remove(index);
|
||||
|
@ -5,16 +5,20 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import chylex.hee.block.BlockList;
|
||||
import chylex.hee.item.ItemList;
|
||||
import chylex.hee.system.commands.HeeDebugCommand.HeeTest;
|
||||
import chylex.hee.system.logging.Stopwatch;
|
||||
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.blobs.generators.BlobGeneratorSingle;
|
||||
import chylex.hee.world.feature.blobs.populators.BlobPopulatorPlant;
|
||||
import chylex.hee.world.feature.blobs.populators.BlobPopulatorChest;
|
||||
import chylex.hee.world.feature.blobs.populators.BlobPopulatorHollower;
|
||||
import chylex.hee.world.feature.util.DecoratorFeatureGenerator;
|
||||
import chylex.hee.world.loot.LootItemStack;
|
||||
import chylex.hee.world.loot.WeightedLootList;
|
||||
import chylex.hee.world.util.IRandomAmount;
|
||||
|
||||
public class WorldGenBlob extends WorldGenerator{
|
||||
@ -61,19 +65,29 @@ public class WorldGenBlob extends WorldGenerator{
|
||||
public void run(){
|
||||
WeightedList<BlobPattern> patterns = new WeightedList<>(new BlobPattern[]{
|
||||
new BlobPattern(10).addGenerators(new BlobGenerator[]{
|
||||
new BlobGeneratorSingle(1).rad(7.4D,7.4D)
|
||||
new BlobGeneratorSingle(1).rad(3D,3D)
|
||||
}).addPopulators(new BlobPopulator[]{
|
||||
new BlobPopulatorPlant(1).block(BlockList.death_flower).blockAmount(IRandomAmount.exact,50,50).attempts(90,90).knownBlockLocations()
|
||||
}).setPopulatorAmountProvider(IRandomAmount.exact,1,1)
|
||||
new BlobPopulatorHollower(1),
|
||||
new BlobPopulatorChest(1).loot(new WeightedLootList(new LootItemStack[]{ new LootItemStack(ItemList.end_powder).setWeight(1) }),IRandomAmount.preferSmaller,3,12).onlyInside()
|
||||
}).setPopulatorAmountProvider(IRandomAmount.exact,2,2)
|
||||
});
|
||||
|
||||
|
||||
DecoratorFeatureGenerator gen = new DecoratorFeatureGenerator();
|
||||
Pair<BlobGenerator,List<BlobPopulator>> pattern = patterns.getRandomItem(world.rand).generatePattern(world.rand);
|
||||
|
||||
Stopwatch.time("WorldGenBlob - test blob generator");
|
||||
pattern.getLeft().generate(gen,world.rand);
|
||||
for(BlobPopulator populator:pattern.getRight())populator.generate(gen,world.rand);
|
||||
Stopwatch.finish("WorldGenBlob - test blob generator");
|
||||
|
||||
Stopwatch.time("WorldGenBlob - test pattern generator");
|
||||
for(BlobPopulator populator:pattern.getRight())populator.generate(gen,world.rand);
|
||||
Stopwatch.finish("WorldGenBlob - test pattern generator");
|
||||
|
||||
Stopwatch.time("WorldGenBlob - test generate");
|
||||
gen.generate(world,world.rand,(int)player.posX+10,(int)player.posY-5,(int)player.posZ);
|
||||
Stopwatch.finish("WorldGenBlob - test generate");
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package chylex.hee.world.feature.blobs;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@ -14,6 +16,13 @@ public final class BlobPattern implements IWeightProvider{
|
||||
private IRandomAmount populatorAmountGen;
|
||||
private int minPopulatorAmount, maxPopulatorAmount;
|
||||
|
||||
private final Comparator<BlobPopulator> populatorSorter = new Comparator<BlobPopulator>(){
|
||||
@Override
|
||||
public int compare(BlobPopulator pop1, BlobPopulator pop2){
|
||||
return populators.indexOf(pop1) < populators.indexOf(pop2) ? -1 : 1; // never equal
|
||||
}
|
||||
};
|
||||
|
||||
public BlobPattern(int weight){
|
||||
this.weight = weight;
|
||||
}
|
||||
@ -39,9 +48,16 @@ public final class BlobPattern implements IWeightProvider{
|
||||
List<BlobPopulator> chosenPopulators = new ArrayList<>();
|
||||
|
||||
if (populatorAmountGen != null && !populators.isEmpty()){
|
||||
for(int a = 0, amount = populatorAmountGen.generate(rand,minPopulatorAmount,maxPopulatorAmount); a < amount; a++){
|
||||
chosenPopulators.add(populators.getRandomItem(rand));
|
||||
WeightedList<BlobPopulator> blobPopulators = new WeightedList<>();
|
||||
blobPopulators.addAll(populators);
|
||||
|
||||
for(int a = 0, amount = populatorAmountGen.generate(rand,minPopulatorAmount,maxPopulatorAmount); a < amount && !blobPopulators.isEmpty(); a++){
|
||||
BlobPopulator populator = blobPopulators.getRandomItem(rand);
|
||||
chosenPopulators.add(populator);
|
||||
blobPopulators.remove(populator);
|
||||
}
|
||||
|
||||
Collections.sort(chosenPopulators,populatorSorter);
|
||||
}
|
||||
|
||||
return Pair.of(generators.getRandomItem(rand),chosenPopulators);
|
||||
|
@ -40,15 +40,14 @@ public class BlobPopulatorChest extends BlobPopulator implements ITileEntityGene
|
||||
@Override
|
||||
public void generate(DecoratorFeatureGenerator gen, Random rand){
|
||||
List<BlockLocation> locs = gen.getUsedLocations();
|
||||
if (locs.isEmpty())return;
|
||||
|
||||
for(int attempt = 0; attempt < 100; attempt++){
|
||||
BlockLocation loc = locs.get(rand.nextInt(locs.size()));
|
||||
while(!locs.isEmpty()){
|
||||
BlockLocation loc = locs.remove(rand.nextInt(locs.size()));
|
||||
|
||||
if (gen.getBlock(loc.x,loc.y,loc.z) == Blocks.end_stone && gen.getBlock(loc.x,loc.y+1,loc.z) == Blocks.air && gen.getBlock(loc.x,loc.y+2,loc.z) == Blocks.air){
|
||||
if (onlyInside && gen.getTopBlockY(loc.x,loc.z) > loc.y+2)continue;
|
||||
if (onlyInside && gen.getTopBlockY(loc.x,loc.z) < loc.y+2)continue;
|
||||
|
||||
gen.setBlock(loc.x,loc.y+1,loc.z,Blocks.chest);
|
||||
gen.setBlock(loc.x,loc.y+1,loc.z,Blocks.chest,rand.nextInt(4));
|
||||
gen.setTileEntity(loc.x,loc.y+1,loc.z,this);
|
||||
break;
|
||||
}
|
||||
|
@ -66,7 +66,11 @@ public final class DecoratorFeatureGenerator{
|
||||
|
||||
public List<BlockLocation> getUsedLocations(){
|
||||
List<BlockLocation> locs = new ArrayList<>();
|
||||
for(GeneratedBlock block:blocks.valueCollection())locs.add(new BlockLocation(block.x,block.y,block.z));
|
||||
|
||||
for(GeneratedBlock block:blocks.valueCollection()){
|
||||
if (block.block != Blocks.air)locs.add(new BlockLocation(block.x,block.y,block.z));
|
||||
}
|
||||
|
||||
return locs;
|
||||
}
|
||||
|
||||
@ -82,11 +86,18 @@ public final class DecoratorFeatureGenerator{
|
||||
if (randX > 0)centerX += rand.nextInt(randX*2)-randX;
|
||||
if (randZ > 0)centerZ += rand.nextInt(randZ*2)-randZ;
|
||||
|
||||
for(GeneratedBlock block:blocks.valueCollection())world.setBlock(centerX+block.x,centerY+block.y,centerZ+block.z,block.block,block.metadata,3);
|
||||
List<GeneratedBlock> delayed = new ArrayList<>();
|
||||
|
||||
for(GeneratedBlock block:blocks.valueCollection()){
|
||||
if (!block.block.canBlockStay(world,centerX+block.x,centerY+block.y,centerZ+block.z))delayed.add(block);
|
||||
else world.setBlock(centerX+block.x,centerY+block.y,centerZ+block.z,block.block,block.metadata,3);
|
||||
}
|
||||
|
||||
for(GeneratedBlock block:delayed)world.setBlock(centerX+block.x,centerY+block.y,centerZ+block.z,block.block,block.metadata,3);
|
||||
|
||||
for(Entry<BlockLocation,ITileEntityGenerator> entry:tileEntities.entrySet()){
|
||||
BlockLocation loc = entry.getKey();
|
||||
entry.getValue().onTileEntityRequested("",world.getTileEntity(loc.x,loc.y,loc.z),rand);
|
||||
entry.getValue().onTileEntityRequested("",world.getTileEntity(centerX+loc.x,centerY+loc.y,centerZ+loc.z),rand);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user