Bonemeal util
This commit is contained in:
parent
c42dbfdf87
commit
4d9a49a10e
3 changed files with 91 additions and 19 deletions
|
@ -24,6 +24,7 @@ import ru.betterend.registry.EndItems;
|
|||
import ru.betterend.registry.EndSounds;
|
||||
import ru.betterend.registry.EndStructures;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BonemealUtil;
|
||||
import ru.betterend.util.Logger;
|
||||
import ru.betterend.world.generator.BetterEndBiomeSource;
|
||||
import ru.betterend.world.surface.SurfaceBuilders;
|
||||
|
@ -52,6 +53,7 @@ public class BetterEnd implements ModInitializer {
|
|||
InfusionRecipes.register();
|
||||
EndStructures.register();
|
||||
Integrations.register();
|
||||
BonemealUtil.init();
|
||||
|
||||
if (hasGuideBook()) {
|
||||
GuideBook.register();
|
||||
|
|
|
@ -22,6 +22,7 @@ import ru.betterend.registry.EndBiomes;
|
|||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.BonemealUtil;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
@Mixin(BoneMealItem.class)
|
||||
|
@ -122,25 +123,8 @@ public class BoneMealItemMixin {
|
|||
private BlockState beGetGrassState(World world, BlockPos pos) {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
if (block == EndBlocks.END_MOSS || block == EndBlocks.END_MYCELIUM) {
|
||||
return world.random.nextBoolean() ? EndBlocks.CREEPING_MOSS.getDefaultState() : EndBlocks.UMBRELLA_MOSS.getDefaultState();
|
||||
}
|
||||
else if (block == EndBlocks.CAVE_MOSS) {
|
||||
return EndBlocks.CAVE_GRASS.getDefaultState();
|
||||
}
|
||||
else if (block == EndBlocks.CHORUS_NYLIUM) {
|
||||
return EndBlocks.CHORUS_GRASS.getDefaultState();
|
||||
}
|
||||
else if (block == EndBlocks.CRYSTAL_MOSS) {
|
||||
return EndBlocks.CRYSTAL_GRASS.getDefaultState();
|
||||
}
|
||||
else if (block == EndBlocks.SHADOW_GRASS) {
|
||||
return EndBlocks.SHADOW_PLANT.getDefaultState();
|
||||
}
|
||||
else if (block == EndBlocks.PINK_MOSS) {
|
||||
return EndBlocks.BUSHY_GRASS.getDefaultState();
|
||||
}
|
||||
return null;
|
||||
block = BonemealUtil.getGrass(block, world.getRandom());
|
||||
return block == null ? null : block.getDefaultState();
|
||||
}
|
||||
|
||||
private BlockState beGetWaterGrassState(World world, BlockPos pos) {
|
||||
|
|
86
src/main/java/ru/betterend/util/BonemealUtil.java
Normal file
86
src/main/java/ru/betterend/util/BonemealUtil.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
public class BonemealUtil {
|
||||
private static final Map<Block, GrassList> GRASS_TYPES = Maps.newHashMap();
|
||||
|
||||
public static void init() {
|
||||
addBonemealGrass(EndBlocks.END_MOSS, EndBlocks.CREEPING_MOSS);
|
||||
addBonemealGrass(EndBlocks.END_MOSS, EndBlocks.UMBRELLA_MOSS);
|
||||
addBonemealGrass(EndBlocks.END_MYCELIUM, EndBlocks.CREEPING_MOSS);
|
||||
addBonemealGrass(EndBlocks.END_MYCELIUM, EndBlocks.UMBRELLA_MOSS);
|
||||
addBonemealGrass(EndBlocks.CAVE_MOSS, EndBlocks.CAVE_GRASS);
|
||||
addBonemealGrass(EndBlocks.CHORUS_NYLIUM, EndBlocks.CHORUS_GRASS);
|
||||
addBonemealGrass(EndBlocks.CRYSTAL_MOSS, EndBlocks.CRYSTAL_GRASS);
|
||||
addBonemealGrass(EndBlocks.SHADOW_GRASS, EndBlocks.SHADOW_PLANT);
|
||||
addBonemealGrass(EndBlocks.PINK_MOSS, EndBlocks.BUSHY_GRASS);
|
||||
addBonemealGrass(EndBlocks.AMBER_MOSS, EndBlocks.AMBER_GRASS);
|
||||
addBonemealGrass(EndBlocks.JUNGLE_MOSS, EndBlocks.JUNGLE_GRASS);
|
||||
}
|
||||
|
||||
public static void addBonemealGrass(Block terrain, Block plant) {
|
||||
addBonemealGrass(terrain, plant, 1F);
|
||||
}
|
||||
|
||||
public static void addBonemealGrass(Block terrain, Block plant, float chance) {
|
||||
GrassList list = GRASS_TYPES.get(terrain);
|
||||
if (list == null) {
|
||||
list = new GrassList();
|
||||
GRASS_TYPES.put(terrain, list);
|
||||
}
|
||||
list.addGrass(plant, chance);
|
||||
}
|
||||
|
||||
public static Block getGrass(Block terrain, Random random) {
|
||||
GrassList list = GRASS_TYPES.get(terrain);
|
||||
return list == null ? null : list.getGrass(random);
|
||||
}
|
||||
|
||||
private static final class GrassInfo {
|
||||
final Block grass;
|
||||
float chance;
|
||||
|
||||
public GrassInfo(Block grass, float chance) {
|
||||
this.grass = grass;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public float addChance(float chance) {
|
||||
this.chance += chance;
|
||||
return this.chance;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GrassList {
|
||||
final List<GrassInfo> list = Lists.newArrayList();
|
||||
float maxChance = 0;
|
||||
|
||||
public void addGrass(Block grass, float chance) {
|
||||
GrassInfo info = new GrassInfo(grass, chance);
|
||||
maxChance = info.addChance(maxChance);
|
||||
list.add(info);
|
||||
}
|
||||
|
||||
public Block getGrass(Random random) {
|
||||
if (maxChance == 0 || list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
float chance = random.nextFloat() * maxChance;
|
||||
for (GrassInfo info: list) {
|
||||
if (chance <= info.chance) {
|
||||
return info.grass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue