use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.
the class LivingEntityMixin_1_15 method dropExperience.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
protected void dropExperience() {
// if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT))) {
if (true) {
int i = bridge$getExpToDrop();
while (i > 0) {
int j = ExperienceOrbEntity.getXPSplit(i);
i -= j;
this.world.addEntity(new ExperienceOrbEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ(), j));
}
bridge$setExpToDrop(0);
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.
the class AbstractFurnaceTileEntityMixin method spawnExpOrbs.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private static void spawnExpOrbs(PlayerEntity entity, int ex, float f) {
if (f == 0.0F) {
ex = 0;
} else if (f < 1.0F) {
int i = MathHelper.floor((float) ex * f);
if (i < MathHelper.ceil((float) ex * f) && Math.random() < (double) ((float) ex * f - (float) i)) {
++i;
}
ex = i;
}
if (arclight$captureFurnace != null && arclight$captureAmount != 0) {
FurnaceExtractEvent event = new FurnaceExtractEvent(((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(arclight$captureFurnace.getWorld(), arclight$captureFurnace.getPos()), CraftMagicNumbers.getMaterial(arclight$item.getItem()), arclight$captureAmount, ex);
Bukkit.getPluginManager().callEvent(event);
ex = event.getExpToDrop();
}
while (ex > 0) {
int j = ExperienceOrbEntity.getXPSplit(ex);
ex -= j;
entity.world.addEntity(new ExperienceOrbEntity(entity.world, entity.posX, entity.posY + 0.5D, entity.posZ + 0.5D, j));
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method processUseEntity.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void processUseEntity(final CUseEntityPacket packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
return;
}
final ServerWorld world = this.minecraftServer.getWorld(this.player.dimension);
final Entity entity = packetIn.getEntityFromWorld(world);
this.player.markPlayerActive();
if (entity != null) {
final boolean flag = this.player.canEntityBeSeen(entity);
double d0 = 36.0;
if (!flag) {
d0 = 9.0;
}
if (this.player.getDistanceSq(entity) < d0) {
final ItemStack itemInHand = this.player.getHeldItem((packetIn.getHand() == null) ? Hand.MAIN_HAND : packetIn.getHand());
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT || packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof MobEntity;
final Item origItem = (this.player.inventory.getCurrentItem() == null) ? null : this.player.inventory.getCurrentItem().getItem();
PlayerInteractEntityEvent event;
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
event = new PlayerInteractEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
} else {
final Vec3d target = packetIn.getHitVec();
event = new PlayerInteractAtEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), new Vector(target.x, target.y, target.z), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
}
this.server.getPluginManager().callEvent(event);
if (entity instanceof AbstractFishEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SSpawnMobPacket((LivingEntity) entity));
this.player.sendContainerToPlayer(this.player.openContainer);
}
if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SMountEntityPacket(entity, ((MobEntity) entity).getLeashHolder()));
}
if (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem) {
this.sendPacket(new SEntityMetadataPacket(entity.getEntityId(), entity.getDataManager(), true));
}
if (event.isCancelled()) {
return;
}
}
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
final Hand hand = packetIn.getHand();
this.player.interactOn(entity, hand);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final Hand hand = packetIn.getHand();
if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, packetIn.getHitVec(), hand) != null)
return;
ActionResultType result = entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand);
if (result == ActionResultType.SUCCESS) {
this.player.swingArm(hand);
}
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.ATTACK) {
if (entity instanceof ItemEntity || entity instanceof ExperienceOrbEntity || entity instanceof AbstractArrowEntity || (entity == this.player && !this.player.isSpectator())) {
this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_entity_attacked"));
this.minecraftServer.logWarning("Player " + this.player.getName().getString() + " tried to attack an invalid entity");
return;
}
this.player.attackTargetEntityWithCurrentItem(entity);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
}
}
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project SimpleMagnets by SuperMartijn642.
the class MagnetItem method inventoryTick.
@Override
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
CompoundNBT tag = stack.getOrCreateTag();
if (tag.contains("active") && tag.getBoolean("active")) {
if (this.canPickupItems(tag)) {
int r = this.getRangeItems(tag);
AxisAlignedBB area = new AxisAlignedBB(entityIn.getCommandSenderWorldPosition().add(-r, -r, -r), entityIn.getCommandSenderWorldPosition().add(r, r, r));
List<ItemEntity> items = worldIn.getEntities(EntityType.ITEM, area, item -> item.isAlive() && (!worldIn.isClientSide || item.tickCount > 1) && (item.getThrower() == null || !item.getThrower().equals(entityIn.getUUID()) || !item.hasPickUpDelay()) && !item.getItem().isEmpty() && !item.getPersistentData().contains("PreventRemoteMovement") && this.canPickupStack(tag, item.getItem()));
items.forEach(item -> item.setPos(entityIn.getX(), entityIn.getY(), entityIn.getZ()));
// Directly add items to the player's inventory when ItemPhysic is installed
if (!worldIn.isClientSide && entityIn instanceof PlayerEntity && ModList.get().isLoaded("itemphysic"))
items.forEach(item -> playerTouch(item, (PlayerEntity) entityIn));
}
if (!worldIn.isClientSide && this.canPickupXp(tag) && entityIn instanceof PlayerEntity) {
int r = this.getRangeXp(tag);
AxisAlignedBB area = new AxisAlignedBB(entityIn.getCommandSenderWorldPosition().add(-r, -r, -r), entityIn.getCommandSenderWorldPosition().add(r, r, r));
PlayerEntity player = (PlayerEntity) entityIn;
List<ExperienceOrbEntity> orbs = worldIn.getEntitiesOfClass(ExperienceOrbEntity.class, area);
orbs.forEach(orb -> {
orb.throwTime = 0;
player.takeXpDelay = 0;
orb.playerTouch(player);
});
}
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by ldtteam.
the class NewBobberEntity method getDamage.
public int getDamage() {
if (!this.level.isClientSide && this.angler != null) {
int i = 0;
final net.minecraftforge.event.entity.player.ItemFishedEvent event = null;
if (this.caughtEntity != null) {
this.bringInHookedEntity();
this.level.broadcastEntityEvent(this, (byte) 31);
i = this.caughtEntity instanceof ItemEntity ? 3 : 5;
} else if (this.ticksCatchable > 0) {
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.level)).withParameter(LootParameters.ORIGIN, this.position()).withParameter(LootParameters.TOOL, this.getAngler().getMainHandItem()).withParameter(LootParameters.THIS_ENTITY, this).withRandom(this.random).withLuck((float) this.luck);
lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.angler).withParameter(LootParameters.THIS_ENTITY, this);
final LootTable loottable = this.level.getServer().getLootTables().get(ModLootTables.FISHING);
final List<ItemStack> list = loottable.getRandomItems(lootcontext$builder.create(LootParameterSets.FISHING));
for (final ItemStack itemstack : list) {
final ItemEntity itementity = new ItemEntity(this.level, onWaterPos.x, onWaterPos.y, onWaterPos.z, itemstack);
final double d0 = this.angler.getX() - onWaterPos.x;
final double d1 = (this.angler.getY() + 0.5D) - onWaterPos.y;
final double d2 = this.angler.getZ() - onWaterPos.z;
itementity.noPhysics = true;
itementity.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
this.level.addFreshEntity(itementity);
this.angler.level.addFreshEntity(new ExperienceOrbEntity(this.angler.level, this.angler.getX(), this.angler.getY() + 0.5D, this.angler.getZ() + 0.5D, XP_PER_CATCH));
}
i = 1;
}
if (this.inGround) {
i = 2;
}
this.remove();
return event == null ? i : event.getRodDamage();
} else {
return 0;
}
}
Aggregations