Search in sources :

Example 6 with ItemEntity

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

the class ItemStackMixin method damage.

// When the Mechanised Sawblade breaks, it "becomes" the Broken Sawblade
@Inject(at = @At("HEAD"), method = "damage(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V")
public <T extends LivingEntity> void damage(int amount, T entity, Consumer<T> breakCallback, CallbackInfo ci) {
    World world = entity.getEntityWorld();
    if (getItem() == ItemRegistry.getItem("sword_mechanized_sawblade") && getDamage() + amount >= getMaxDamage()) {
        ItemEntity brokenSawbladeDrop = new ItemEntity(entity.world, entity.getX(), entity.getY(), entity.getZ(), new ItemStack(ItemRegistry.getItem("sword_broken_sawblade")));
        world.spawnEntity(brokenSawbladeDrop);
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with ItemEntity

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

the class ReplenishEnchantmentMixin method applyReplenishEnchantmentDamage.

@Inject(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", at = @At("HEAD"))
public void applyReplenishEnchantmentDamage(DamageSource source, float amount, CallbackInfo info) {
    if (!(source.getAttacker() instanceof PlayerEntity))
        return;
    LivingEntity user = (LivingEntity) source.getAttacker();
    if (source.isProjectile()) {
        if (amount != 0.0F) {
            ItemStack mainHandStack = null;
            if (user != null) {
                mainHandStack = user.getMainHandStack();
            }
            if (McdwEnchantsConfig.getValue("replenish")) {
                if (mainHandStack != null && (EnchantmentHelper.getLevel(EnchantsRegistry.REPLENISH, mainHandStack) >= 1)) {
                    int level = EnchantmentHelper.getLevel(EnchantsRegistry.REPLENISH, mainHandStack);
                    if (user instanceof PlayerEntity) {
                        if (level >= 1) {
                            float replenishRand = user.getRandom().nextFloat();
                            float replenishChance = 0;
                            if (level == 1)
                                replenishChance = 0.10f;
                            if (level == 2)
                                replenishChance = 0.17f;
                            if (level == 3)
                                replenishChance = 0.24f;
                            if (replenishRand <= replenishChance) {
                                ItemEntity arrowDrop = new ItemEntity(user.world, user.getX(), user.getY(), user.getZ(), new ItemStack(Items.ARROW));
                                user.world.spawnEntity(arrowDrop);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.ItemEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with ItemEntity

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

the class ProspectorEnchantmentMixin method onProspectorEnchantmentKill.

@Inject(at = @At("HEAD"), method = "onDeath", cancellable = true)
private void onProspectorEnchantmentKill(DamageSource source, CallbackInfo ci) {
    if (!(source.getAttacker() instanceof PlayerEntity))
        return;
    LivingEntity user = (LivingEntity) source.getAttacker();
    LivingEntity target = (LivingEntity) (Object) this;
    ItemStack mainHandStack = null;
    if (user != null) {
        mainHandStack = user.getMainHandStack();
    }
    if (McdwEnchantsConfig.getValue("prospector")) {
        if (mainHandStack != null && (EnchantmentHelper.getLevel(EnchantsRegistry.PROSPECTOR, mainHandStack) >= 1)) {
            int level = EnchantmentHelper.getLevel(EnchantsRegistry.PROSPECTOR, mainHandStack);
            float prospectorChance = 0.05F * level;
            float prospectorRand = user.getRandom().nextFloat();
            if (prospectorRand <= prospectorChance) {
                if (target instanceof Monster) {
                    ItemEntity emeraldDrop = new ItemEntity(target.world, target.getX(), target.getY(), target.getZ(), new ItemStack(Items.EMERALD, 1));
                    user.world.spawnEntity(emeraldDrop);
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.ItemEntity) Monster(net.minecraft.entity.mob.Monster) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with ItemEntity

use of net.minecraft.entity.ItemEntity in project meteor-client by MeteorDevelopment.

the class ClientPlayNetworkHandlerMixin method onItemPickupAnimation.

@Inject(method = "onItemPickupAnimation", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getEntityById(I)Lnet/minecraft/entity/Entity;", ordinal = 0))
private void onItemPickupAnimation(ItemPickupAnimationS2CPacket packet, CallbackInfo info) {
    Entity itemEntity = client.world.getEntityById(packet.getEntityId());
    Entity entity = client.world.getEntityById(packet.getCollectorEntityId());
    if (itemEntity instanceof ItemEntity && entity == client.player) {
        MeteorClient.EVENT_BUS.post(PickItemsEvent.get(((ItemEntity) itemEntity).getStack(), packet.getStackAmount()));
    }
}
Also used : Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.ItemEntity) ItemEntity(net.minecraft.entity.ItemEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with ItemEntity

use of net.minecraft.entity.ItemEntity in project Sprout by Toadstool-Studios.

the class EatFoodGoal method canStart.

@Override
public boolean canStart() {
    ItemEntity nearFood = elephant.isNearFood();
    if (nearFood != null) {
        this.foodEntity = nearFood;
        this.foodStackCopy = nearFood.getStack().copy();
        BlockPos targetPosition = nearFood.getBlockPos();
        return Math.sqrt(targetPosition.getSquaredDistance(elephant.getPos())) - 1 <= 1 && this.isPreocupied();
    }
    return false;
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) BlockPos(net.minecraft.util.math.BlockPos)

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