Fixed earth ponies breaking blocks in adventure mode and protected regions. Fixes #434

This commit is contained in:
Sollace 2024-09-16 17:51:41 +01:00
parent 2046ca3029
commit 0ba3fd64a7
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
6 changed files with 29 additions and 17 deletions

View file

@ -14,6 +14,7 @@ import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.recipe.TransformCropsRecipe;
import com.minelittlepony.unicopia.recipe.URecipes;
import com.minelittlepony.unicopia.server.world.BlockDestructionManager;
import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.TraceHelper;
import com.minelittlepony.unicopia.util.VecHelper;
@ -70,8 +71,10 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
for (BlockPos pos : BlockPos.iterate(
data.pos().add(-2, -2, -2),
data.pos().add( 2, 2, 2))) {
if (player.canModifyAt(pos, ModificationType.PHYSICAL)) {
count += applySingle(player, player.asWorld(), player.asWorld().getBlockState(pos), pos);
}
}
} else {
count = 1;
}

View file

@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.server.world.BlockDestructionManager;
import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.*;
import net.minecraft.block.BeehiveBlock;
@ -98,7 +99,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
}
BlockPos pos = kickLocation.pos();
EarthPonyStompAbility.stompBlock(w, pos, 10 * (1 + player.getLevel().getScaled(5)) * w.getBlockState(pos).calcBlockBreakingDelta(player.asEntity(), w, pos));
EarthPonyStompAbility.stompBlock(player, w, pos, 10 * (1 + player.getLevel().getScaled(5)) * w.getBlockState(pos).calcBlockBreakingDelta(player.asEntity(), w, pos));
player.setAnimation(Animation.KICK, Animation.Recipient.ANYONE);
});
}
@ -165,10 +166,16 @@ public class EarthPonyKickAbility implements Ability<Pos> {
if (BlockDestructionManager.of(player.getWorld()).getBlockDestruction(pos) + 4 >= BlockDestructionManager.MAX_DAMAGE) {
if (player.getWorld().random.nextInt(30) == 0) {
tree.logs().forEach(player.getWorld(), (w, state, p) -> w.breakBlock(p, true));
tree.logs().forEach(player.getWorld(), (w, state, p) -> {
if (iplayer.canModifyAt(p, ModificationType.PHYSICAL)) {
w.breakBlock(p, true);
}
});
tree.leaves().forEach(player.getWorld(), (w, state, p) -> {
if (iplayer.canModifyAt(p, ModificationType.PHYSICAL)) {
Block.dropStacks(w.getBlockState(p), w, p);
w.setBlockState(p, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL);
}
});
}

View file

@ -19,6 +19,7 @@ import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.server.world.BlockDestructionManager;
import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.PosHelper;
import com.minelittlepony.unicopia.util.VecHelper;
@ -166,7 +167,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
double radius = rad + heavyness * 0.3;
spawnEffectAround(player, center, radius, rad);
spawnEffectAround(iplayer, player, center, radius, rad);
ParticleUtils.spawnParticle(player.getWorld(), UParticles.GROUND_POUND, player.getX(), player.getY() - 1, player.getZ(), 0, 0, 0);
BlockState steppingState = player.getSteppingBlockState();
@ -198,17 +199,17 @@ public class EarthPonyStompAbility implements Ability<Hit> {
return true;
}
public static void spawnEffectAround(Entity source, BlockPos center, double radius, double range) {
public static void spawnEffectAround(Pony pony, Entity source, BlockPos center, double radius, double range) {
BlockPos.stream(new BlockBox(center).expand(MathHelper.ceil(radius))).forEach(i -> {
double dist = Math.sqrt(i.getSquaredDistance(source.getX(), source.getY(), source.getZ()));
if (dist <= radius) {
spawnEffect(source.getWorld(), i, dist, range);
spawnEffect(pony, source.getWorld(), i, dist, range);
}
});
}
public static void spawnEffect(World w, BlockPos pos, double dist, double rad) {
public static void spawnEffect(Pony pony, World w, BlockPos pos, double dist, double rad) {
if (w.getBlockState(pos.up()).isAir()) {
BlockState state = w.getBlockState(pos);
@ -216,18 +217,18 @@ public class EarthPonyStompAbility implements Ability<Hit> {
float scaledHardness = (1 - hardness / 70);
float damage = hardness < 0 ? 0 : MathHelper.clamp((int)((1 - dist / rad) * 9 * scaledHardness), 0, BlockDestructionManager.MAX_DAMAGE - 1);
stompBlock(w, pos, damage);
stompBlock(pony, w, pos, damage);
}
}
public static void stompBlock(World w, BlockPos pos, float damage) {
public static void stompBlock(Pony pony, World w, BlockPos pos, float damage) {
BlockState state = w.getBlockState(pos);
if (state.isAir() || damage <= 0) {
return;
}
if (BlockDestructionManager.of(w).damageBlock(pos, damage) >= BlockDestructionManager.MAX_DAMAGE) {
if (BlockDestructionManager.of(w).damageBlock(pos, damage) >= BlockDestructionManager.MAX_DAMAGE && pony.canModifyAt(pos, ModificationType.PHYSICAL)) {
w.breakBlock(pos, true);
if (w instanceof ServerWorld) {

View file

@ -829,8 +829,8 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
.reduce(0, (u, pos) -> {
if (pony.canModifyAt(pos, ModificationType.PHYSICAL)) {
if (isEarthPonySmash) {
BlockDestructionManager.of(entity.getWorld()).damageBlock(pos, (int)entity.getWorld().getRandom().nextTriangular(5, 3));
if (BlockDestructionManager.of(entity.getWorld()).getBlockDestruction(pos) >= 9) {
float destruction = BlockDestructionManager.of(entity.getWorld()).damageBlock(pos, (int)entity.getWorld().getRandom().nextTriangular(5, 3));
if (destruction >= BlockDestructionManager.MAX_DAMAGE - 1 && pony.canModifyAt(pos, ModificationType.PHYSICAL)) {
entity.getWorld().breakBlock(pos, true);
}
} else {
@ -862,7 +862,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
if (isFlying()) {
playSound(USounds.ENTITY_PLAYER_PEGASUS_DASH, 1, 1);
} else {
playSound(USounds.ENTITY_PLAYER_EARTHPONY_DASH, 2, 0.3F);
playSound(USounds.ENTITY_PLAYER_EARTHPONY_DASH, 2, 1.3F);
}
}

View file

@ -703,7 +703,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
if (EffectUtils.hasExtraDefenses(entity)) {
double radius = distance / 10;
if (radius > 0) {
EarthPonyStompAbility.spawnEffectAround(entity, entity.getSteppingPos(), radius, radius);
EarthPonyStompAbility.spawnEffectAround(this, entity, entity.getSteppingPos(), radius, radius);
}
}

View file

@ -17,6 +17,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
public class BlockDestructionManager implements Tickable {
@ -54,7 +55,7 @@ public class BlockDestructionManager implements Tickable {
if (amount == 0) {
return getBlockDestruction(pos);
}
amount = Math.max(getBlockDestruction(pos), 0) + amount;
amount = MathHelper.clamp(Math.max(getBlockDestruction(pos), 0) + amount, 0, MAX_DAMAGE);
setBlockDestruction(pos, amount);
return amount;
}