diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java index 6d982e43..523e2fc4 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java @@ -6,7 +6,6 @@ import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Pos; import com.minelittlepony.unicopia.block.UBlocks; -import com.minelittlepony.unicopia.entity.mob.TentacleEntity; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.util.TraceHelper; @@ -85,14 +84,11 @@ public class EarthPonyGrowAbility implements Ability { w.setBlockState(pos.down(), Blocks.DIRT.getDefaultState()); } w.setBlockState(pos, UBlocks.PLUNDER_VINE_BUD.getDefaultState()); - } else if (w.random.nextInt(5000) == 0 || w.getBlockState(pos).isOf(UBlocks.CURING_JOKE)) { + } else if (w.random.nextInt(5000) == 0) { if (w.getBlockState(pos.down()).isOf(Blocks.FARMLAND)) { FarmlandBlock.setToDirt(null, state, w, pos.down()); } - w.breakBlock(pos, false); - TentacleEntity tentacle = new TentacleEntity(w, pos); - tentacle.updatePositionAndAngles(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0); - w.spawnEntity(tentacle); + UBlocks.CURING_JOKE.grow(w, state, pos); } return 1; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/CuringJokeBlock.java b/src/main/java/com/minelittlepony/unicopia/block/CuringJokeBlock.java index 73243fd1..5f37ff82 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/CuringJokeBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/CuringJokeBlock.java @@ -1,16 +1,20 @@ package com.minelittlepony.unicopia.block; +import com.minelittlepony.unicopia.ability.EarthPonyGrowAbility.Growable; +import com.minelittlepony.unicopia.entity.mob.IgnimeousBulbEntity; +import com.minelittlepony.unicopia.entity.mob.TentacleEntity; import com.minelittlepony.unicopia.particle.MagicParticleEffect; import net.minecraft.block.BlockState; import net.minecraft.block.FlowerBlock; import net.minecraft.client.util.ParticleUtil; +import net.minecraft.entity.Dismounting; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; import net.minecraft.world.World; -class CuringJokeBlock extends FlowerBlock { +public class CuringJokeBlock extends FlowerBlock implements Growable { public CuringJokeBlock(StatusEffect suspiciousStewEffect, int effectDuration, Settings settings) { super(suspiciousStewEffect, effectDuration, settings); } @@ -21,4 +25,29 @@ class CuringJokeBlock extends FlowerBlock { ParticleUtil.spawnParticle(world, pos, random, new MagicParticleEffect(0x3388EE)); } } + + @Override + public boolean grow(World world, BlockState state, BlockPos pos) { + var otherFlowers = BlockPos.streamOutwards(pos, 16, 16, 16) + .filter(p -> world.getBlockState(p).isOf(this)) + .map(BlockPos::toImmutable) + .toList(); + + if (otherFlowers.size() >= 8) { + IgnimeousBulbEntity bulb = new IgnimeousBulbEntity(world); + bulb.updatePositionAndAngles(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0); + + if (Dismounting.canPlaceEntityAt(world, bulb, bulb.getBoundingBox())) { + otherFlowers.forEach(p -> world.removeBlock(p, false)); + world.spawnEntity(bulb); + return true; + } + } + + world.removeBlock(pos, false); + TentacleEntity tentacle = new TentacleEntity(world, pos); + tentacle.updatePositionAndAngles(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0); + world.spawnEntity(tentacle); + return true; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java index 24ebc94d..cd8284da 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java +++ b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java @@ -139,7 +139,7 @@ public interface UBlocks { Block PLUNDER_VINE = register("plunder_vine", new ThornBlock(Settings.create().mapColor(MapColor.DARK_CRIMSON).hardness(1).ticksRandomly().sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.DESTROY), () -> UBlocks.PLUNDER_VINE_BUD)); Block PLUNDER_VINE_BUD = register("plunder_vine_bud", new ThornBudBlock(Settings.create().mapColor(MapColor.DARK_CRIMSON).hardness(1).nonOpaque().ticksRandomly().sounds(BlockSoundGroup.GRASS).pistonBehavior(PistonBehavior.DESTROY), PLUNDER_VINE.getDefaultState())); - Block CURING_JOKE = register("curing_joke", new CuringJokeBlock(UEffects.BUTTER_FINGERS, 7, AbstractBlock.Settings.create().mapColor(MapColor.PALE_PURPLE).noCollision().breakInstantly().sounds(BlockSoundGroup.GRASS).offset(AbstractBlock.OffsetType.XZ).pistonBehavior(PistonBehavior.DESTROY))); + CuringJokeBlock CURING_JOKE = register("curing_joke", new CuringJokeBlock(UEffects.BUTTER_FINGERS, 7, AbstractBlock.Settings.create().mapColor(MapColor.PALE_PURPLE).noCollision().breakInstantly().sounds(BlockSoundGroup.GRASS).offset(AbstractBlock.OffsetType.XZ).pistonBehavior(PistonBehavior.DESTROY))); Block CHITIN = register("chitin", new SnowyBlock(Settings.create().mapColor(MapColor.PALE_PURPLE).hardness(5).requiresTool().ticksRandomly().sounds(BlockSoundGroup.CORAL)), ItemGroups.NATURAL); Block SURFACE_CHITIN = register("surface_chitin", new GrowableBlock(Settings.copy(CHITIN), () -> CHITIN), ItemGroups.NATURAL); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnimeousBulbEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnimeousBulbEntity.java index 286f0fad..a13fbdf1 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnimeousBulbEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnimeousBulbEntity.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.entity.player.Pony; +import net.minecraft.block.BlockState; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.MovementType; @@ -120,15 +121,27 @@ public class IgnimeousBulbEntity extends MobEntity { World w = getWorld(); mutable.set(getBlockPos()); mutable.move(offset); - while (w.isAir(mutable.down()) && w.isInBuildLimit(mutable)) { + while (isSpace(w, mutable.down()) && w.isInBuildLimit(mutable)) { mutable.move(Direction.DOWN); } - while (!w.isAir(mutable) && w.isInBuildLimit(mutable)) { + while (!isPosValid(w, mutable) && w.isInBuildLimit(mutable)) { mutable.move(Direction.UP); } + if (w.getBlockState(mutable).isReplaceable()) { + w.breakBlock(mutable, true); + } return mutable.toImmutable(); } + private boolean isPosValid(World w, BlockPos pos) { + return w.isTopSolid(pos.down(), this) && isSpace(w, pos); + } + + private boolean isSpace(World w, BlockPos pos) { + BlockState state = w.getBlockState(pos); + return state.isAir() || state.isReplaceable(); + } + @Override public void remove(RemovalReason reason) { super.remove(reason); diff --git a/src/main/resources/data/unicopia/loot_tables/blocks/curing_joke.json b/src/main/resources/data/unicopia/loot_tables/blocks/curing_joke.json new file mode 100644 index 00000000..7a4cba95 --- /dev/null +++ b/src/main/resources/data/unicopia/loot_tables/blocks/curing_joke.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1.0, + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "name": "unicopia:curing_joke" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file