From 3cbce466883152b4fed4810b3877acdd2aa866e9 Mon Sep 17 00:00:00 2001 From: afamiliarquiet Date: Fri, 1 Nov 2024 14:49:41 -0700 Subject: [PATCH] give offerings --- .../entity/SummoningTableBlockEntity.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/io/github/afamiliarquiet/familiar_magic/block/entity/SummoningTableBlockEntity.java b/src/main/java/io/github/afamiliarquiet/familiar_magic/block/entity/SummoningTableBlockEntity.java index 325ed5a..b64a019 100644 --- a/src/main/java/io/github/afamiliarquiet/familiar_magic/block/entity/SummoningTableBlockEntity.java +++ b/src/main/java/io/github/afamiliarquiet/familiar_magic/block/entity/SummoningTableBlockEntity.java @@ -22,6 +22,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; +import net.minecraft.world.Containers; import net.minecraft.world.LockCode; import net.minecraft.world.MenuProvider; import net.minecraft.world.Nameable; @@ -225,6 +226,8 @@ public void acceptSummoning(LivingEntity livingTarget) { pathfindermob.getNavigation().stop(); } + this.giveOfferings(livingTarget); + level.gameEvent(GameEvent.TELEPORT, livingTarget.position(), GameEvent.Context.of(livingTarget)); level.broadcastEntityEvent(livingTarget, (byte)46); level.playSound(null, this.getBlockPos(), SoundEvents.PLAYER_TELEPORT, SoundSource.BLOCKS, 1, 1); @@ -235,6 +238,25 @@ public void acceptSummoning(LivingEntity livingTarget) { } } + private void giveOfferings(LivingEntity target) { + if (level == null || level.isClientSide) { + // this isn't happening. chill out, relax, it's fine + return; + } + BlockPos pos = this.getBlockPos(); + for (int i = 0; i < this.offerings.getSlots(); i++) { + ItemStack offering = this.offerings.getStackInSlot(i); + if (target instanceof ServerPlayer player) { + if (!player.getInventory().add(offering)) { + Containers.dropItemStack(level, pos.getX(), pos.getY()+1, pos.getZ(), offering); + } + } else { + // todo - feed the critters + Containers.dropItemStack(level, pos.getX(), pos.getY()+1, pos.getZ(), offering); + } + } + } + public BlockState tryBurnName(BlockState state, boolean simulate) { // this fails on client because client can't see the true name. maybe that's a problem to deal with? idk