mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 11:49:37 +00:00
wip - Move flower generation to Feature
This commit is contained in:
1 parent
d0878c731b
commit
24421d83dd
6 files changed
+116
-53
No files matched your search
@@ -9,7 +9,8 @@
|
||||
* File Created @ [? (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.item;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
/**
|
||||
* A Biome that implements this will not have Botania flowers generated.
|
||||
*/
|
||||
@@ -17,5 +18,5 @@ public interface IFlowerlessBiome {
|
||||
/**
|
||||
* @return Should this world be allowed to generate flowers?
|
||||
*/
|
||||
public boolean canGenerateFlowers(World world, int x, int z);
|
||||
public boolean canGenerateFlowers(IWorld world, int x, int z);
|
||||
}
|
||||
@@ -10,15 +10,15 @@
|
||||
*/
|
||||
package vazkii.botania.api.item;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
/**
|
||||
* A WorldProvider that implements this will not have Botania flowers generated.
|
||||
* A {@link net.minecraft.world.dimension.Dimension} that implements this will not have Botania flowers generated.
|
||||
*/
|
||||
public interface IFlowerlessWorld {
|
||||
|
||||
/**
|
||||
* @return Should this world be allowed to generate flowers?
|
||||
*/
|
||||
public boolean generateFlowers(World world);
|
||||
public boolean generateFlowers(IWorld world);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -34,6 +35,7 @@ import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.client.model.pipeline.VertexTransformer;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import vazkii.botania.api.BotaniaAPIClient;
|
||||
import vazkii.botania.api.item.IFloatingFlower;
|
||||
@@ -42,6 +44,7 @@ import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.decor.BlockFloatingFlower;
|
||||
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -119,16 +122,18 @@ public class FloatingFlowerModel implements IBakedModel {
|
||||
} else {
|
||||
IBakedModel islandModel;
|
||||
try {
|
||||
islandModel = ModelLoaderRegistry.getModel(BotaniaAPIClient.getRegisteredIslandTypeModels().get(islandType)).bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
|
||||
islandModel = ModelLoaderRegistry.getModel(BotaniaAPIClient.getRegisteredIslandTypeModels().get(islandType))
|
||||
.bake(ModelLoader.defaultModelGetter(), ModelLoader.defaultTextureGetter(), TRSRTransformation.identity(), false, DefaultVertexFormats.ITEM);
|
||||
} catch (Exception e) {
|
||||
islandModel = modelManager.getMissingModel();
|
||||
}
|
||||
|
||||
IBakedModel flowerModel;
|
||||
|
||||
if(identifier.getPath().contains(MUNDANE_PREFIX)) {
|
||||
int meta = Integer.parseInt(identifier.getPath().substring(identifier.getPath().indexOf(MUNDANE_PREFIX) + MUNDANE_PREFIX.length()));
|
||||
flowerModel = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getItemModel(new ItemStack(ModBlocks.shinyFlower, 1, meta));
|
||||
if(identifier.getPath().endsWith(LibBlockNames.FLOATING_FLOWER_SUFFIX)) {
|
||||
ResourceLocation shinyId = new ResourceLocation(identifier.getNamespace(), identifier.getPath().replaceAll(LibBlockNames.FLOATING_FLOWER_SUFFIX, LibBlockNames.SHINY_FLOWER_SUFFIX));
|
||||
Item shinyFlower = ForgeRegistries.ITEMS.getValue(shinyId);
|
||||
flowerModel = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getItemModel(new ItemStack(shinyFlower));
|
||||
} else {
|
||||
ItemStack stack = ItemBlockSpecialFlower.ofType(identifier);
|
||||
IBakedModel specialFlowerModel = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getItemModel(stack);
|
||||
|
||||
@@ -34,51 +34,7 @@ public final class BiomeDecorationHandler {
|
||||
BlockPos pos = event.getPlacementPos() != null ? event.getPlacementPos() : event.getChunkPos().getBlock(0, 0, 0);
|
||||
|
||||
if((event.getResult() == Result.ALLOW || event.getResult() == Result.DEFAULT) && event.getType() == EventType.FLOWERS) {
|
||||
boolean flowers = true;
|
||||
if(event.getWorld().provider instanceof IFlowerlessWorld)
|
||||
flowers = ((IFlowerlessWorld) event.getWorld().provider).generateFlowers(event.getWorld());
|
||||
else if(event.getWorld().getBiome(pos) instanceof IFlowerlessBiome)
|
||||
flowers = ((IFlowerlessBiome) event.getWorld().getBiome(pos)).canGenerateFlowers(event.getWorld(), pos.getX(), pos.getZ());
|
||||
|
||||
if(!flowers)
|
||||
return;
|
||||
|
||||
int dist = Math.min(8, Math.max(1, ConfigHandler.COMMON.flowerPatchSize.get()));
|
||||
for(int i = 0; i < ConfigHandler.COMMON.flowerQuantity.get(); i++) {
|
||||
if(event.getRand().nextInt(ConfigHandler.COMMON.flowerPatchChance.get()) == 0) {
|
||||
int x = pos.getX() + event.getRand().nextInt(16) + 8;
|
||||
int z = pos.getZ() + event.getRand().nextInt(16) + 8;
|
||||
int y = event.getWorld().getTopSolidOrLiquidBlock(pos).getY();
|
||||
|
||||
EnumDyeColor color = EnumDyeColor.byMetadata(event.getRand().nextInt(16));
|
||||
|
||||
for(int j = 0; j < ConfigHandler.COMMON.flowerDensity.get() * ConfigHandler.COMMON.flowerPatchChance.get(); j++) {
|
||||
int x1 = x + event.getRand().nextInt(dist * 2) - dist;
|
||||
int y1 = y + event.getRand().nextInt(4) - event.getRand().nextInt(4);
|
||||
int z1 = z + event.getRand().nextInt(dist * 2) - dist;
|
||||
BlockPos pos2 = new BlockPos(x1, y1, z1);
|
||||
if(event.getWorld().isAirBlock(pos2) && (!event.getWorld().provider.isNether() || y1 < 127) && ModBlocks.flower.canPlaceBlockAt(event.getWorld(), pos2)) {
|
||||
event.getWorld().setBlockState(pos2, ModBlocks.flower.getDefaultState().with(BotaniaStateProps.COLOR, color), 2);
|
||||
if(event.getRand().nextDouble() < ConfigHandler.COMMON.flowerTallChance.get() && ((BlockModFlower) ModBlocks.flower).canGrow(event.getWorld(), pos2, event.getWorld().getBlockState(pos2), false)) {
|
||||
Block block = ModBlocks.getDoubleFlower(color);
|
||||
if(block instanceof BlockDoublePlant) {
|
||||
((BlockDoublePlant) block).placeAt(event.getWorld(), pos2, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < ConfigHandler.COMMON.mushroomQuantity.get(); i++) {
|
||||
int x = pos.getX() + event.getRand().nextInt(16) + 8;
|
||||
int z = pos.getZ() + event.getRand().nextInt(16) + 8;
|
||||
int y = event.getRand().nextInt(26) + 4;
|
||||
BlockPos pos3 = new BlockPos(x, y, z);
|
||||
EnumDyeColor color = EnumDyeColor.byMetadata(event.getRand().nextInt(16));
|
||||
if(event.getWorld().isAirBlock(pos3) && ModBlocks.mushroom.canPlaceBlockAt(event.getWorld(), pos3))
|
||||
event.getWorld().setBlockState(pos3, ModBlocks.mushroom.getDefaultState().with(BotaniaStateProps.COLOR, color), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package vazkii.botania.common.world;
|
||||
|
||||
import net.minecraft.world.gen.feature.IFeatureConfig;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
|
||||
public class MysticalFlowerConfig implements IFeatureConfig {
|
||||
public int getPatchSize() {
|
||||
return ConfigHandler.COMMON.flowerPatchSize.get();
|
||||
}
|
||||
|
||||
public int getPatchCount() {
|
||||
return ConfigHandler.COMMON.flowerQuantity.get();
|
||||
}
|
||||
|
||||
public int getPatchDensity() {
|
||||
return ConfigHandler.COMMON.flowerDensity.get();
|
||||
}
|
||||
|
||||
public int getPatchChance() {
|
||||
return ConfigHandler.COMMON.flowerPatchChance.get();
|
||||
}
|
||||
|
||||
public double getTallChance() {
|
||||
return ConfigHandler.COMMON.flowerTallChance.get();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package vazkii.botania.common.world;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoublePlant;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
import net.minecraft.world.gen.IChunkGenSettings;
|
||||
import net.minecraft.world.gen.IChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import vazkii.botania.api.item.IFlowerlessBiome;
|
||||
import vazkii.botania.api.item.IFlowerlessWorld;
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.common.block.BlockModFlower;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
|
||||
public class MysticalFlowerFeature extends Feature<MysticalFlowerConfig> {
|
||||
@Override
|
||||
public boolean place(@Nonnull IWorld world, @Nonnull IChunkGenerator<? extends IChunkGenSettings> generator, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull MysticalFlowerConfig config) {
|
||||
boolean flowers = true;
|
||||
if(world.getDimension() instanceof IFlowerlessWorld)
|
||||
flowers = ((IFlowerlessWorld) world.getDimension()).generateFlowers(world);
|
||||
else if(world.getBiome(pos) instanceof IFlowerlessBiome)
|
||||
flowers = ((IFlowerlessBiome) world.getBiome(pos)).canGenerateFlowers(world, pos.getX(), pos.getZ());
|
||||
|
||||
if(!flowers)
|
||||
return false;
|
||||
|
||||
int dist = Math.min(8, Math.max(1, config.getPatchSize()));
|
||||
for(int i = 0; i < config.getPatchCount(); i++) {
|
||||
if(rand.nextInt(config.getPatchChance()) == 0) {
|
||||
int x = pos.getX() + rand.nextInt(16) + 8;
|
||||
int z = pos.getZ() + rand.nextInt(16) + 8;
|
||||
int y = world.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, pos).getY();
|
||||
|
||||
EnumDyeColor color = EnumDyeColor.byId(rand.nextInt(16));
|
||||
IBlockState flower = ModBlocks.getFlower(color).getDefaultState();
|
||||
|
||||
for(int j = 0; j < config.getPatchDensity() * config.getPatchChance(); j++) {
|
||||
int x1 = x + rand.nextInt(dist * 2) - dist;
|
||||
int y1 = y + rand.nextInt(4) - rand.nextInt(4);
|
||||
int z1 = z + rand.nextInt(dist * 2) - dist;
|
||||
BlockPos pos2 = new BlockPos(x1, y1, z1);
|
||||
if(world.isAirBlock(pos2) && (!world.getDimension().isNether() || y1 < 127) && flower.isValidPosition(world, pos2)) {
|
||||
world.setBlockState(pos2, flower, 2);
|
||||
if(rand.nextDouble() < config.getTallChance() && ((BlockModFlower) flower).canGrow(world, pos2, world.getBlockState(pos2), false)) {
|
||||
Block block = ModBlocks.getDoubleFlower(color);
|
||||
if(block instanceof BlockDoublePlant) {
|
||||
((BlockDoublePlant) block).placeAt(world, pos2, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < ConfigHandler.COMMON.mushroomQuantity.get(); i++) {
|
||||
int x = pos.getX() + rand.nextInt(16) + 8;
|
||||
int z = pos.getZ() + rand.nextInt(16) + 8;
|
||||
int y = rand.nextInt(26) + 4;
|
||||
BlockPos pos3 = new BlockPos(x, y, z);
|
||||
EnumDyeColor color = EnumDyeColor.byMetadata(rand.nextInt(16));
|
||||
if(world.isAirBlock(pos3) && ModBlocks.mushroom.canPlaceBlockAt(world, pos3))
|
||||
world.setBlockState(pos3, ModBlocks.mushroom.getDefaultState().with(BotaniaStateProps.COLOR, color), 2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user