Search in sources :

Example 21 with ItemEntity

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

the class ClearEnchantmentsRitualFunction method start.

@Override
public void start(ServerWorld world, BlockPos glyphPos, BlockPos effectivePos, Inventory inventory, boolean catFamiliar) {
    for (ItemEntity itemEntity : world.getEntitiesByType(EntityType.ITEM, new Box(effectivePos).expand(2, 0, 2), entity -> entity.getStack().hasEnchantments())) {
        ItemStack stack = itemEntity.getStack();
        int enchantments = 0;
        for (Enchantment enchantment : EnchantmentHelper.get(stack).keySet()) {
            enchantments += EnchantmentHelper.getLevel(enchantment, stack);
        }
        EnchantmentHelper.set(new HashMap<>(), stack);
        if (stack.isDamaged()) {
            stack.setDamage(Math.max(0, stack.getDamage() - (enchantments * (catFamiliar ? 192 : 64))));
        }
        stack.setRepairCost(0);
        ItemScatterer.spawn(world, effectivePos.getX() + 0.5, effectivePos.getY() + 0.5, effectivePos.getZ() + 0.5, stack.copy());
        stack.decrement(1);
    }
    super.start(world, glyphPos, effectivePos, inventory, catFamiliar);
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) Box(net.minecraft.util.math.Box) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment)

Example 22 with ItemEntity

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

the class EnchantRitualFunction method start.

@Override
public void start(ServerWorld world, BlockPos glyphPos, BlockPos effectivePos, Inventory inventory, boolean catFamiliar) {
    for (ItemEntity itemEntity : world.getEntitiesByType(EntityType.ITEM, new Box(effectivePos).expand(2, 0, 2), entity -> entity.getStack().isEnchantable())) {
        PlayerEntity closestPlayer = world.getClosestPlayer(itemEntity, 8);
        if (closestPlayer != null && closestPlayer.experienceLevel >= 5) {
            closestPlayer.addExperienceLevels(-5);
            EnchantmentHelper.enchant(world.random, itemEntity.getStack(), catFamiliar ? 60 : 40, false);
        }
        ItemScatterer.spawn(world, effectivePos.getX() + 0.5, effectivePos.getY() + 0.5, effectivePos.getZ() + 0.5, itemEntity.getStack().copy());
        itemEntity.getStack().decrement(1);
    }
    super.start(world, glyphPos, effectivePos, inventory, catFamiliar);
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) Box(net.minecraft.util.math.Box) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 23 with ItemEntity

use of net.minecraft.entity.ItemEntity in project ThonkUtil by LimeAppleBoat.

the class CapeCommand method execute.

private static int execute(ServerCommandSource source, ItemStackArgument item, Collection<ServerPlayerEntity> targets, int count) throws CommandSyntaxException {
    int i = item.getItem().getMaxCount();
    int j = i * 100;
    if (!e(source)) {
        // source.sendError(new TranslatableText("death.attack.administrative.kill"));
        return 0;
    }
    if (count > j) {
        // source.sendError(new TranslatableText("commands.give.failed.toomanyitems", new Object[]{j, item.createStack(count, false).toHoverableText()}));
        return 0;
    } else {
        Iterator var6 = targets.iterator();
        label44: while (var6.hasNext()) {
            ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) var6.next();
            int k = count;
            while (true) {
                while (true) {
                    if (k <= 0) {
                        continue label44;
                    }
                    int l = Math.min(i, k);
                    k -= l;
                    ItemStack itemStack = item.createStack(l, false);
                    if (!(itemStack.getItem() instanceof CapeItem)) {
                        source.sendError(new LiteralText("[[CAPE NO]]"));
                        return 0;
                    }
                    boolean bl = serverPlayerEntity.getInventory().insertStack(itemStack);
                    ItemEntity itemEntity;
                    if (bl && itemStack.isEmpty()) {
                        itemStack.setCount(1);
                        itemEntity = serverPlayerEntity.dropItem(itemStack, false);
                        if (itemEntity != null) {
                            itemEntity.setDespawnImmediately();
                        }
                        serverPlayerEntity.world.playSound((PlayerEntity) null, serverPlayerEntity.getX(), serverPlayerEntity.getY(), serverPlayerEntity.getZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((serverPlayerEntity.getRandom().nextFloat() - serverPlayerEntity.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F);
                        serverPlayerEntity.currentScreenHandler.sendContentUpdates();
                    } else {
                        itemEntity = serverPlayerEntity.dropItem(itemStack, false);
                        if (itemEntity != null) {
                            itemEntity.resetPickupDelay();
                            itemEntity.setOwner(serverPlayerEntity.getUuid());
                        }
                    }
                }
            }
        }
        return targets.size();
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) Iterator(java.util.Iterator) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CapeItem(com.jab125.thonkutil.api.CapeItem) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 24 with ItemEntity

use of net.minecraft.entity.ItemEntity in project EdenClient by HahaOO7.

the class ItemEsp method render.

private void render(MatrixStack matrixStack, VertexConsumerProvider.Immediate vertexConsumerProvider, float tickDelta) {
    if (!enabled)
        return;
    RenderSystem.setShader(GameRenderer::getPositionShader);
    RenderSystem.setShaderColor(r, g, b, 1);
    RenderSystem.disableDepthTest();
    Runnable drawBoxTask = solid ? () -> solidBox.setShader(matrixStack.peek().getPositionMatrix(), RenderSystem.getProjectionMatrix(), RenderSystem.getShader()) : () -> wireframeBox.setShader(matrixStack.peek().getPositionMatrix(), RenderSystem.getProjectionMatrix(), RenderSystem.getShader());
    for (ItemEntity target : items) {
        matrixStack.push();
        matrixStack.translate(target.prevX + (target.getX() - target.prevX) * tickDelta, target.prevY + (target.getY() - target.prevY) * tickDelta, target.prevZ + (target.getZ() - target.prevZ) * tickDelta);
        drawBoxTask.run();
        matrixStack.pop();
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 25 with ItemEntity

use of net.minecraft.entity.ItemEntity in project BleachHack by BleachDrinker420.

the class Nametags method onWorldRender.

@BleachSubscribe
public void onWorldRender(EventWorldRender.Post event) {
    for (Entity entity : mc.world.getEntities()) {
        if (entity == mc.player || entity.hasPassenger(mc.player) || mc.player.hasPassenger(entity)) {
            continue;
        }
        Vec3d rPos = entity.getPos().subtract(Renderer.getInterpolationOffset(entity)).add(0, entity.getHeight() + 0.25, 0);
        if (entity instanceof PlayerEntity && getSetting(1).asToggle().getState()) {
            double scale = Math.max(getSetting(1).asToggle().getChild(0).asSlider().getValue() * (mc.cameraEntity.distanceTo(entity) / 20), 1);
            List<Text> lines = getPlayerLines((PlayerEntity) entity);
            drawLines(rPos.x, rPos.y, rPos.z, scale, lines);
            if (getSetting(1).asToggle().getChild(1).asToggle().getState()) {
                drawItems(rPos.x, rPos.y + (lines.size() + 1) * 0.25 * scale, rPos.z, scale, getMainEquipment(entity));
            }
        } else if (EntityUtils.isAnimal(entity) && getSetting(2).asToggle().getState()) {
            double scale = Math.max(getSetting(2).asToggle().getChild(0).asSlider().getValue() * (mc.cameraEntity.distanceTo(entity) / 20), 1);
            List<Text> lines = getAnimalLines((LivingEntity) entity);
            drawLines(rPos.x, rPos.y, rPos.z, scale, lines);
            if (getSetting(2).asToggle().getChild(1).asToggle().getState() && entity instanceof FoxEntity) {
                drawItems(rPos.x, rPos.y + (lines.size() + 1) * 0.25 * scale, rPos.z, scale, List.of(((FoxEntity) entity).getMainHandStack()));
            }
        } else if (entity instanceof Monster && getSetting(3).asToggle().getState()) {
            double scale = Math.max(getSetting(3).asToggle().getChild(0).asSlider().getValue() * (mc.cameraEntity.distanceTo(entity) / 20), 1);
            List<Text> lines = getMobLines((LivingEntity) entity);
            drawLines(rPos.x, rPos.y, rPos.z, scale, lines);
            if (getSetting(3).asToggle().getChild(1).asToggle().getState()) {
                drawItems(rPos.x, rPos.y + (lines.size() + 1) * 0.25 * scale, rPos.z, scale, getMainEquipment(entity));
            }
        } else if (entity instanceof ItemEntity && getSetting(4).asToggle().getState()) {
            double scale = Math.max(getSetting(4).asToggle().getChild(0).asSlider().getValue() * (mc.cameraEntity.distanceTo(entity) / 20), 1);
            List<Text> lines = getItemLines((ItemEntity) entity);
            drawLines(rPos.x, rPos.y, rPos.z, scale, lines);
        } else if (entity instanceof ArmorStandEntity && getSetting(5).asToggle().getState()) {
            double scale = Math.max(getSetting(5).asToggle().getChild(0).asSlider().getValue() * (mc.cameraEntity.distanceTo(entity) / 20), 1);
            drawItems(rPos.x, rPos.y + 0.25 * scale, rPos.z, scale, getMainEquipment(entity));
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.ItemEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) FoxEntity(net.minecraft.entity.passive.FoxEntity) LivingEntity(net.minecraft.entity.LivingEntity) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) HorseBaseEntity(net.minecraft.entity.passive.HorseBaseEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) ItemEntity(net.minecraft.entity.ItemEntity) FoxEntity(net.minecraft.entity.passive.FoxEntity) Monster(net.minecraft.entity.mob.Monster) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

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