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);
}
}
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);
}
}
}
}
}
}
}
}
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);
}
}
}
}
}
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()));
}
}
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;
}
Aggregations