From aa973eabee6f66887a327ac87bfa89b146439c0c Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Fri, 27 Dec 2024 09:50:03 +0100 Subject: [PATCH] dispenser place hat stand --- .../dispenser/DispenserBehaviorsManager.java | 3 ++ .../dispenser/PlaceHatStandBehavior.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/PlaceHatStandBehavior.java diff --git a/common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/DispenserBehaviorsManager.java b/common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/DispenserBehaviorsManager.java index e6237aaa6..88e42aaf0 100644 --- a/common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/DispenserBehaviorsManager.java +++ b/common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/DispenserBehaviorsManager.java @@ -50,6 +50,9 @@ public static void registerBehaviors(DispenserHelper.Event event) { event.register(new EmptyContainerItemBehavior(ModRegistry.LUNCH_BASKET_ITEM.get())); event.register(new EmptyContainerItemBehavior(ModRegistry.QUIVER_ITEM.get())); } + if(CommonConfigs.Building.HAT_STAND_ENABLED.get()){ + event.register(new PlaceHatStandBehavior(ModRegistry.HAT_STAND.get())); + } if (CommonConfigs.Tweaks.ENDER_PEAR_DISPENSERS.get()) { event.register(new ThrowableEnderPearlBehavior()); diff --git a/common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/PlaceHatStandBehavior.java b/common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/PlaceHatStandBehavior.java new file mode 100644 index 000000000..6582cbfd7 --- /dev/null +++ b/common/src/main/java/net/mehvahdjukaar/supplementaries/common/block/dispenser/PlaceHatStandBehavior.java @@ -0,0 +1,39 @@ +package net.mehvahdjukaar.supplementaries.common.block.dispenser; + +import net.mehvahdjukaar.moonlight.api.util.DispenserHelper; +import net.mehvahdjukaar.supplementaries.common.entities.HatStandEntity; +import net.mehvahdjukaar.supplementaries.reg.ModEntities; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.dispenser.BlockSource; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.DispenserBlock; + +import java.util.function.Consumer; + +public class PlaceHatStandBehavior extends DispenserHelper.AdditionalDispenserBehavior { + public PlaceHatStandBehavior(Item item) { + super(item); + } + + @Override + protected InteractionResultHolder customBehavior(BlockSource blockSource, ItemStack itemStack) { + Direction direction = blockSource.state().getValue(DispenserBlock.FACING); + BlockPos blockPos = blockSource.pos().relative(direction); + ServerLevel serverLevel = blockSource.level(); + Consumer consumer = EntityType.appendDefaultStackConfig((armorStandx) -> { + armorStandx.setYRot(direction.toYRot()); + }, serverLevel, itemStack, null); + HatStandEntity armorStand = ModEntities.HAT_STAND.get().spawn(serverLevel, consumer, blockPos, MobSpawnType.DISPENSER, false, false); + if (armorStand != null) { + itemStack.shrink(1); + } + + return InteractionResultHolder.success(itemStack); + } +}