Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

脆冰相关 #93

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.vehicle.VehicleEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
Expand All @@ -28,6 +30,7 @@
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import org.polaris2023.wild_wind.util.EnchantmentHelper;

Expand All @@ -50,10 +53,13 @@ public MapCodec<? extends BrittleIceBlock> codec() {
return CODEC;
}

protected boolean canCrash(Entity entity, ServerLevel serverLevel) {
return (entity instanceof LivingEntity livingEntity && !hasFrostWalker(serverLevel, livingEntity)) || entity instanceof VehicleEntity || entity instanceof Projectile;
}

@Override
public void fallOn(Level level, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
if(level instanceof ServerLevel serverLevel && entity instanceof LivingEntity livingEntity &&
!hasFrostWalker(serverLevel, livingEntity) && fallDistance > 0.75F) {
if(level instanceof ServerLevel serverLevel && this.canCrash(entity, serverLevel) && fallDistance > 0.75F) {
this.crash(serverLevel, pos, entity);
}
super.fallOn(level, state, pos, entity, fallDistance);
Expand All @@ -63,11 +69,19 @@ public void fallOn(Level level, BlockState state, BlockPos pos, Entity entity, f
public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) {
super.stepOn(level, pos, state, entity);

if (!level.isClientSide() && !level.getBlockTicks().willTickThisTick(pos, this) && !entity.isSteppingCarefully()) {
if (level instanceof ServerLevel serverLevel && !level.getBlockTicks().willTickThisTick(pos, this) &&
!entity.isSteppingCarefully() && this.canCrash(entity, serverLevel)) {
level.scheduleTick(pos, this, 10);
}
}

@Override
protected void onProjectileHit(Level level, BlockState state, BlockHitResult hit, Projectile projectile) {
if(level instanceof ServerLevel serverLevel && this.canCrash(projectile, serverLevel)) {
this.crash(serverLevel, hit.getBlockPos(), projectile);
}
}

@SuppressWarnings("deprecation")
@Override
public void tick(BlockState blockState, ServerLevel level, BlockPos blockPos, RandomSource random) {
Expand All @@ -77,10 +91,8 @@ public void tick(BlockState blockState, ServerLevel level, BlockPos blockPos, Ra
this.crash(level, blockPos, null);
return;
}
Predicate<Entity> entityPredicate = entity -> entity.onGround() && entity.getOnPosLegacy().equals(blockPos) && !entity.isSteppingCarefully() && (
!(entity instanceof LivingEntity livingEntity) || !hasFrostWalker(level, livingEntity)
);
List<? extends Entity> entitiesOnBlock = level.getEntities(EntityTypeTest.forClass(LivingEntity.class), entityPredicate);
Predicate<Entity> entityPredicate = entity -> entity.onGround() && entity.getOnPosLegacy().equals(blockPos) && !entity.isSteppingCarefully() && this.canCrash(entity, level);
List<? extends Entity> entitiesOnBlock = level.getEntities(EntityTypeTest.forClass(Entity.class), entityPredicate);
if(entitiesOnBlock.isEmpty()) {
if(age > 0) {
if(random.nextInt(100 / age / age) < 10) {
Expand Down Expand Up @@ -116,13 +128,15 @@ private void crash(ServerLevel level, BlockPos blockPos, @Nullable Entity entity
if(level.random.nextInt(5) < 2) {
this.tryChainReactAt(level, blockPos.west());
}
this.tryChainReactAt(level, blockPos.above());
this.tryChainReactAt(level, blockPos.below());
if(level.random.nextInt(5) < 3) {
this.tryChainReactAt(level, blockPos.below());
}
}

private void tryChainReactAt(ServerLevel level, BlockPos blockPos) {
BlockState blockState = level.getBlockState(blockPos);
if(blockState.is(this)) {
BlockState above = level.getBlockState(blockPos.above());
if(blockState.is(this) && !above.is(this)) {
level.setBlock(blockPos, blockState.setValue(UNSTABLE, true), Block.UPDATE_ALL);
if(!level.getBlockTicks().willTickThisTick(blockPos, this)) {
level.scheduleTick(blockPos, this, 2);
Expand Down
Loading