Search in sources :

Example 1 with FallibleItemDispenserBehavior

use of net.minecraft.block.dispenser.FallibleItemDispenserBehavior in project Biome-Makeover by Lemonszz.

the class BMWorldEvents method init.

public static void init() {
    DispenserBlock.registerBehavior(Items.CROSSBOW, new FallibleItemDispenserBehavior() {

        public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
            BlockPos blockPos = pointer.getBlockPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
            List<StoneGolemEntity> list = pointer.getWorld().getEntitiesByClass(StoneGolemEntity.class, new Box(blockPos), (golem) -> !golem.isHolding(Items.CROSSBOW) && golem.isPlayerCreated() && golem.isAlive());
            if (!list.isEmpty()) {
                list.get(0).equipStack(EquipmentSlot.MAINHAND, stack.copy());
                stack.decrement(1);
                this.setSuccess(true);
                return stack;
            } else {
                return super.dispenseSilently(pointer, stack);
            }
        }
    });
    // Adjudicator Drop Illunite Shard
    ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register((world, entity, killedEntity) -> {
        if (!world.isClient() && entity instanceof PlayerEntity && killedEntity instanceof EvokerEntity) {
            if (!LootBlocker.isBlocked(killedEntity)) {
                if (world.random.nextFloat() < 0.15F) {
                    killedEntity.dropStack(new ItemStack(BMItems.ILLUNITE_SHARD, 1 + world.random.nextInt(2)));
                }
            }
        }
    });
}
Also used : CarvedPumpkinBlockAccess(party.lemons.biomemakeover.util.access.CarvedPumpkinBlockAccess) StoneGolemEntity(party.lemons.biomemakeover.entity.StoneGolemEntity) ServerWorld(net.minecraft.server.world.ServerWorld) BlockPointer(net.minecraft.util.math.BlockPointer) EvokerEntity(net.minecraft.entity.mob.EvokerEntity) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) net.minecraft.block(net.minecraft.block) BlockPlacer(net.minecraft.world.gen.placer.BlockPlacer) LootBlocker(party.lemons.biomemakeover.util.extensions.LootBlocker) SmallLilyPadBlock(party.lemons.biomemakeover.block.SmallLilyPadBlock) EquipmentSlot(net.minecraft.entity.EquipmentSlot) DoublePlantPlacer(net.minecraft.world.gen.placer.DoublePlantPlacer) FallibleItemDispenserBehavior(net.minecraft.block.dispenser.FallibleItemDispenserBehavior) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) Box(net.minecraft.util.math.Box) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) BlockPatternBuilder(net.minecraft.block.pattern.BlockPatternBuilder) BlockPattern(net.minecraft.block.pattern.BlockPattern) SimpleBlockPlacer(net.minecraft.world.gen.placer.SimpleBlockPlacer) List(java.util.List) BMBlocks(party.lemons.biomemakeover.init.BMBlocks) MaterialPredicate(net.minecraft.util.function.MaterialPredicate) ServerEntityCombatEvents(net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents) BlockStatePredicate(net.minecraft.predicate.block.BlockStatePredicate) CachedBlockPosition(net.minecraft.block.pattern.CachedBlockPosition) BMItems(party.lemons.biomemakeover.init.BMItems) StoneGolemEntity(party.lemons.biomemakeover.entity.StoneGolemEntity) EvokerEntity(net.minecraft.entity.mob.EvokerEntity) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) Box(net.minecraft.util.math.Box) BlockPointer(net.minecraft.util.math.BlockPointer) ItemStack(net.minecraft.item.ItemStack) FallibleItemDispenserBehavior(net.minecraft.block.dispenser.FallibleItemDispenserBehavior) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

List (java.util.List)1 Random (java.util.Random)1 ServerEntityCombatEvents (net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents)1 net.minecraft.block (net.minecraft.block)1 FallibleItemDispenserBehavior (net.minecraft.block.dispenser.FallibleItemDispenserBehavior)1 BlockPattern (net.minecraft.block.pattern.BlockPattern)1 BlockPatternBuilder (net.minecraft.block.pattern.BlockPatternBuilder)1 CachedBlockPosition (net.minecraft.block.pattern.CachedBlockPosition)1 EquipmentSlot (net.minecraft.entity.EquipmentSlot)1 EvokerEntity (net.minecraft.entity.mob.EvokerEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 Items (net.minecraft.item.Items)1 BlockStatePredicate (net.minecraft.predicate.block.BlockStatePredicate)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 MaterialPredicate (net.minecraft.util.function.MaterialPredicate)1 BlockPointer (net.minecraft.util.math.BlockPointer)1 BlockPos (net.minecraft.util.math.BlockPos)1 Box (net.minecraft.util.math.Box)1 World (net.minecraft.world.World)1