This commit is contained in:
gnembon committed 2019-05-23 15:59:43 -03:00
1 parent b257e6f984
commit e3c0edae3c
14 files changed
+501 -326

No files matched your search

@@ -0,0 +1,12 @@
package carpet.fakes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorConfig;
public interface StructureFeatureInterface
{
public boolean plopAnywhere(IWorld world, BlockPos pos);
public boolean plopAnywhere(IWorld world, BlockPos pos, ChunkGenerator<? extends ChunkGeneratorConfig> generator);
}
@@ -0,0 +1,202 @@
package carpet.helpers;
import carpet.CarpetSettings;
import carpet.fakes.StructureFeatureInterface;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.VanillaLayeredBiomeSource;
import net.minecraft.world.biome.source.VanillaLayeredBiomeSourceConfig;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.OverworldChunkGenerator;
import net.minecraft.world.gen.chunk.OverworldChunkGeneratorConfig;
import net.minecraft.world.gen.feature.BoulderFeatureConfig;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.DoublePlantFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.IcebergFeatureConfig;
import net.minecraft.world.gen.feature.JungleGroundBushFeature;
import net.minecraft.world.gen.feature.LakeFeatureConfig;
import net.minecraft.world.gen.feature.MineshaftFeature;
import net.minecraft.world.gen.feature.MineshaftFeatureConfig;
import net.minecraft.world.gen.feature.OceanRuinFeature;
import net.minecraft.world.gen.feature.OceanRuinFeatureConfig;
import net.minecraft.world.gen.feature.PlantedFeatureConfig;
import net.minecraft.world.gen.feature.SeaPickleFeatureConfig;
import net.minecraft.world.gen.feature.SeagrassFeatureConfig;
import net.minecraft.world.gen.feature.ShipwreckFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import net.minecraft.world.gen.feature.VillageFeatureConfig;
import java.util.HashMap;
import java.util.Map;
public class FeatureGenerator
{
@FunctionalInterface
private interface Thing
{
Boolean plop(World world, BlockPos pos);
}
private static Thing simplePlop(Feature<DefaultFeatureConfig> feature)
{
return simplePlop(feature, FeatureConfig.DEFAULT);
}
private static Thing simplePlop(Feature feature, FeatureConfig config)
{
return (w, p) -> {
CarpetSettings.skipGenerationChecks=true;
boolean res = feature.generate(w, w.getChunkManager().getChunkGenerator(), w.random, p, config);
CarpetSettings.skipGenerationChecks=false;
return res;
};
}
private static Thing spawnCustomStructure(StructureFeature structure, FeatureConfig conf, Biome biome)
{
return (w, p) -> {
ChunkGenerator chunkgen = new OverworldChunkGenerator(w, null, new OverworldChunkGeneratorConfig())
{
@Override
public <C extends FeatureConfig> C getStructureConfig(Biome biome_1, StructureFeature<C> structureFeature_1)
{
return (C)conf;
}
@Override
public BiomeSource getBiomeSource()
{
return new VanillaLayeredBiomeSource(new VanillaLayeredBiomeSourceConfig().setLevelProperties(w.getLevelProperties()))
{
@Override
public Biome getBiome(int i, int j)
{
return biome;
}
};
}
};
return ((StructureFeatureInterface)structure).plopAnywhere(w, p, chunkgen);
};
}
public static Boolean spawn(String name, World world, BlockPos pos)
{
if (featureMap.containsKey(name))
return featureMap.get(name).plop(world, pos);
return null;
}
private static Map<String, Thing> featureMap = new HashMap<String, Thing>() {{
put("oak", simplePlop(Feature.NORMAL_TREE));
put("oak_large", simplePlop(Feature.FANCY_TREE));
put("birch", simplePlop(Feature.BIRCH_TREE));
put("birch_large", simplePlop(Feature.SUPER_BIRCH_TREE));
put("shrub", simplePlop(Feature.JUNGLE_GROUND_BUSH));
put("shrub_acacia", simplePlop(new JungleGroundBushFeature((d) -> FeatureConfig.DEFAULT, Blocks.ACACIA_WOOD.getDefaultState(), Blocks.ACACIA_LEAVES.getDefaultState())));
put("shrub_birch", simplePlop(new JungleGroundBushFeature((d) -> FeatureConfig.DEFAULT, Blocks.BIRCH_WOOD.getDefaultState(), Blocks.BIRCH_LEAVES.getDefaultState())));
put("shrub_snowy", simplePlop(new JungleGroundBushFeature((d) -> FeatureConfig.DEFAULT, Blocks.BONE_BLOCK.getDefaultState(), Blocks.COBWEB.getDefaultState())));
put("jungle", simplePlop(Feature.JUNGLE_TREE));
put("spruce_matchstick", simplePlop(Feature.PINE_TREE));
put("dark_oak", simplePlop(Feature.DARK_OAK_TREE));
put("acacia", simplePlop(Feature.SAVANNA_TREE));
put("spruce", simplePlop(Feature.SPRUCE_TREE));
put("oak_swamp", simplePlop(Feature.SWAMP_TREE));
put("jungle_large", simplePlop(Feature.MEGA_JUNGLE_TREE));
//put("spruce_matchstick_large", simplePlop(Feature.MEGA_PINE_TREE));??
put("spruce_large", simplePlop(Feature.MEGA_SPRUCE_TREE));
put("well", simplePlop(Feature.DESERT_WELL));
put("grass_jungle", simplePlop(Feature.JUNGLE_GRASS));
put("fern", simplePlop(Feature.TAIGA_GRASS));
put("grass", simplePlop(Feature.DOUBLE_PLANT, new DoublePlantFeatureConfig(Blocks.TALL_GRASS.getDefaultState())));
//put("", simplePlop(Feature.));
//put("", simplePlop(Feature.));
//put("", simplePlop(Feature.));
//put("", simplePlop(Feature.));
put("cactus", simplePlop(Feature.CACTUS));
put("dead_bush", simplePlop(Feature.DEAD_BUSH));
put("fossils", simplePlop(Feature.FOSSIL)); // spawn above, spawn invisible
put("mushroom_brown", simplePlop(Feature.HUGE_BROWN_MUSHROOM, new PlantedFeatureConfig(false)));
put("mushroom_red", simplePlop(Feature.HUGE_RED_MUSHROOM, new PlantedFeatureConfig(false)));
put("ice_spike", simplePlop(Feature.ICE_SPIKE));
put("glowstone", simplePlop(Feature.GLOWSTONE_BLOB));
put("melon", simplePlop(Feature.MELON));
put("pumpkin", simplePlop(Feature.PUMPKIN));
put("sugarcane", simplePlop(Feature.REED));
put("lilypad", simplePlop(Feature.WATERLILY));
put("dungeon", simplePlop(Feature.MONSTER_ROOM));
put("iceberg", simplePlop(Feature.ICEBERG, new IcebergFeatureConfig(Blocks.PACKED_ICE.getDefaultState())));
put("iceberg_blue", simplePlop(Feature.ICEBERG, new IcebergFeatureConfig(Blocks.BLUE_ICE.getDefaultState())));
put("lake", simplePlop(Feature.LAKE, new LakeFeatureConfig(Blocks.WATER.getDefaultState())));
put("lake_lava", simplePlop(Feature.LAKE, new LakeFeatureConfig(Blocks.LAVA.getDefaultState())));
//put("end tower", simplePlop(Feature.END_CRYSTAL_TOWER)); // requires more complex setup
put("end_island", simplePlop(Feature.END_ISLAND));
put("chorus", simplePlop(Feature.CHORUS_PLANT));
put("sea_grass", simplePlop(Feature.SEAGRASS, new SeagrassFeatureConfig(80, 0.8D)));
put("sea_grass_river", simplePlop(Feature.SEAGRASS, new SeagrassFeatureConfig(48, 0.4D)));
put("kelp", simplePlop(Feature.KELP));
put("coral_tree", simplePlop(Feature.CORAL_TREE));
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM));
put("coral_claw", simplePlop(Feature.CORAL_CLAW));
put("coral", (w, p) ->
w.random.nextInt(3)!=0?
(w.random.nextInt(2)!=0?
simplePlop(Feature.CORAL_MUSHROOM).plop(w, p):
simplePlop(Feature.CORAL_TREE).plop(w, p))
:simplePlop(Feature.CORAL_CLAW).plop(w, p));
put("sea_pickle", simplePlop(Feature.SEA_PICKLE, new SeaPickleFeatureConfig(20)));
put("boulder", simplePlop(Feature.FOREST_ROCK, new BoulderFeatureConfig(Blocks.MOSSY_COBBLESTONE.getDefaultState(), 0)));
//structures
put("monument", ((StructureFeatureInterface)Feature.OCEAN_MONUMENT)::plopAnywhere);
put("fortress", ((StructureFeatureInterface)Feature.NETHER_BRIDGE)::plopAnywhere);
put("mansion", ((StructureFeatureInterface)Feature.WOODLAND_MANSION)::plopAnywhere);
put("jungle_temple", ((StructureFeatureInterface)Feature.JUNGLE_TEMPLE)::plopAnywhere);
put("desert_temple", ((StructureFeatureInterface)Feature.DESERT_PYRAMID)::plopAnywhere);
put("end_city", ((StructureFeatureInterface)Feature.END_CITY)::plopAnywhere);
put("igloo", ((StructureFeatureInterface)Feature.IGLOO)::plopAnywhere);
put("shipwreck", spawnCustomStructure(Feature.SHIPWRECK, new ShipwreckFeatureConfig(true), Biomes.PLAINS));
put("shipwreck2", spawnCustomStructure(Feature.SHIPWRECK, new ShipwreckFeatureConfig(false), Biomes.PLAINS));
put("witchhut", ((StructureFeatureInterface)Feature.SWAMP_HUT)::plopAnywhere);
put("stronghold", ((StructureFeatureInterface)Feature.STRONGHOLD)::plopAnywhere);
put("oceanruin_small", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 0.0F, 0.5F), Biomes.PLAINS));
put("oceanruin_warm_small", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 0.0F, 0.5F), Biomes.PLAINS));
put("oceanruin_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 1.0F, 0.0F), Biomes.PLAINS));
put("oceanruin_warm_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 1.0F, 0.0F), Biomes.PLAINS));
put("oceanruin", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 1.0F, 1.0F), Biomes.PLAINS));
put("oceanruin_warm", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 1.0F, 1.0F), Biomes.PLAINS));
put("treasure", ((StructureFeatureInterface)Feature.BURIED_TREASURE)::plopAnywhere);
put("mineshaft", spawnCustomStructure(Feature.MINESHAFT, new MineshaftFeatureConfig(0.0, MineshaftFeature.Type.NORMAL), Biomes.PLAINS));
put("mineshaft_mesa", spawnCustomStructure(Feature.MINESHAFT, new MineshaftFeatureConfig(0.0, MineshaftFeature.Type.MESA), Biomes.PLAINS));
put("village", spawnCustomStructure(Feature.VILLAGE, new VillageFeatureConfig("village/plains/town_centers",6), Biomes.PLAINS));
put("village_desert", spawnCustomStructure(Feature.VILLAGE, new VillageFeatureConfig("village/desert/town_centers", 6), Biomes.PLAINS));
put("village_savanna", spawnCustomStructure(Feature.VILLAGE, new VillageFeatureConfig("village/savanna/town_centers", 6), Biomes.PLAINS));
put("village_taiga", spawnCustomStructure(Feature.VILLAGE, new VillageFeatureConfig("village/taiga/town_centers", 6), Biomes.PLAINS));
put("village_snowy", spawnCustomStructure(Feature.VILLAGE, new VillageFeatureConfig("village/snowy/town_centers", 6), Biomes.PLAINS));
}};
}
@@ -1,203 +0,0 @@
package carpet.helpers;
import carpet.CarpetSettings;
import net.minecraft.init.Biomes;
import net.minecraft.init.Blocks;
import net.minecraft.structure.Structure;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.biome.provider.OverworldBiomeProvider;
import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings;
import net.minecraft.world.gen.ChunkGeneratorOverworld;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.OverworldGenSettings;
import net.minecraft.world.gen.feature.BlockBlobConfig;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.IcebergConfig;
import net.minecraft.world.gen.feature.LakesConfig;
import net.minecraft.world.gen.feature.OceanRuinFeature;
import net.minecraft.world.gen.feature.SeaGrassConfig;
import net.minecraft.world.gen.feature.ShrubFeature;
import net.minecraft.world.gen.feature.TallGrassConfig;
import net.minecraft.world.gen.feature.TallGrassFeature;
import net.minecraft.world.gen.feature.structure.MineshaftConfig;
import net.minecraft.world.gen.feature.structure.MineshaftStructure;
import net.minecraft.world.gen.feature.structure.OceanRuinConfig;
import net.minecraft.structure.OceanRuinGenerator;
import net.minecraft.world.gen.feature.structure.ShipwreckConfig;
import net.minecraft.structure.Structure;
import net.minecraft.world.gen.feature.structure.VillageConfig;
import net.minecraft.world.gen.feature.structure.VillagePieces;
import net.minecraft.world.gen.placement.CountConfig;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
public class FeatureGenerator
{
@FunctionalInterface
private interface Thing
{
Boolean plop(World world, BlockPos pos);
}
private static Thing simplePlop(Feature<DefaultFeatureConfig> feature)
{
return simplePlop(feature, FeatureConfig.DEFAULT);
}
private static Thing simplePlop(Feature feature, FeatureConfig config)
{
return (w, p) -> {
CarpetSettings.skipGenerationChecks=true;
boolean res = feature.generate(w, w.getChunkManager().getChunkGenerator(), w.random, p, config);
CarpetSettings.skipGenerationChecks=false;
return res;
};
}
private static Thing spawnCustomStructure(Structure structure, FeatureConfig config)
{
return (w, p) -> {
IChunkGenerator chunkgen = new ChunkGeneratorOverworld(w, null, new OverworldGenSettings())
{
@Nullable
@Override
public FeatureConfig getStructureConfig(Biome biomeIn, Structure<? extends FeatureConfig> structureIn)
{
return config;
}
@Override
public BiomeProvider getBiomeProvider()
{
return new OverworldBiomeProvider(new OverworldBiomeProviderSettings().setWorldInfo(w.getWorldInfo()))
{
@Nullable
@Override
public Biome getBiome(BlockPos pos, @Nullable Biome defaultBiome)
{
return Biomes.PLAINS;
}
};
}
};
return structure.plopAnywhere(w, p, chunkgen);
};
}
public static Boolean spawn(String name, World world, BlockPos pos)
{
if (featureMap.containsKey(name))
return featureMap.get(name).plop(world, pos);
return null;
}
private static Map<String, Thing> featureMap = new HashMap<String, Thing>() {{
put("oak", simplePlop(Feature.TREE));
put("oak_large", simplePlop(Feature.BIG_TREE));
put("birch", simplePlop(Feature.BIRCH_TREE));
put("birch_large", simplePlop(Feature.TALL_BIRCH_TREE));
put("shrub", simplePlop(Feature.SHRUB));
put("shrub_acacia", simplePlop(new ShrubFeature(Blocks.ACACIA_WOOD.getDefaultState(), Blocks.ACACIA_LEAVES.getDefaultState())));
put("shrub_birch", simplePlop(new ShrubFeature(Blocks.BIRCH_WOOD.getDefaultState(), Blocks.BIRCH_LEAVES.getDefaultState())));
put("shrub_snowy", simplePlop(new ShrubFeature(Blocks.BONE_BLOCK.getDefaultState(), Blocks.COBWEB.getDefaultState())));
put("jungle", simplePlop(Feature.JUNGLE_TREE));
put("spruce_matchstick", simplePlop(Feature.POINTY_TAIGA_TREE));
put("dark_oak", simplePlop(Feature.CANOPY_TREE));
put("acacia", simplePlop(Feature.SAVANNA_TREE));
put("spruce", simplePlop(Feature.TALL_TAIGA_TREE));
put("oak_swamp", simplePlop(Feature.SWAMP_TREE));
put("jungle_large", simplePlop(Feature.MESA_JUNGLE));
put("spruce_matchstick_large", simplePlop(Feature.MEGA_PINE_TREE_1));
put("spruce_large", simplePlop(Feature.MEGA_PINE_TREE_2));
put("well", simplePlop(Feature.DESERT_WELLS));
put("grass_jungle", simplePlop(Feature.JUNGLE_GRASS));
put("fern", simplePlop(Feature.TAIGA_GRASS));
put("grass", simplePlop(new TallGrassFeature(), new TallGrassConfig(Blocks.GRASS.getDefaultState())));
//put("", simplePlop(Feature.));
//put("", simplePlop(Feature.));
//put("", simplePlop(Feature.));
//put("", simplePlop(Feature.));
put("cactus", simplePlop(Feature.CACTUS));
put("dead_bush", simplePlop(Feature.DEAD_BUSH));
put("fossils", simplePlop(Feature.FOSSILS)); // spawn above, spawn invisible
put("mushroom_brown", simplePlop(Feature.BIG_BROWN_MUSHROOM));
put("mushroom_red", simplePlop(Feature.BIG_RED_MUSHROOM));
put("ice_spike", simplePlop(Feature.ICE_SPIKE));
put("glowstone", simplePlop(Feature.GLOWSTONE));
put("melon", simplePlop(Feature.MELON));
put("pumpkin", simplePlop(Feature.PUMPKIN));
put("sugarcane", simplePlop(Feature.REED));
put("lilypad", simplePlop(Feature.WATERLILY));
put("dungeon", simplePlop(Feature.DUNGEONS));
put("iceberg", simplePlop(Feature.ICEBERG, new IcebergConfig(Blocks.PACKED_ICE.getDefaultState())));
put("iceberg_blue", simplePlop(Feature.ICEBERG, new IcebergConfig(Blocks.BLUE_ICE.getDefaultState())));
put("lake", simplePlop(Feature.LAKES, new LakesConfig(Blocks.WATER)));
put("lake_lava", simplePlop(Feature.LAKES, new LakesConfig(Blocks.LAVA)));
//put("end tower", simplePlop(Feature.END_CRYSTAL_TOWER)); // requires more complex setup
put("end_island", simplePlop(Feature.END_ISLAND));
put("chorus", simplePlop(Feature.CHORUS_PLANT));
put("sea_grass", simplePlop(Feature.SEA_GRASS, new SeaGrassConfig(80, 0.8D)));
put("sea_grass_river", simplePlop(Feature.SEA_GRASS, new SeaGrassConfig(48, 0.4D)));
put("kelp", simplePlop(Feature.KELP));
put("coral_tree", simplePlop(Feature.CORAL_TREE));
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM));
put("coral_claw", simplePlop(Feature.CORAL_CLAW));
put("coral", (w, p) ->
w.rand.nextInt(3)!=0?
(w.rand.nextInt(2)!=0?
simplePlop(Feature.CORAL_MUSHROOM).plop(w, p):
simplePlop(Feature.CORAL_TREE).plop(w, p))
:simplePlop(Feature.CORAL_CLAW).plop(w, p));
put("sea_pickle", simplePlop(Feature.SEA_PICKLE, new CountConfig(20)));
put("boulder", simplePlop(Feature.BLOCK_BLOB, new BlockBlobConfig(Blocks.MOSSY_COBBLESTONE, 0)));
//structures
put("monument", Feature.OCEAN_MONUMENT::plopAnywhere);
put("fortress", Feature.FORTRESS::plopAnywhere);
put("mansion", Feature.WOODLAND_MANSION::plopAnywhere);
put("jungle_temple", Feature.JUNGLE_PYRAMID::plopAnywhere);
put("desert_temple", Feature.DESERT_PYRAMID::plopAnywhere);
put("end_city", Feature.END_CITY::plopAnywhere);
put("igloo", Feature.IGLOO::plopAnywhere);
put("shipwreck", spawnCustomStructure(Feature.SHIPWRECK, new ShipwreckConfig(true)));
put("shipwreck2", spawnCustomStructure(Feature.SHIPWRECK, new ShipwreckConfig(false)));
put("witchhut", Feature.SWAMP_HUT::plopAnywhere);
put("stronghold", Feature.STRONGHOLD::plopAnywhere);
put("oceanruin_small", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinConfig(OceanRuinGenerator.Type.COLD, 0.0F, 0.5F)));
put("oceanruin_warm_small", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinConfig(OceanRuinGenerator.Type.WARM, 0.0F, 0.5F)));
put("oceanruin_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinConfig(OceanRuinGenerator.Type.COLD, 1.0F, 0.0F)));
put("oceanruin_warm_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinConfig(OceanRuinGenerator.Type.WARM, 1.0F, 0.0F)));
put("oceanruin", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinConfig(OceanRuinGenerator.Type.COLD, 1.0F, 1.0F)));
put("oceanruin_warm", spawnCustomStructure(Feature.OCEAN_RUIN,
new OceanRuinConfig(OceanRuinGenerator.Type.WARM, 1.0F, 1.0F)));
put("treasure", Feature.BURIED_TREASURE::plopAnywhere);
put("mineshaft", spawnCustomStructure(Feature.MINESHAFT, new MineshaftConfig(0.0, MineshaftStructure.Type.NORMAL)));
put("mineshaft_mesa", spawnCustomStructure(Feature.MINESHAFT, new MineshaftConfig(0.0, MineshaftStructure.Type.MESA)));
put("village", spawnCustomStructure(Feature.VILLAGE, new VillageConfig(0,VillagePieces.Type.OAK)));
put("village_desert", spawnCustomStructure(Feature.VILLAGE, new VillageConfig(0,VillagePieces.Type.SANDSTONE)));
put("village_savanna", spawnCustomStructure(Feature.VILLAGE, new VillageConfig(0,VillagePieces.Type.ACACIA)));
put("village_taiga", spawnCustomStructure(Feature.VILLAGE, new VillageConfig(0,VillagePieces.Type.SPRUCE)));
}};
}
@@ -0,0 +1,22 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.structure.BuriedTreasureGenerator;
import net.minecraft.world.Heightmap;
import net.minecraft.world.IWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(BuriedTreasureGenerator.Piece.class)
public class BuriedTreasureGeneratorPieceMixin
{
@Redirect(method = "generate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I"
))
private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3)
{
return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3);
}
}
@@ -0,0 +1,22 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.world.Heightmap;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.feature.FossilFeature;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(FossilFeature.class)
public class FossilFeatureMixin
{
@Redirect(method = "method_13236", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I"
))
private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3)
{
return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3);
}
}
@@ -0,0 +1,22 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.structure.IglooGenerator;
import net.minecraft.world.Heightmap;
import net.minecraft.world.IWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(IglooGenerator.Piece.class)
public class IglooGeneratorPieceMixin
{
@Redirect(method = "generate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I"
))
private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3)
{
return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.WORLD_SURFACE:Heightmap.Type.WORLD_SURFACE_WG, var2, var3);
}
}
@@ -0,0 +1,22 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.structure.OceanRuinGenerator;
import net.minecraft.world.Heightmap;
import net.minecraft.world.IWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(OceanRuinGenerator.Piece.class)
public class OceanRuinGeneratorPieceMixin
{
@Redirect(method = "generate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I"
))
private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3)
{
return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3);
}
}
@@ -57,7 +57,7 @@ public abstract class ServerChunkManagerMixin
Object2IntMap object2IntMap_1)
{
DimensionType dim = this.world.dimension.getType();
((WorldInterface)world).getPrecookedMobs().clear();
//((WorldInterface)world).getPrecookedMobs().clear(); not needed because mobs are compared with predefined BBs
SpawnReporter.mobCounts.put(dim, (Object2IntMap<EntityCategory>)object2IntMap_1);
SpawnReporter.chunkCounts.put(dim, int_2);
@@ -0,0 +1,29 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.structure.ShipwreckGenerator;
import net.minecraft.world.Heightmap;
import net.minecraft.world.IWorld;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ShipwreckGenerator.Piece.class)
public class ShipwreckGeneratorPieceMixin
{
@Shadow @Final private boolean grounded;
@Redirect(method = "generate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/IWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I"
))
private int getTop(IWorld iWorld, Heightmap.Type var1, int var2, int var3)
{
if (grounded)
return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.WORLD_SURFACE:Heightmap.Type.WORLD_SURFACE_WG, var2, var3);
else
return iWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3);
}
}
@@ -0,0 +1,136 @@
package carpet.mixins;
import carpet.CarpetServer;
import carpet.CarpetSettings;
import carpet.fakes.StructureFeatureInterface;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableIntBoundingBox;
import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Random;
@Mixin(StructureFeature.class)
public abstract class StructureFeatureMixin implements StructureFeatureInterface
{
//problem is that is seems that now chunks deal with its portion of the strucuture
//on its own.
@Shadow public abstract int getRadius();
@Shadow public abstract String getName();
@Shadow public abstract StructureFeature.StructureStartFactory getStructureStartFactory();
@Override
public boolean plopAnywhere(IWorld world, BlockPos pos)
{
return plopAnywhere(world, pos, world.getChunkManager().getChunkGenerator());
}
public boolean plopAnywhere(IWorld world, BlockPos pos, ChunkGenerator<? extends ChunkGeneratorConfig> generator)
{
if (world.isClient())
return false;
CarpetSettings.skipGenerationChecks = true;
try
{
Random rand = new Random(world.getRandom().nextInt());
int j = pos.getX() >> 4;
int k = pos.getZ() >> 4;
long chId = ChunkPos.toLong(j, k);
StructureStart structurestart = forceStructureStart(world, generator, rand, chId);
if (structurestart == null || structurestart == StructureStart.DEFAULT)
{
CarpetSettings.skipGenerationChecks = false;
return false;
}
//generator.ge getStructurePositionToReferenceMap(this).computeIfAbsent(chId,
// (x) -> new LongOpenHashSet()).add(chId);
world.getChunk(j, k, ChunkStatus.STRUCTURE_STARTS).addStructureReference(this.getName(), chId);
MutableIntBoundingBox box = structurestart.getBoundingBox();
structurestart.generateStructure(
world,
rand,
new MutableIntBoundingBox(
pos.getX() - this.getRadius()*16,
pos.getZ() - this.getRadius()*16,
pos.getX() + (this.getRadius()+1)*16,
pos.getZ() + (1+this.getRadius())*16),
new ChunkPos(j, k)
);
//structurestart.notifyPostProcessAt(new ChunkPos(j, k));
int i = getRadius();
for (int k1 = j - i; k1 <= j + i; ++k1)
{
for (int l1 = k - i; l1 <= k + i; ++l1)
{
if (k1 == j && l1 == k) continue;
long nbchkid = ChunkPos.toLong(k1, l1);
if (box.intersectsXZ(k1<<4, l1<<4, (k1<<4) + 15, (l1<<4) + 15))
{
//generator.getStructurePositionToReferenceMap(this).computeIfAbsent(nbchkid, (__) -> new LongOpenHashSet()).add(chId);
world.getChunk(k1, l1, ChunkStatus.STRUCTURE_STARTS).addStructureReference(this.getName(), chId);
//structurestart. notifyPostProcessAt(new ChunkPos(k1, l1));
}
}
}
}
catch (Exception ignored)
{
CarpetSettings.LOG.error("Unknown Exception while plopping structure: "+ignored);
ignored.printStackTrace();
CarpetSettings.skipGenerationChecks = false;
return false;
}
CarpetSettings.skipGenerationChecks = false;
return true;
}
private StructureStart forceStructureStart(IWorld worldIn, ChunkGenerator <? extends ChunkGeneratorConfig > generator, Random rand, long packedChunkPos)
{
ChunkPos chunkpos = new ChunkPos(packedChunkPos);
StructureStart structurestart = worldIn.getChunk(chunkpos.x, chunkpos.z).getStructureStart(this.getName());
if (structurestart != null)
{
return structurestart; // structure already exist, will skip
}
Chunk ichunk = worldIn.getChunk(chunkpos.x, chunkpos.z, ChunkStatus.STRUCTURE_STARTS);
if (ichunk != null)
{
structurestart = ichunk.getStructureStart(this.getName());
if (structurestart != null)
{
//long2objectmap.put(packedChunkPos, structurestart);
return structurestart;
}
}
Biome biome_1 = generator.getBiomeSource().getBiome(new BlockPos(chunkpos.getStartX() + 9, 0, chunkpos.getStartZ() + 9));
StructureStart structurestart1 = getStructureStartFactory().create((StructureFeature)(Object)this, chunkpos.x, chunkpos.z, biome_1, MutableIntBoundingBox.empty(),0,generator.getSeed());
structurestart1.initialize(generator, ((ServerWorld)worldIn).getStructureManager() , chunkpos.x, chunkpos.z, biome_1);
structurestart = structurestart.hasChildren() ? structurestart : StructureStart.DEFAULT;
if (structurestart.hasChildren())
{
worldIn.getChunk(chunkpos.x, chunkpos.z, ChunkStatus.STRUCTURE_STARTS).setStructureStart(this.getName(), structurestart);
}
//long2objectmap.put(packedChunkPos, structurestart);
return structurestart;
}
}
@@ -1,119 +0,0 @@
package carpet.mixins;
import carpet.CarpetSettings;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import org.spongepowered.asm.mixin.Mixin;
import java.util.Random;
@Mixin(StructureFeature.class)
public class StructureFeatureMixin
{
//problem is that is seems that now chunks deal with its portion of the strucuture
//on its own.
public boolean plopAnywhere(IWorld world, BlockPos pos)
{
return plopAnywhere(world, pos, world.getChunkManager().getChunkGenerator());
}
public boolean plopAnywhere(IWorld world, BlockPos pos, ChunkGenerator<? extends ChunkGeneratorConfig> generator)
{
CarpetSettings.skipGenerationChecks = true;
try
{
Random rand = new Random(world.getRandom().nextInt());
int j = pos.getX() >> 4;
int k = pos.getZ() >> 4;
long chId = ChunkPos.toLong(j, k);
StructureStart structurestart = forceStructureStart(world, generator, rand, chId);
if (structurestart == null || structurestart == StructureStart.DEFAULT)
{
CarpetSettings.skipGenerationChecks = false;
return false;
}
generator.ge getStructurePositionToReferenceMap(this).computeIfAbsent(chId, (x) -> new LongOpenHashSet()).add(chId);
world.getChunkManager().getChunkOrPrimer(j, k, true).addStructureReference(this.getStructureName(), chId);
MutableBoundingBox box = structurestart.getBoundingBox();
structurestart.generateStructure(
world,
rand,
new MutableBoundingBox(
pos.getX() - this.getSize()*16,
pos.getZ() - this.getSize()*16,
pos.getX() + (this.getSize()+1)*16,
pos.getZ() + (1+this.getSize())*16),
new ChunkPos(j, k)
);
structurestart.notifyPostProcessAt(new ChunkPos(j, k));
int i = this.getSize();
for (int k1 = j - i; k1 <= j + i; ++k1)
{
for (int l1 = k - i; l1 <= k + i; ++l1)
{
if (k1 == j && l1 == k) continue;
long nbchkid = ChunkPos.toLong(k1, l1);
if (box.intersectsWith(k1<<4, l1<<4, (k1<<4) + 15, (l1<<4) + 15))
{
generator.getStructurePositionToReferenceMap(this).computeIfAbsent(nbchkid, (__) -> new LongOpenHashSet()).add(chId);
world.getChunkManager().getChunkOrPrimer(k1, l1, true).addStructureReference(this.getStructureName(), chId);
structurestart.notifyPostProcessAt(new ChunkPos(k1, l1));
}
}
}
}
catch (Exception ignored)
{
CarpetSettings.LOG.error("Unknown Exception while plopping structure: "+ignored);
ignored.printStackTrace();
CarpetSettings.skipGenerationChecks = false;
return false;
}
CarpetSettings.skipGenerationChecks = false;
return true;
}
private StructureStart forceStructureStart(IWorld worldIn, ChunkGenerator <? extends ChunkGeneratorConfig > generator, Random rand, long packedChunkPos)
{
Long2ObjectMap<StructureStart> long2objectmap = generator.getStructureReferenceToStartMap(this);
StructureStart structurestart = long2objectmap.get(packedChunkPos);
if (structurestart != null)
{
return structurestart; // structure already exist, will skip
}
ChunkPos chunkpos = new ChunkPos(packedChunkPos);
IChunk ichunk = worldIn.getChunkManager().getChunkOrPrimer(chunkpos.x, chunkpos.z, false);
if (ichunk != null)
{
structurestart = ichunk.getStructureStart(this.getStructureName());
if (structurestart != null)
{
long2objectmap.put(packedChunkPos, structurestart);
return structurestart;
}
}
StructureStart structurestart1 = this.makeStart(worldIn, generator, rand, chunkpos.x, chunkpos.z);
structurestart = structurestart1.isValid() ? structurestart1 : NO_STRUCTURE;
if (structurestart.isValid())
{
worldIn.getChunkManager().getChunkOrPrimer(chunkpos.x, chunkpos.z, true).putStructureStart(this.getStructureName(), structurestart);
}
long2objectmap.put(packedChunkPos, structurestart);
return structurestart;
}
}
@@ -0,0 +1,22 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.structure.StructurePiece;
import net.minecraft.world.Heightmap;
import net.minecraft.world.ViewableWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(StructurePiece.class)
public class StructurePieceMixin
{
@Redirect(method = "isUnderSeaLevel", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/ViewableWorld;getTop(Lnet/minecraft/world/Heightmap$Type;II)I"
))
private int getTop(ViewableWorld viewableWorld, Heightmap.Type var1, int var2, int var3)
{
return viewableWorld.getTop(CarpetSettings.skipGenerationChecks?Heightmap.Type.OCEAN_FLOOR:Heightmap.Type.OCEAN_FLOOR_WG, var2, var3);
}
}
@@ -2,7 +2,7 @@ package carpet.script;
import carpet.CarpetServer;
import carpet.CarpetSettings;
// import carpet.helpers.FeatureGenerator; todo
import carpet.helpers.FeatureGenerator;
import carpet.fakes.MinecraftServerInterface;
import carpet.script.exception.CarpetExpressionException;
import carpet.script.exception.ExpressionException;
@@ -1878,13 +1878,13 @@ public class CarpetExpression
return (cc, tt) -> retval;
});
/*this.expr.addLazyFunction("plop", 4, (c, t, lv) ->{
this.expr.addLazyFunction("plop", 4, (c, t, lv) ->{
BlockValue.LocatorResult locator = BlockValue.fromParams((CarpetContext)c, lv, 0);
Boolean res = FeatureGenerator.spawn(lv.get(locator.offset).evalValue(c).getString(), ((CarpetContext)c).s.getWorld(), locator.block.getPos());
if (res == null)
return (c_, t_) -> Value.NULL;
return (c_, t_) -> new NumericValue(res);
});*/
});
}
/**
+8
View File
@@ -40,6 +40,14 @@
"KelpFeatureMixin",
"CoralBlockMixin",
"CoralFeatureMixin",
"StructurePieceMixin",
"StructureFeatureMixin",
"ShipwreckGeneratorPieceMixin",
"OceanRuinGeneratorPieceMixin",
"IglooGeneratorPieceMixin",
"FossilFeatureMixin",
"BuriedTreasureGeneratorPieceMixin",
"ServerChunkManagerMixin",
"SpawnHelperMixin",