Search in sources :

Example 1 with LivingEntity

use of net.minecraft.entity.LivingEntity in project AgriCraft by AgriCraft.

the class JsonPlantCallBackPoisoning method onEntityCollision.

public void onEntityCollision(@Nonnull IAgriCrop crop, Entity entity) {
    if (entity instanceof LivingEntity && !entity.isSneaking() && !entity.getEntityWorld().isRemote) {
        LivingEntity livingEntity = ((LivingEntity) entity);
        if (!livingEntity.isPotionActive(Effects.POISON)) {
            EffectInstance poison = new EffectInstance(Effects.POISON, (int) (20 * crop.getStats().getAverage()));
            ((LivingEntity) entity).addPotionEffect(poison);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EffectInstance(net.minecraft.potion.EffectInstance)

Example 2 with LivingEntity

use of net.minecraft.entity.LivingEntity in project BluePower by Qmunity.

the class TileDeployer method rightClick.

/**
 * Be sure to set up the fake player's hotbar with the right clicked items. starting with hotbar slot 0.
 * @param player
 * @param useItems this method will set the current selected slot of the fake player to 0, and move on to the next slot useItems - 1 times.
 *          So to use the first slot only, pass 1, to use the full hotbar, 9.
 * @return
 */
protected boolean rightClick(FakePlayer player, int useItems) {
    if (useItems > 9)
        throw new IllegalArgumentException("Hotbar is 9 items in width! You're trying " + useItems + "!");
    Direction faceDir = getFacingDirection();
    int dx = faceDir.getStepX();
    int dy = faceDir.getStepY();
    int dz = faceDir.getStepZ();
    int x = worldPosition.getX() + dx;
    int y = worldPosition.getY() + dy;
    int z = worldPosition.getZ() + dz;
    player.setPos(x + 0.5, y + 0.5 - player.getEyeHeight(), z + 0.5);
    player.xRot = faceDir.getStepY() * -90;
    switch(faceDir) {
        case NORTH:
            player.yRot = 180;
            break;
        case SOUTH:
            player.yRot = 0;
            break;
        case WEST:
            player.yRot = 90;
            break;
        case EAST:
            player.yRot = -90;
    }
    try {
        PlayerInteractEvent event = new PlayerInteractEvent.RightClickEmpty(player, Hand.MAIN_HAND);
        if (event.isCanceled())
            return false;
        Block block = level.getBlockState(new BlockPos(x, y, z)).getBlock();
        List<LivingEntity> detectedEntities = level.getEntitiesOfClass(LivingEntity.class, new AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1));
        Entity entity = detectedEntities.isEmpty() ? null : detectedEntities.get(level.random.nextInt(detectedEntities.size()));
        if (entity != null) {
            for (int i = 0; i < useItems; i++) {
                player.inventory.selected = i;
                ItemStack stack = player.getMainHandItem();
                if (canDeployItem(stack) && stack.getItem().interactLivingEntity(stack, player, (LivingEntity) entity, Hand.MAIN_HAND).shouldSwing())
                    return true;
                if (entity instanceof AnimalEntity && ((AnimalEntity) entity).mobInteract(player, Hand.MAIN_HAND).shouldSwing())
                    return true;
            }
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.selected = i;
            ItemStack stack = player.getMainHandItem();
            if (canDeployItem(stack) && stack.getItem().onItemUseFirst(stack, new ItemUseContext(player, Hand.MAIN_HAND, new BlockRayTraceResult(new Vector3d(dx, dy, dz), faceDir, new BlockPos(x, y, z), false))) == ActionResultType.SUCCESS)
                return true;
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.selected = i;
            if (!level.isEmptyBlock(new BlockPos(x, y, z)) && block.use(level.getBlockState(new BlockPos(x, y, z)), level, new BlockPos(x, y, z), player, Hand.MAIN_HAND, new BlockRayTraceResult(new Vector3d(dx, dy, dz), faceDir, new BlockPos(x, y, z), false)) == ActionResultType.SUCCESS)
                return true;
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.selected = i;
            ItemStack stack = player.getMainHandItem();
            boolean isGoingToShift = false;
            if (!stack.isEmpty()) {
                if (stack.getItem() == Items.SUGAR_CANE || stack.getItem() == Items.REDSTONE) {
                    isGoingToShift = true;
                }
            }
            int useX = isGoingToShift ? worldPosition.getX() : x;
            int useY = isGoingToShift ? worldPosition.getY() : y;
            int useZ = isGoingToShift ? worldPosition.getZ() : z;
            if (canDeployItem(stack) && stack.getItem().useOn(new ItemUseContext(player, Hand.MAIN_HAND, new BlockRayTraceResult(new Vector3d(dx, dy, dz), faceDir, new BlockPos(x, y, z), false))) == ActionResultType.SUCCESS)
                return true;
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.selected = i;
            ItemStack stack = player.getMainHandItem();
            if (canDeployItem(stack)) {
                ItemStack copy = stack.copy();
                // TODO Check this
                player.setItemInHand(Hand.MAIN_HAND, stack.getItem().use(level, player, Hand.MAIN_HAND).getObject());
                if (!copy.sameItem(stack))
                    return true;
            }
        }
        return false;
    } catch (Throwable e) {
        BluePower.log.error("Deployer crashed! Stacktrace: ");
        e.printStackTrace();
        return true;
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemUseContext(net.minecraft.item.ItemUseContext) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Direction(net.minecraft.util.Direction) LivingEntity(net.minecraft.entity.LivingEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 3 with LivingEntity

use of net.minecraft.entity.LivingEntity in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerDrop.

@SubscribeEvent
public static void onPlayerDrop(LivingDropsEvent event) {
    LivingEntity livingEntity = event.getEntityLiving();
    Iterator<ItemEntity> iter = event.getDrops().iterator();
    if (livingEntity instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) livingEntity;
        while (iter.hasNext()) {
            ItemEntity entityItem = iter.next();
            ItemStack stack = entityItem.getItem();
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                player.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
                iter.remove();
                break;
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with LivingEntity

use of net.minecraft.entity.LivingEntity in project NetherEx by LogicTechCorp.

the class RenderEventHandler method onRenderLivingPost.

@SubscribeEvent
public static void onRenderLivingPost(RenderLivingEvent.Post<?, ?> event) {
    MatrixStack matrixStack = event.getMatrixStack();
    IRenderTypeBuffer renderTypeBuffer = event.getBuffers();
    LivingEntity entity = event.getEntity();
    if (entity.isPotionActive(NetherExEffects.FIRE_BURNING.get())) {
        renderThirdPersonBlueFire(matrixStack, renderTypeBuffer, entity);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with LivingEntity

use of net.minecraft.entity.LivingEntity in project AgriCraft by AgriCraft.

the class JsonPlantCallBackWithering method onEntityCollision.

public void onEntityCollision(@Nonnull IAgriCrop crop, Entity entity) {
    if (entity instanceof LivingEntity) {
        EffectInstance wither = new EffectInstance(Effects.WITHER, (int) (10 * crop.getStats().getAverage()));
        ((LivingEntity) entity).addPotionEffect(wither);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EffectInstance(net.minecraft.potion.EffectInstance)

Aggregations

LivingEntity (net.minecraft.entity.LivingEntity)5 ItemEntity (net.minecraft.entity.item.ItemEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 EffectInstance (net.minecraft.potion.EffectInstance)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 ItemUseContext (net.minecraft.item.ItemUseContext)1 Direction (net.minecraft.util.Direction)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 PlayerInteractEvent (net.minecraftforge.event.entity.player.PlayerInteractEvent)1