Search in sources :

Example 1 with DefaultDispenseItemBehavior

use of net.minecraft.dispenser.DefaultDispenseItemBehavior in project Champions by TheIllusiveC4.

the class Champions method setup.

private void setup(final FMLCommonSetupEvent evt) {
    ChampionCapability.register();
    NetworkHandler.register();
    AffixManager.register();
    evt.enqueueWork(() -> {
        Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation(Champions.MODID, "entity_champion"), EntityIsChampion.type);
        DefaultDispenseItemBehavior dispenseBehavior = new DefaultDispenseItemBehavior() {

            @Nonnull
            @Override
            public ItemStack dispenseStack(IBlockSource source, @Nonnull ItemStack stack) {
                Direction direction = source.getBlockState().get(DispenserBlock.FACING);
                Optional<EntityType<?>> entitytype = ChampionEggItem.getType(stack);
                entitytype.ifPresent(type -> {
                    Entity entity = type.create(source.getWorld(), stack.getTag(), null, null, source.getBlockPos().offset(direction), SpawnReason.DISPENSER, true, direction != Direction.UP);
                    if (entity instanceof LivingEntity) {
                        ChampionCapability.getCapability((LivingEntity) entity).ifPresent(champion -> ChampionEggItem.read(champion, stack));
                        source.getWorld().addEntity(entity);
                        stack.shrink(1);
                    }
                });
                return stack;
            }
        };
        DispenserBlock.registerDispenseBehavior(ChampionsRegistry.EGG, dispenseBehavior);
        ArgumentTypes.register(Champions.MODID + ":affix", AffixArgument.class, new ArgumentSerializer<>(AffixArgument::affix));
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) DefaultDispenseItemBehavior(net.minecraft.dispenser.DefaultDispenseItemBehavior) IBlockSource(net.minecraft.dispenser.IBlockSource) Nonnull(javax.annotation.Nonnull) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 2 with DefaultDispenseItemBehavior

use of net.minecraft.dispenser.DefaultDispenseItemBehavior in project bioplethora by AquexTheSeal.

the class BioplethoraSpawnEggItem method initUnaddedEggs.

public static void initUnaddedEggs() {
    final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
    DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior() {

        @Override
        public ItemStack execute(IBlockSource source, ItemStack stack) {
            Direction direction = source.getBlockState().getValue(DispenserBlock.FACING);
            EntityType<?> entitytype = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
            entitytype.spawn(source.getLevel(), stack, null, source.getPos().relative(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
            stack.shrink(1);
            return stack;
        }
    };
    for (final SpawnEggItem egg : UNADDED_EGGS) {
        EGGS.put(egg.getType(null), egg);
        DispenserBlock.registerBehavior(egg, defaultDispenseItemBehavior);
    }
    UNADDED_EGGS.clear();
}
Also used : EntityType(net.minecraft.entity.EntityType) DefaultDispenseItemBehavior(net.minecraft.dispenser.DefaultDispenseItemBehavior) IBlockSource(net.minecraft.dispenser.IBlockSource) SpawnEggItem(net.minecraft.item.SpawnEggItem) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 3 with DefaultDispenseItemBehavior

use of net.minecraft.dispenser.DefaultDispenseItemBehavior in project Mekanism by mekanism.

the class MekanismAdditions method commonSetup.

private void commonSetup(FMLCommonSetupEvent event) {
    event.enqueueWork(() -> {
        // Ensure our tags are all initialized
        AdditionsTags.init();
        // Setup some stuff related to entities
        SpawnHelper.setupEntities();
        // Dispenser behavior
        DispenserBlock.registerBehavior(AdditionsBlocks.OBSIDIAN_TNT, new DefaultDispenseItemBehavior() {

            @Nonnull
            @Override
            protected ItemStack execute(@Nonnull IBlockSource source, @Nonnull ItemStack stack) {
                BlockPos blockpos = source.getPos().relative(source.getBlockState().getValue(DispenserBlock.FACING));
                BlockObsidianTNT.createAndAddEntity(source.getLevel(), blockpos, null);
                stack.shrink(1);
                return stack;
            }
        });
    });
    Mekanism.logger.info("Loaded 'Mekanism: Additions' module.");
}
Also used : DefaultDispenseItemBehavior(net.minecraft.dispenser.DefaultDispenseItemBehavior) Nonnull(javax.annotation.Nonnull) IBlockSource(net.minecraft.dispenser.IBlockSource) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

DefaultDispenseItemBehavior (net.minecraft.dispenser.DefaultDispenseItemBehavior)3 IBlockSource (net.minecraft.dispenser.IBlockSource)3 ItemStack (net.minecraft.item.ItemStack)3 Nonnull (javax.annotation.Nonnull)2 EntityType (net.minecraft.entity.EntityType)2 Direction (net.minecraft.util.Direction)2 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 SpawnEggItem (net.minecraft.item.SpawnEggItem)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1