Skip to content

Commit

Permalink
dispenser place hat stand
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed Dec 27, 2024
1 parent 9bf5c13 commit aa973ea
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ItemStack> customBehavior(BlockSource blockSource, ItemStack itemStack) {
Direction direction = blockSource.state().getValue(DispenserBlock.FACING);
BlockPos blockPos = blockSource.pos().relative(direction);
ServerLevel serverLevel = blockSource.level();
Consumer<HatStandEntity> 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);
}
}

0 comments on commit aa973ea

Please sign in to comment.