Search in sources :

Example 1 with EntityLeashKnot

use of net.minecraft.entity.EntityLeashKnot in project Charset by CharsetMC.

the class CharsetTweakZorro method doTheZorroThing.

@SubscribeEvent
public void doTheZorroThing(PlayerInteractEvent.EntityInteract event) {
    EntityPlayer player = event.getEntityPlayer();
    if (player.world.isRemote)
        return;
    if (player.isRiding())
        return;
    if (!(event.getTarget() instanceof EntityHorse))
        return;
    EntityHorse horse = (EntityHorse) event.getTarget();
    if (player.fallDistance <= 2)
        return;
    if (!horse.isHorseSaddled())
        return;
    if (horse.getLeashed()) {
        if (!(horse.getLeashHolder() instanceof EntityLeashKnot))
            return;
        horse.getLeashHolder().processInitialInteract(player, EnumHand.MAIN_HAND);
    }
    boolean awesome = false;
    ItemStack heldStack = player.getHeldItem(EnumHand.MAIN_HAND);
    if (player.fallDistance > 5 && !heldStack.isEmpty()) {
        Item held = heldStack.getItem();
        boolean has_baby = false;
        if (player.getRidingEntity() instanceof EntityAgeable) {
            EntityAgeable ea = (EntityAgeable) player.getRidingEntity();
            has_baby = ea.isChild();
        }
        awesome = held instanceof ItemSword || held instanceof ItemBow || player.getRidingEntity() instanceof EntityPlayer || has_baby;
        if (!awesome) {
            Set<String> classes = held.getToolClasses(heldStack);
            awesome |= classes.contains("axe");
        }
    }
    if (awesome) {
        horse.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("speed"), 20 * 40, 2, false, false));
        horse.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("resistance"), 20 * 40, 1, true, true));
        horse.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("jump_boost"), 20 * 40, 1, true, true));
    } else {
        horse.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("speed"), 20 * 8, 1, false, false));
    }
    horse.playLivingSound();
}
Also used : EntityLeashKnot(net.minecraft.entity.EntityLeashKnot) ItemSword(net.minecraft.item.ItemSword) Item(net.minecraft.item.Item) EntityHorse(net.minecraft.entity.passive.EntityHorse) PotionEffect(net.minecraft.potion.PotionEffect) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityAgeable(net.minecraft.entity.EntityAgeable) ItemBow(net.minecraft.item.ItemBow) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityAgeable (net.minecraft.entity.EntityAgeable)1 EntityLeashKnot (net.minecraft.entity.EntityLeashKnot)1 EntityHorse (net.minecraft.entity.passive.EntityHorse)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 ItemBow (net.minecraft.item.ItemBow)1 ItemStack (net.minecraft.item.ItemStack)1 ItemSword (net.minecraft.item.ItemSword)1 PotionEffect (net.minecraft.potion.PotionEffect)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1