use of net.minecraft.entity.ItemEntity in project friends-and-foes by Faboslav.
the class MoobloomEntity method sheared.
public void sheared(SoundCategory shearedSoundCategory) {
this.world.playSoundFromEntity(null, this, SoundEvents.ENTITY_MOOSHROOM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
if (!this.world.isClient()) {
((ServerWorld) this.world).spawnParticles(ParticleTypes.EXPLOSION, this.getX(), this.getBodyY(0.5D), this.getZ(), 1, 0.0D, 0.0D, 0.0D, 0.0D);
this.discard();
CowEntity cowEntity = EntityType.COW.create(this.world);
if (cowEntity == null) {
return;
}
cowEntity.setHealth(this.getHealth());
cowEntity.copyPositionAndRotation(this);
cowEntity.prevBodyYaw = this.prevBodyYaw;
cowEntity.bodyYaw = this.bodyYaw;
cowEntity.prevHeadYaw = this.prevHeadYaw;
cowEntity.headYaw = this.headYaw;
if (this.hasCustomName()) {
cowEntity.setCustomName(this.getCustomName());
cowEntity.setCustomNameVisible(this.isCustomNameVisible());
}
if (this.isPersistent()) {
cowEntity.setPersistent();
}
cowEntity.setInvulnerable(this.isInvulnerable());
this.getEntityWorld().spawnEntity(cowEntity);
for (int i = 0; i < 5; ++i) {
this.getEntityWorld().spawnEntity(new ItemEntity(this.world, this.getX(), this.getBodyY(1.0D), this.getZ(), new ItemStack(ModBlocks.BUTTERCUP.get())));
}
}
}
use of net.minecraft.entity.ItemEntity in project Client by MatHax.
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)
MatHax.EVENT_BUS.post(PickItemsEvent.get(((ItemEntity) itemEntity).getStack(), packet.getStackAmount()));
}
use of net.minecraft.entity.ItemEntity in project AurorasDecorations by LambdAurora.
the class ShelfBlock method onBlockBreakStart.
@Override
public void onBlockBreakStart(BlockState state, World world, BlockPos pos, PlayerEntity player) {
var shelf = AurorasDecoRegistry.SHELF_BLOCK_ENTITY_TYPE.get(world, pos);
if (shelf != null && !shelf.isEmpty()) {
Direction facing = state.get(FACING);
var cameraPosVec = player.getCameraPosVec(1.0F);
var rotationVec = player.getRotationVec(1.0F);
var extendedVec = cameraPosVec.add(rotationVec.x * 4.5F, rotationVec.y * 4.5F, rotationVec.z * 4.5F);
var rayCtx = new RaycastContext(cameraPosVec, extendedVec, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, player);
var hit = world.raycast(rayCtx);
int y = 0;
if (AuroraUtil.posMod(hit.getPos().getY(), 1) <= 0.5)
y = 1;
int x;
if (facing.getAxis() == Direction.Axis.Z) {
x = (int) (AuroraUtil.posMod(hit.getPos().getX(), 1) * 4.0);
} else {
x = 3 - (int) (AuroraUtil.posMod(hit.getPos().getZ(), 1) * 4.0);
}
if (facing.getDirection() == Direction.AxisDirection.NEGATIVE) {
x = 3 - x;
}
int slot = y * 4 + x;
var stack = shelf.getStack(slot);
if (!stack.isEmpty()) {
if (player.getStackInHand(Hand.MAIN_HAND).isEmpty()) {
player.setStackInHand(Hand.MAIN_HAND, stack.copy());
shelf.removeStack(slot);
} else {
var item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack.copy());
float speed = world.random.nextFloat() * .5f;
float angle = world.random.nextFloat() * 6.2831855f;
item.setVelocity(-MathHelper.sin(angle) * speed, 0.20000000298023224, MathHelper.cos(angle) * speed);
world.spawnEntity(item);
shelf.removeStack(slot);
}
world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos);
}
}
}
use of net.minecraft.entity.ItemEntity in project Terracraft by SimplyCmd.
the class SickleItem method postMine.
@Override
public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) {
if (miner instanceof ServerPlayerEntity && !((ServerPlayerEntity) miner).isCreative() && state.getBlock() instanceof FernBlock) {
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), BlockRegistry.grass_bale.getItem().get().getDefaultStack());
entity.updatePosition(pos.getX(), pos.getY(), pos.getZ());
world.spawnEntity(entity);
}
stack.damage(1, miner, (e) -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
return true;
}
use of net.minecraft.entity.ItemEntity in project Terracraft by SimplyCmd.
the class CoinPortalEntity method tick.
@Override
public void tick() {
tick++;
if (tick % 10 == 0) {
ItemEntity coin = new ItemEntity(world, this.getX(), this.getY(), this.getZ(), ItemRegistry.gold_coin.getItem().getDefaultStack());
world.spawnEntity(coin);
}
if (tick >= 100)
kill();
this.move(MovementType.SELF, this.getVelocity());
this.baseTick();
}
Aggregations