Search in sources :

Example 16 with ItemEntity

use of net.minecraft.entity.ItemEntity in project wildmod by Osmiooo.

the class AllayEntity method initGoals.

protected void initGoals() {
    this.goalSelector.add(1, new LookAtEntityGoal(this, PlayerEntity.class, 8.0F));
    this.goalSelector.add(3, new FlyRandomlyGoal(this));
    this.setCanPickUpLoot(true);
    List<ItemEntity> list = AllayEntity.this.world.getEntitiesByClass(ItemEntity.class, AllayEntity.this.getBoundingBox().expand(8.0D, 8.0D, 8.0D), AllayEntity.CAN_TAKE);
}
Also used : FlyRandomlyGoal(frozenblock.wild.mod.liukrastapi.FlyRandomlyGoal) ItemEntity(net.minecraft.entity.ItemEntity) LookAtEntityGoal(net.minecraft.entity.ai.goal.LookAtEntityGoal) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 17 with ItemEntity

use of net.minecraft.entity.ItemEntity in project MCDungeonsArmors by chronosacaria.

the class EnchantmentEffects method applySurpriseGift.

public static void applySurpriseGift(PlayerEntity playerEntity) {
    if (!isInstantHealthPotion(playerEntity.getMainHandStack()))
        return;
    int surpriseGiftLevel = EnchantmentHelper.getEquipmentLevel(EnchantsRegistry.enchants.get(SURPRISE_GIFT), playerEntity);
    if (surpriseGiftLevel == 0)
        return;
    float surpriseGiftChance = 0.5F * surpriseGiftLevel;
    while (surpriseGiftChance > 0) {
        float surpriseGiftRand = playerEntity.getRandom().nextFloat();
        if (surpriseGiftRand <= surpriseGiftChance) {
            ItemStack potionToDrop = SURPRISE_GIFT_LIST.get(playerEntity.getRandom().nextInt(SURPRISE_GIFT_LIST.size()));
            ItemEntity surpriseGift = new ItemEntity(playerEntity.world, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), potionToDrop);
            playerEntity.world.spawnEntity(surpriseGift);
        }
        surpriseGiftChance -= 1.0F;
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) ItemStack(net.minecraft.item.ItemStack)

Example 18 with ItemEntity

use of net.minecraft.entity.ItemEntity in project FastAsyncWorldEdit by IntellectualSites.

the class FabricWorld method dropItem.

@Override
public void dropItem(Vector3 position, BaseItemStack item) {
    checkNotNull(position);
    checkNotNull(item);
    if (item.getType() == ItemTypes.AIR) {
        return;
    }
    ItemEntity entity = new ItemEntity(getWorld(), position.getX(), position.getY(), position.getZ(), FabricAdapter.adapt(item));
    entity.setPickupDelay(10);
    getWorld().spawnEntity(entity);
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity)

Example 19 with ItemEntity

use of net.minecraft.entity.ItemEntity in project KiwiClient by TangyKiwi.

the class Nametags method onWorldRender.

@Subscribe
@AllowConcurrentEvents
public void onWorldRender(WorldRenderEvent.Post event) {
    for (Entity entity : mc.world.getEntities()) {
        Vec3d rPos = entity.getPos().subtract(RenderUtils.getInterpolationOffset(entity)).add(0, entity.getHeight(), 0);
        double d = entity.squaredDistanceTo(mc.cameraEntity);
        if (!(d > 4096.0D)) {
            float scale = 1f;
            if (Math.sqrt(d) > 10)
                scale *= Math.sqrt(d) / 10;
            if (entity instanceof ItemEntity && getSetting(3).asToggle().state) {
                ItemEntity itemEntity = (ItemEntity) entity;
                String name = itemEntity.getName().getString();
                String customName = itemEntity.getStack().getName().getString();
                String amount = "[x" + itemEntity.getStack().getCount() + "]";
                if (!customName.equals(name)) {
                    double up = 0.7 + 0.9 * (Math.sqrt(d / 4096));
                    RenderUtils.drawWorldText(name + " " + getEmptyString(amount), rPos.x, rPos.y + up, rPos.z, scale, 0xFFAA00, true);
                    RenderUtils.drawWorldText(getEmptyString(name) + " " + amount, rPos.x, rPos.y + up, rPos.z, scale, 0xFFFF55, true);
                    RenderUtils.drawWorldText(customName, rPos.x, rPos.y + 0.5, rPos.z, scale, 0xFFAA00, true);
                } else {
                    // RenderUtils.drawWorldText("\u00a76" + name + " " + "\u00a7e" + amount, rPos.x, rPos.y + 0.5, rPos.z, scale, -1, true);
                    RenderUtils.drawWorldText(name + " " + getEmptyString(amount), rPos.x, rPos.y + 0.5, rPos.z, scale, 0xFFAA00, true);
                    RenderUtils.drawWorldText(getEmptyString(name) + " " + amount, rPos.x, rPos.y + 0.5, rPos.z, scale, 0xFFFF55, true);
                }
            } else if (entity instanceof LivingEntity) {
                if (entity == mc.player || entity.hasPassenger(mc.player) || mc.player.hasPassenger(entity)) {
                    continue;
                }
                if ((EntityUtils.isAnimal(entity) && getSetting(1).asToggle().state) || (entity instanceof Monster && getSetting(2).asToggle().state) || (entity instanceof PlayerEntity && getSetting(0).asToggle().state) || (entity instanceof ItemEntity && getSetting(3).asToggle().state)) {
                    LivingEntity livingEntity = (LivingEntity) entity;
                    String name = livingEntity.getName().getString();
                    String health = String.format("%.1f", livingEntity.getHealth());
                    RenderUtils.drawWorldText(name + " " + getEmptyString(health), rPos.x, rPos.y + 0.5, rPos.z, scale, 0xFFFFFF, true);
                    RenderUtils.drawWorldText(getEmptyString(name) + " " + health, rPos.x, rPos.y + 0.5, rPos.z, scale, getHealthColor(livingEntity), true);
                    int armorAmount = 0;
                    for (ItemStack i : livingEntity.getArmorItems()) {
                        if (!i.isEmpty()) {
                            armorAmount++;
                        }
                    }
                    double c = -3 + 0.5 * (4 - armorAmount);
                    double lscale = scale * 0.4;
                    double up = 0.7 + 0.9 * (Math.sqrt(d / 4096));
                    int height = 0;
                    height = Math.min(height, drawItem(rPos.x, rPos.y + up, rPos.z, 0.5 * (armorAmount + 1), 0, lscale, livingEntity.getEquippedStack(EquipmentSlot.MAINHAND)));
                    height = Math.min(height, drawItem(rPos.x, rPos.y + up, rPos.z, -0.5 * (armorAmount + 1), 0, lscale, livingEntity.getEquippedStack(EquipmentSlot.OFFHAND)));
                    for (ItemStack i : livingEntity.getArmorItems()) {
                        height = Math.min(height, drawItem(rPos.x, rPos.y + up, rPos.z, c + 1.5, 0, lscale, i));
                        if (!i.isEmpty()) {
                            c++;
                        }
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.ItemEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.ItemEntity) Monster(net.minecraft.entity.mob.Monster) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 20 with ItemEntity

use of net.minecraft.entity.ItemEntity in project nbt-crafting by Siphalor.

the class MixinCauldronBlock method onActivate.

@Inject(method = "onUse", at = @At("HEAD"), cancellable = true)
public void onActivate(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable<ActionResult> callbackInfoReturnable) {
    if (!world.isClient()) {
        TemporaryCauldronInventory inventory = new TemporaryCauldronInventory(playerEntity, hand, world, blockPos);
        Optional<CauldronRecipe> cauldronRecipe = world.getRecipeManager().getFirstMatch(NbtCrafting.CAULDRON_RECIPE_TYPE, inventory, world);
        if (cauldronRecipe.isPresent()) {
            DefaultedList<ItemStack> remainingStacks = cauldronRecipe.get().getRemainingStacks(inventory);
            ItemStack itemStack = cauldronRecipe.get().craft(inventory);
            itemStack.onCraft(world, playerEntity, itemStack.getCount());
            if (!playerEntity.inventory.insertStack(remainingStacks.get(0))) {
                ItemEntity itemEntity = playerEntity.dropItem(remainingStacks.get(0), false);
                if (itemEntity != null) {
                    itemEntity.resetPickupDelay();
                    itemEntity.setOwner(playerEntity.getUuid());
                }
            }
            if (!playerEntity.inventory.insertStack(itemStack)) {
                ItemEntity itemEntity = playerEntity.dropItem(itemStack, false);
                if (itemEntity != null) {
                    itemEntity.resetPickupDelay();
                    itemEntity.setOwner(playerEntity.getUuid());
                }
            }
            callbackInfoReturnable.setReturnValue(ActionResult.SUCCESS);
        }
    }
}
Also used : CauldronRecipe(de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe) ItemEntity(net.minecraft.entity.ItemEntity) TemporaryCauldronInventory(de.siphalor.nbtcrafting.recipe.cauldron.TemporaryCauldronInventory) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ItemEntity (net.minecraft.entity.ItemEntity)32 ItemStack (net.minecraft.item.ItemStack)15 PlayerEntity (net.minecraft.entity.player.PlayerEntity)7 Inject (org.spongepowered.asm.mixin.injection.Inject)6 Entity (net.minecraft.entity.Entity)5 LivingEntity (net.minecraft.entity.LivingEntity)5 Box (net.minecraft.util.math.Box)4 Monster (net.minecraft.entity.mob.Monster)3 Vec3d (net.minecraft.util.math.Vec3d)3 Item (net.minecraft.item.Item)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 World (net.minecraft.world.World)2 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)1 Subscribe (com.google.common.eventbus.Subscribe)1 CapeItem (com.jab125.thonkutil.api.CapeItem)1 CauldronRecipe (de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe)1 TemporaryCauldronInventory (de.siphalor.nbtcrafting.recipe.cauldron.TemporaryCauldronInventory)1 FlyRandomlyGoal (frozenblock.wild.mod.liukrastapi.FlyRandomlyGoal)1 Color (java.awt.Color)1 Iterator (java.util.Iterator)1