Water bonemeal mixin update
This commit is contained in:
parent
2dd7fdfc11
commit
3a238bbf9c
1 changed files with 64 additions and 1 deletions
|
@ -17,9 +17,12 @@ import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.BlockPos.Mutable;
|
import net.minecraft.util.math.BlockPos.Mutable;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.biome.Biome.Category;
|
||||||
|
import ru.betterend.registry.EndBiomes;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndTags;
|
import ru.betterend.registry.EndTags;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
|
import ru.betterend.world.biome.EndBiome;
|
||||||
|
|
||||||
@Mixin(BoneMealItem.class)
|
@Mixin(BoneMealItem.class)
|
||||||
public class BoneMealItemMixin {
|
public class BoneMealItemMixin {
|
||||||
|
@ -41,7 +44,13 @@ public class BoneMealItemMixin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
consume = beGrowGrass(world, blockPos);
|
BlockPos offseted = blockPos.offset(context.getSide().getOpposite());
|
||||||
|
if (!world.getBlockState(offseted).isOf(Blocks.WATER) && world.getBiome(offseted).getCategory() == Category.THEEND) {
|
||||||
|
consume = beGrowWaterGrass(world, blockPos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
consume = beGrowGrass(world, blockPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (consume) {
|
if (consume) {
|
||||||
if (!context.getPlayer().isCreative())
|
if (!context.getPlayer().isCreative())
|
||||||
|
@ -51,6 +60,18 @@ public class BoneMealItemMixin {
|
||||||
info.cancel();
|
info.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
BlockPos offseted = blockPos.offset(context.getSide().getOpposite());
|
||||||
|
if (!world.getBlockState(offseted).isOf(Blocks.WATER) && world.getBiome(offseted).getCategory() == Category.THEEND) {
|
||||||
|
if (beGrowWaterGrass(world, blockPos)) {
|
||||||
|
if (!context.getPlayer().isCreative())
|
||||||
|
context.getStack().decrement(1);
|
||||||
|
world.syncWorldEvent(2005, blockPos, 0);
|
||||||
|
info.setReturnValue(ActionResult.SUCCESS);
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +100,31 @@ public class BoneMealItemMixin {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean beGrowWaterGrass(World world, BlockPos pos) {
|
||||||
|
int y1 = pos.getY() + 3;
|
||||||
|
int y2 = pos.getY() - 3;
|
||||||
|
boolean result = false;
|
||||||
|
for (int i = 0; i < 64; i++) {
|
||||||
|
int x = (int) (pos.getX() + world.random.nextGaussian() * 2);
|
||||||
|
int z = (int) (pos.getZ() + world.random.nextGaussian() * 2);
|
||||||
|
POS.setX(x);
|
||||||
|
POS.setZ(z);
|
||||||
|
for (int y = y1; y >= y2; y--) {
|
||||||
|
POS.setY(y);
|
||||||
|
BlockPos down = POS.down();
|
||||||
|
if (world.getBlockState(POS).isOf(Blocks.WATER) && world.getBlockState(down).isIn(EndTags.END_GROUND)) {
|
||||||
|
BlockState grass = beGetWaterGrassState(world, down);
|
||||||
|
if (grass != null) {
|
||||||
|
BlocksHelper.setWithoutUpdate(world, POS, grass);
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private BlockState beGetGrassState(World world, BlockPos pos) {
|
private BlockState beGetGrassState(World world, BlockPos pos) {
|
||||||
BlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
|
@ -103,6 +149,23 @@ public class BoneMealItemMixin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BlockState beGetWaterGrassState(World world, BlockPos pos) {
|
||||||
|
EndBiome biome = EndBiomes.getFromBiome(world.getBiome(pos));
|
||||||
|
if (world.random.nextInt(16) == 0) {
|
||||||
|
return EndBlocks.CHARNIA_RED.getDefaultState();
|
||||||
|
}
|
||||||
|
else if (biome == EndBiomes.FOGGY_MUSHROOMLAND || biome == EndBiomes.MEGALAKE || biome == EndBiomes.MEGALAKE_GROVE) {
|
||||||
|
return world.random.nextBoolean() ? EndBlocks.CHARNIA_LIGHT_BLUE.getDefaultState() : EndBlocks.CHARNIA_LIGHT_BLUE.getDefaultState();
|
||||||
|
}
|
||||||
|
else if (biome == EndBiomes.AMBER_LAND) {
|
||||||
|
return world.random.nextBoolean() ? EndBlocks.CHARNIA_ORANGE.getDefaultState() : EndBlocks.CHARNIA_RED.getDefaultState();
|
||||||
|
}
|
||||||
|
else if (biome == EndBiomes.CHORUS_FOREST || biome == EndBiomes.SHADOW_FOREST) {
|
||||||
|
return EndBlocks.CHARNIA_PURPLE.getDefaultState();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void beShuffle(Random random) {
|
private void beShuffle(Random random) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int j = random.nextInt(4);
|
int j = random.nextInt(4);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue