Search in sources :

Example 1 with ItemEntity

use of net.minecraft.entity.ItemEntity in project MasaGadget by plusls.

the class MixinRenderUtils method modifyInv.

@ModifyVariable(method = "renderInventoryOverlay", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", ordinal = 0, remap = false), ordinal = 0)
private static Inventory modifyInv(Inventory inv) {
    Inventory ret = inv;
    Entity traceEntity = TraceUtil.getTraceEntity();
    if (Configs.Tweakeroo.INVENTORY_PREVIEW_SUPPORT_SHULKER_BOX_ITEM_ENTITY.getBooleanValue() && ret == null && traceEntity instanceof ItemEntity) {
        ItemStack itemStack = ((ItemEntity) traceEntity).getStack();
        Item item = itemStack.getItem();
        NbtCompound invNbt = itemStack.getSubNbt("BlockEntityTag");
        DefaultedList<ItemStack> stacks = DefaultedList.ofSize(27, ItemStack.EMPTY);
        if (item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof ShulkerBoxBlock) {
            ret = new SimpleInventory(27);
            if (invNbt != null) {
                Inventories.readNbt(invNbt, stacks);
            }
            for (int i = 0; i < 27; ++i) {
                ret.setStack(i, stacks.get(i));
            }
        }
    }
    return ret;
}
Also used : Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.ItemEntity) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) ItemEntity(net.minecraft.entity.ItemEntity) NbtCompound(net.minecraft.nbt.NbtCompound) ShulkerBoxBlock(net.minecraft.block.ShulkerBoxBlock) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) ModifyVariable(org.spongepowered.asm.mixin.injection.ModifyVariable)

Example 2 with ItemEntity

use of net.minecraft.entity.ItemEntity in project bewitchment by MoriyaShiine.

the class SmeltItemsRitualFunction method tick.

@Override
public void tick(World world, BlockPos glyphPos, BlockPos effectivePos, boolean catFamiliar) {
    int radius = catFamiliar ? 9 : 3;
    if (!world.isClient) {
        if (world.getTime() % 20 == 0) {
            for (ItemEntity itemEntity : world.getEntitiesByType(EntityType.ITEM, new Box(effectivePos).expand(radius, 0, radius), entity -> true)) {
                if (world.random.nextFloat() < 1 / 4f) {
                    world.getRecipeManager().listAllOfType(RecipeType.SMELTING).forEach(smeltingRecipe -> {
                        for (Ingredient ingredient : smeltingRecipe.getIngredients()) {
                            if (ingredient.test(itemEntity.getStack())) {
                                world.playSound(null, itemEntity.getBlockPos(), SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1, 1);
                                ItemScatterer.spawn(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), smeltingRecipe.getOutput().copy());
                                world.spawnEntity(new ExperienceOrbEntity(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), 1));
                                itemEntity.getStack().decrement(1);
                            }
                        }
                    });
                }
            }
        }
    } else {
        world.addParticle(ParticleTypes.FLAME, effectivePos.getX() + MathHelper.nextDouble(world.random, -radius, radius), effectivePos.getY() + 0.5, effectivePos.getZ() + MathHelper.nextDouble(world.random, -radius, radius), 0, 0, 0);
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) Ingredient(net.minecraft.recipe.Ingredient) Box(net.minecraft.util.math.Box) ExperienceOrbEntity(net.minecraft.entity.ExperienceOrbEntity)

Example 3 with ItemEntity

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

the class EnchantmentEffects method applyLuckyExplorer.

public static void applyLuckyExplorer(LivingEntity livingEntity) {
    World world = livingEntity.getWorld();
    if (livingEntity.isOnGround() && world.getTime() % 50 == 0) {
        int luckyExplorerLevel = EnchantmentHelper.getEquipmentLevel(EnchantsRegistry.enchants.get(LUCKY_EXPLORER), livingEntity);
        if (luckyExplorerLevel == 0)
            return;
        float luckyExplorerThreshold = luckyExplorerLevel * 0.10f;
        float luckyExplorerRand = livingEntity.getRandom().nextFloat();
        if (luckyExplorerRand <= luckyExplorerThreshold) {
            ItemStack feetStack = livingEntity.getEquippedStack(EquipmentSlot.FEET);
            double currentXCoord = livingEntity.getPos().getX();
            double currentZCoord = livingEntity.getPos().getZ();
            if (feetStack.getNbt().get("x-coord") == null) {
                feetStack.getOrCreateNbt().putDouble("x-coord", currentXCoord);
                feetStack.getOrCreateNbt().putDouble("z-coord", currentZCoord);
                return;
            }
            double storedXCoord = feetStack.getNbt().getDouble("x-coord");
            double storedZCoord = feetStack.getNbt().getDouble("z-coord");
            Vec3d vec3d = new Vec3d(storedXCoord, 0, storedZCoord);
            double distanceBetween = Math.sqrt(vec3d.squaredDistanceTo(currentXCoord, 0, currentZCoord));
            if (distanceBetween >= 20) {
                ItemEntity emerald = new ItemEntity(livingEntity.world, currentXCoord, livingEntity.getY(), currentZCoord, Items.EMERALD.getDefaultStack());
                livingEntity.world.spawnEntity(emerald);
                feetStack.getOrCreateNbt().putDouble("x-coord", currentXCoord);
                feetStack.getOrCreateNbt().putDouble("z-coord", currentZCoord);
            }
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 4 with ItemEntity

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

the class EnchantmentEffects method applyFoodReserves.

public static void applyFoodReserves(PlayerEntity playerEntity) {
    if (!isInstantHealthPotion(playerEntity.getMainHandStack()))
        return;
    int foodReserveLevel = EnchantmentHelper.getEquipmentLevel(EnchantsRegistry.enchants.get(FOOD_RESERVES), playerEntity);
    while (foodReserveLevel > 0) {
        Item foodToDrop = FOOD_RESERVE_LIST.get(playerEntity.getRandom().nextInt(FOOD_RESERVE_LIST.size()));
        ItemEntity foodDrop = new ItemEntity(playerEntity.world, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), new ItemStack(foodToDrop));
        playerEntity.world.spawnEntity(foodDrop);
        foodReserveLevel--;
    }
}
Also used : Item(net.minecraft.item.Item) ItemEntity(net.minecraft.entity.ItemEntity) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ItemEntity

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

the class RecyclerEnchantment method onUserDamaged.

@Override
public void onUserDamaged(LivingEntity user, Entity attacker, int level) {
    DamageSource damageSource = user.getRecentDamageSource();
    if (damageSource != null && damageSource.isProjectile()) {
        float recyclerRand = user.getRandom().nextFloat();
        float recyclerChance = level * 0.1F;
        if (recyclerRand <= recyclerChance) {
            ItemEntity arrowDrop = new ItemEntity(user.world, user.getX(), user.getY(), user.getZ(), new ItemStack(Items.ARROW));
            user.world.spawnEntity(arrowDrop);
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) DamageSource(net.minecraft.entity.damage.DamageSource) ItemStack(net.minecraft.item.ItemStack)

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