-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
13 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/main/java/net/id/paradiselost/mixin/entity/PotionEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.id.paradiselost.mixin.entity; | ||
|
||
import net.id.paradiselost.util.BloomedCalciteUtil; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.effect.StatusEffectInstance; | ||
import net.minecraft.entity.effect.StatusEffects; | ||
import net.minecraft.entity.projectile.thrown.PotionEntity; | ||
import net.minecraft.entity.projectile.thrown.ThrownItemEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.potion.PotionUtil; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@Mixin(PotionEntity.class) | ||
public class PotionEntityMixin extends ThrownItemEntity { | ||
|
||
public PotionEntityMixin(EntityType<? extends ThrownItemEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Inject(method = "onBlockHit", at = @At("TAIL"), cancellable = true) | ||
protected void onBlockHit(BlockHitResult blockHitResult, CallbackInfo ci) { | ||
if (!this.world.isClient) { | ||
ItemStack itemStack = this.getStack(); | ||
List<StatusEffectInstance> list = PotionUtil.getPotionEffects(itemStack); | ||
boolean healingPotion = list.stream().anyMatch((e) -> e.getEffectType() == StatusEffects.INSTANT_HEALTH); | ||
Direction direction = blockHitResult.getSide(); | ||
BlockPos blockPos = blockHitResult.getBlockPos(); | ||
BlockPos landBlock = blockPos.offset(direction); | ||
if (healingPotion) { | ||
List<BlockPos> affected = new LinkedList<>(); | ||
if (world.getBlockState(landBlock.up()).isOf(Blocks.CALCITE)) { | ||
affected.add(landBlock.up()); | ||
} | ||
if (world.getBlockState(landBlock.down()).isOf(Blocks.CALCITE)) { | ||
affected.add(landBlock.down()); | ||
} | ||
addIfValid(landBlock, affected); | ||
addIfValid(landBlock.up(), affected); | ||
addIfValid(landBlock.down(), affected); | ||
for (Direction dir : Direction.Type.HORIZONTAL) { | ||
addIfValid(landBlock.up().offset(dir), affected); | ||
addIfValid(landBlock.down().offset(dir), affected); | ||
} | ||
for (BlockPos pos : new BlockPos[] {landBlock, landBlock.north(), landBlock.south()}) { | ||
addIfValid(pos, affected); | ||
addIfValid(pos.east(), affected); | ||
addIfValid(pos.west(), affected); | ||
} | ||
if (!affected.isEmpty()) { | ||
Collections.shuffle(affected); | ||
BloomedCalciteUtil.applyHealing(this.getOwner(), world, affected.get(0), this.world.random, itemStack); | ||
if (affected.size() > 1 && this.world.random.nextBoolean()) BloomedCalciteUtil.applyHealing(this.getOwner(), world, affected.get(1), this.world.random, itemStack); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
private void addIfValid(BlockPos pos, List<BlockPos> list) { | ||
if (world.getBlockState(pos).isOf(Blocks.CALCITE)) { | ||
list.add(pos); | ||
} | ||
} | ||
|
||
@Override | ||
public Item getDefaultItem() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/net/id/paradiselost/util/BloomedCalciteUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.id.paradiselost.util; | ||
|
||
import net.id.paradiselost.blocks.ParadiseLostBlocks; | ||
import net.minecraft.advancement.criterion.Criteria; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.particle.ParticleTypes; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.World; | ||
|
||
public class BloomedCalciteUtil { | ||
|
||
public static void applyHealing(Entity applier, World world, BlockPos blockPos, Random random, ItemStack itemStack) { | ||
if (applier instanceof ServerPlayerEntity) { | ||
Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity)applier, blockPos, itemStack); | ||
} | ||
|
||
world.setBlockState(blockPos, ParadiseLostBlocks.BLOOMED_CALCITE.getDefaultState()); | ||
// particles | ||
for (int i = 0; i < 16; i++) { | ||
double xOffset = random.nextDouble(); | ||
double yOffset = random.nextDouble(); | ||
double zOffset = random.nextDouble(); | ||
world.addParticle(ParticleTypes.ENTITY_EFFECT, blockPos.getX() + xOffset, blockPos.getY() + yOffset, blockPos.getZ() + zOffset, 0.97, 0.15, 0.14); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters