Created
October 3, 2019 20:47
-
-
Save YanisBft/c9f6ef81bf1089629fe6d824b3398c41 to your computer and use it in GitHub Desktop.
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
package com.fabriccommunity.spookytime.mixin; | |
import java.util.List; | |
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.CallbackInfoReturnable; | |
import com.fabriccommunity.spookytime.registry.SpookyDimensions; | |
import com.fabriccommunity.spookytime.registry.SpookyItems; | |
import net.minecraft.entity.AreaEffectCloudEntity; | |
import net.minecraft.entity.boss.dragon.EnderDragonEntity; | |
import net.minecraft.entity.player.PlayerEntity; | |
import net.minecraft.item.GlassBottleItem; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.item.Items; | |
import net.minecraft.potion.PotionUtil; | |
import net.minecraft.potion.Potions; | |
import net.minecraft.sound.SoundCategory; | |
import net.minecraft.sound.SoundEvents; | |
import net.minecraft.stat.Stats; | |
import net.minecraft.tag.FluidTags; | |
import net.minecraft.util.ActionResult; | |
import net.minecraft.util.Hand; | |
import net.minecraft.util.TypedActionResult; | |
import net.minecraft.util.hit.BlockHitResult; | |
import net.minecraft.util.hit.HitResult; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.world.RayTraceContext; | |
import net.minecraft.world.World; | |
@SuppressWarnings({ "unchecked", "rawtypes" }) | |
@Mixin(GlassBottleItem.class) | |
public class GlassBottleItemMixin extends Item { | |
public GlassBottleItemMixin(Settings settings) { | |
super(settings); | |
} | |
@Inject(at = @At(value = "HEAD", target = "net/minecraft/item/GlassBottleItem.use(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/TypedActionResult;"), method = "use", cancellable = true) | |
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { | |
List<AreaEffectCloudEntity> list_1 = world.getEntities(AreaEffectCloudEntity.class, player.getBoundingBox().expand(2.0D), (areaEffectCloudEntity_1x) -> { | |
return areaEffectCloudEntity_1x != null && areaEffectCloudEntity_1x.isAlive() && areaEffectCloudEntity_1x.getOwner() instanceof EnderDragonEntity; | |
}); | |
ItemStack stack = player.getStackInHand(hand); | |
if (!list_1.isEmpty()) { | |
AreaEffectCloudEntity areaEffectCloudEntity_1 = (AreaEffectCloudEntity)list_1.get(0); | |
areaEffectCloudEntity_1.setRadius(areaEffectCloudEntity_1.getRadius() - 0.5F); | |
world.playSound((PlayerEntity)null, player.x, player.y, player.z, SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.NEUTRAL, 1.0F, 1.0F); | |
return new TypedActionResult(ActionResult.SUCCESS, this.fill(stack, player, new ItemStack(Items.DRAGON_BREATH))); | |
} else { | |
HitResult hitResult = rayTrace(world, player, RayTraceContext.FluidHandling.SOURCE_ONLY); | |
if (hitResult.getType() == HitResult.Type.MISS) { | |
return new TypedActionResult(ActionResult.PASS, stack); | |
} else { | |
if (hitResult.getType() == HitResult.Type.BLOCK) { | |
BlockPos pos = ((BlockHitResult) hitResult).getBlockPos(); | |
if (!world.canPlayerModifyAt(player, pos)) { | |
return new TypedActionResult(ActionResult.PASS, stack); | |
} | |
if (world.getFluidState(pos).matches(FluidTags.WATER)) { | |
world.playSound(player, player.x, player.y, player.z, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1.0F, 1.0F); | |
if (world.getDimension().getType() == SpookyDimensions.SPOOKY) { | |
return new TypedActionResult(ActionResult.SUCCESS, this.fill(stack, player, new ItemStack(SpookyItems.BLOOD_BOTTLE))); | |
} else { | |
return new TypedActionResult(ActionResult.SUCCESS, this.fill(stack, player, PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER))); | |
} | |
} | |
} | |
return new TypedActionResult(ActionResult.PASS, stack); | |
} | |
} | |
} | |
public ItemStack fill(ItemStack stack, PlayerEntity player, ItemStack stack_2) { | |
stack.decrement(1); | |
player.incrementStat(Stats.USED.getOrCreateStat(this)); | |
if (stack.isEmpty()) { | |
return stack_2; | |
} else { | |
if (!player.inventory.insertStack(stack_2)) { | |
player.dropItem(stack_2, false); | |
} | |
return stack; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment