|
| 1 | +package cc.cassian.raspberry.mixin.twigs; |
| 2 | + |
| 3 | +import cc.cassian.raspberry.config.ModConfig; |
| 4 | +import com.ninni.twigs.entity.Pebble; |
| 5 | +import net.mehvahdjukaar.supplementaries.reg.ModTags; |
| 6 | +import net.minecraft.core.BlockPos; |
| 7 | +import net.minecraft.world.entity.EntityType; |
| 8 | +import net.minecraft.world.entity.projectile.ThrowableItemProjectile; |
| 9 | +import net.minecraft.world.level.Level; |
| 10 | +import net.minecraft.world.level.block.state.BlockState; |
| 11 | +import net.minecraft.world.phys.BlockHitResult; |
| 12 | +import net.minecraft.world.phys.HitResult; |
| 13 | +import org.spongepowered.asm.mixin.Mixin; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | + |
| 19 | +@Mixin(Pebble.class) |
| 20 | +public abstract class PebbleMixin extends ThrowableItemProjectile { |
| 21 | + |
| 22 | + public PebbleMixin(EntityType<? extends ThrowableItemProjectile> entityType, Level level) { |
| 23 | + super(entityType, level); |
| 24 | + } |
| 25 | + |
| 26 | + @Inject( |
| 27 | + method = "onHit", |
| 28 | + at = @At(value = "INVOKE", target = "Lcom/ninni/twigs/entity/Pebble;getItem()Lnet/minecraft/world/item/ItemStack;"), |
| 29 | + cancellable = true) |
| 30 | + private void rewriteRarity(HitResult hitResult, CallbackInfo ci) { |
| 31 | + if (ModConfig.get().strongerPebbles && hitResult instanceof BlockHitResult blockHitResult) { |
| 32 | + if (raspberryCore$breakGlass(blockHitResult.getBlockPos(), 6)) |
| 33 | + ci.cancel(); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + @Unique |
| 38 | + private boolean raspberryCore$breakGlass(BlockPos pos, int chance) { |
| 39 | + boolean flag = false; |
| 40 | + int c = chance - 1 - this.random.nextInt(4); |
| 41 | + BlockState state = this.level.getBlockState(pos); |
| 42 | + if (!(state.getBlock().getExplosionResistance() > 3.0F)) { |
| 43 | + if (c >= 0 && state.is(ModTags.BRICK_BREAKABLE_GLASS)) { |
| 44 | + this.level.destroyBlock(pos, true); |
| 45 | + this.raspberryCore$breakGlass(pos.above(), c); |
| 46 | + this.raspberryCore$breakGlass(pos.below(), c); |
| 47 | + this.raspberryCore$breakGlass(pos.east(), c); |
| 48 | + this.raspberryCore$breakGlass(pos.west(), c); |
| 49 | + this.raspberryCore$breakGlass(pos.north(), c); |
| 50 | + this.raspberryCore$breakGlass(pos.south(), c); |
| 51 | + flag = true; |
| 52 | + } |
| 53 | + } |
| 54 | + return flag; |
| 55 | + } |
| 56 | +} |
0 commit comments