Search in sources :

Example 1 with BehaviorProjectileDispense

use of net.minecraft.dispenser.BehaviorProjectileDispense in project Gaspunk by Ladysnake.

the class CommonProxy method init.

public void init() {
    PacketHandler.initPackets();
    if (GasPunkConfig.alternativeAshRecipe)
        GameRegistry.addSmelting(Items.NETHER_WART, new ItemStack(ModItems.ASH), 0.8f);
    else
        GameRegistry.addSmelting(Items.ROTTEN_FLESH, new ItemStack(ModItems.ASH), 0.35f);
    if (Loader.isModLoaded("baubles"))
        MinecraftForge.EVENT_BUS.register(new BaublesCompatHandler());
    new Thread(SpecialRewardChecker::retrieveSpecialRewards).start();
    BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(ModItems.GRENADE, new BehaviorProjectileDispense() {

        @Nonnull
        @Override
        protected IProjectile getProjectileEntity(@Nonnull World worldIn, @Nonnull IPosition position, @Nonnull ItemStack stackIn) {
            EntityGrenade grenade = new EntityGrenade(worldIn);
            grenade.setItem(stackIn);
            return grenade;
        }
    });
}
Also used : IPosition(net.minecraft.dispenser.IPosition) BehaviorProjectileDispense(net.minecraft.dispenser.BehaviorProjectileDispense) Nonnull(javax.annotation.Nonnull) EntityGrenade(ladysnake.gaspunk.entity.EntityGrenade) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) BaublesCompatHandler(ladysnake.gaspunk.compat.BaublesCompatHandler) IProjectile(net.minecraft.entity.IProjectile)

Example 2 with BehaviorProjectileDispense

use of net.minecraft.dispenser.BehaviorProjectileDispense in project Galacticraft by micdoodle8.

the class GCFluids method registerDispenserBehaviours.

public static void registerDispenserBehaviours() {
    IBehaviorDispenseItem ibehaviordispenseitem = new BehaviorDefaultDispenseItem() {

        private final BehaviorDefaultDispenseItem dispenseBehavior = new BehaviorDefaultDispenseItem();

        @Override
        public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
            ItemBucketGC itembucket = (ItemBucketGC) stack.getItem();
            BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
            if (itembucket.tryPlaceContainedLiquid(source.getWorld(), blockpos)) {
                stack.setItem(Items.bucket);
                stack.stackSize = 1;
                return stack;
            } else {
                return this.dispenseBehavior.dispense(source, stack);
            }
        }
    };
    if (GCItems.bucketFuel != null) {
        BlockDispenser.dispenseBehaviorRegistry.putObject(GCItems.bucketFuel, ibehaviordispenseitem);
    }
    if (GCItems.bucketOil != null) {
        BlockDispenser.dispenseBehaviorRegistry.putObject(GCItems.bucketOil, ibehaviordispenseitem);
    }
    if (GalacticraftCore.isPlanetsLoaded) {
        if (MarsItems.bucketSludge != null) {
            BlockDispenser.dispenseBehaviorRegistry.putObject(MarsItems.bucketSludge, ibehaviordispenseitem);
        }
        if (VenusItems.bucketSulphuricAcid != null) {
            BlockDispenser.dispenseBehaviorRegistry.putObject(VenusItems.bucketSulphuricAcid, ibehaviordispenseitem);
        }
    }
    // The following code is for other objects, not liquids, but it's convenient to keep it all together
    BlockDispenser.dispenseBehaviorRegistry.putObject(GCItems.meteorChunk, new BehaviorProjectileDispense() {

        @Override
        protected IProjectile getProjectileEntity(World worldIn, IPosition position) {
            return new EntityMeteorChunk(worldIn);
        }

        @Override
        public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
            World world = source.getWorld();
            IPosition position = BlockDispenser.getDispensePosition(source);
            EnumFacing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
            EntityMeteorChunk meteor = new EntityMeteorChunk(world);
            meteor.setPosition(position.getX(), position.getY(), position.getZ());
            meteor.setThrowableHeading((double) enumfacing.getFrontOffsetX(), (double) ((float) enumfacing.getFrontOffsetY() + 0.1F), (double) enumfacing.getFrontOffsetZ(), 1.0F, this.func_82498_a());
            if (stack.getItemDamage() > 0) {
                meteor.setFire(20);
                meteor.isHot = true;
            }
            meteor.canBePickedUp = 1;
            world.spawnEntityInWorld((Entity) meteor);
            stack.splitStack(1);
            return stack;
        }
    });
    BlockDispenser.dispenseBehaviorRegistry.putObject(GCItems.rocketTier1, new BehaviorDefaultDispenseItem() {

        @Override
        public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
            World world = source.getWorld();
            BlockPos pos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()), 2);
            IBlockState iblockstate = world.getBlockState(pos);
            boolean rocketPlaced = false;
            if (iblockstate.getBlock() == GCBlocks.landingPadFull && GCBlocks.landingPadFull.getMetaFromState(iblockstate) == 0) {
                float centerX = pos.getX() + 0.5F;
                float centerY = pos.getY() + 0.4F;
                float centerZ = pos.getZ() + 0.5F;
                rocketPlaced = ItemTier1Rocket.placeRocketOnPad(stack, world, world.getTileEntity(pos), centerX, centerY, centerZ);
            }
            if (rocketPlaced) {
                stack.splitStack(1);
            }
            return stack;
        }
    });
    if (GalacticraftCore.isPlanetsLoaded) {
        BlockDispenser.dispenseBehaviorRegistry.putObject(MarsItems.rocketMars, new BehaviorDefaultDispenseItem() {

            @Override
            public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
                World world = source.getWorld();
                BlockPos pos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()), 2);
                IBlockState iblockstate = world.getBlockState(pos);
                boolean rocketPlaced = false;
                if (iblockstate.getBlock() == GCBlocks.landingPadFull && GCBlocks.landingPadFull.getMetaFromState(iblockstate) == 0) {
                    float centerX = pos.getX() + 0.5F;
                    float centerY = pos.getY() + 0.4F;
                    float centerZ = pos.getZ() + 0.5F;
                    rocketPlaced = ItemTier2Rocket.placeRocketOnPad(stack, world, world.getTileEntity(pos), centerX, centerY, centerZ);
                }
                if (rocketPlaced) {
                    stack.splitStack(1);
                }
                return stack;
            }
        });
        BlockDispenser.dispenseBehaviorRegistry.putObject(AsteroidsItems.tier3Rocket, new BehaviorDefaultDispenseItem() {

            @Override
            public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
                World world = source.getWorld();
                BlockPos pos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()), 2);
                IBlockState iblockstate = world.getBlockState(pos);
                boolean rocketPlaced = false;
                if (iblockstate.getBlock() == GCBlocks.landingPadFull && GCBlocks.landingPadFull.getMetaFromState(iblockstate) == 0) {
                    float centerX = pos.getX() + 0.5F;
                    float centerY = pos.getY() + 0.4F;
                    float centerZ = pos.getZ() + 0.5F;
                    rocketPlaced = ItemTier3Rocket.placeRocketOnPad(stack, world, world.getTileEntity(pos), centerX, centerY, centerZ);
                }
                if (rocketPlaced) {
                    stack.splitStack(1);
                }
                return stack;
            }
        });
    }
}
Also used : Entity(net.minecraft.entity.Entity) IPosition(net.minecraft.dispenser.IPosition) IBlockState(net.minecraft.block.state.IBlockState) IBehaviorDispenseItem(net.minecraft.dispenser.IBehaviorDispenseItem) EnumFacing(net.minecraft.util.EnumFacing) World(net.minecraft.world.World) IProjectile(net.minecraft.entity.IProjectile) BehaviorDefaultDispenseItem(net.minecraft.dispenser.BehaviorDefaultDispenseItem) IBlockSource(net.minecraft.dispenser.IBlockSource) BehaviorProjectileDispense(net.minecraft.dispenser.BehaviorProjectileDispense) ItemBucketGC(micdoodle8.mods.galacticraft.core.items.ItemBucketGC) EntityMeteorChunk(micdoodle8.mods.galacticraft.core.entities.EntityMeteorChunk) BlockPos(net.minecraft.util.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 3 with BehaviorProjectileDispense

use of net.minecraft.dispenser.BehaviorProjectileDispense in project Bewitchment by Um-Mitternacht.

the class ModEntities method init.

public static void init() {
    int id = 0;
    EntityRegistry.registerModEntity(getResource("brew_throwable"), EntityBrew.class, "brew_throwable", id++, Bewitchment.instance, 64, 1, true);
    EntityRegistry.registerModEntity(getResource("spell_carrier"), EntitySpellCarrier.class, "spell_carrier", id++, Bewitchment.instance, 64, 1, true);
    BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(ModItems.brew_phial_splash, new IBehaviorDispenseItem() {

        @Override
        public ItemStack dispense(IBlockSource source, final ItemStack stack) {
            return (new BehaviorProjectileDispense() {

                @Override
                protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn) {
                    return new EntityBrew(worldIn, position.getX(), position.getY(), position.getZ(), stack.copy(), EntityBrew.BrewDispersion.SPLASH);
                }

                @Override
                protected float getProjectileInaccuracy() {
                    return super.getProjectileInaccuracy() * 0.5F;
                }

                @Override
                protected float getProjectileVelocity() {
                    return super.getProjectileVelocity() * 1.25F;
                }
            }).dispense(source, stack);
        }
    });
    EntityRegistry.registerModEntity(getResource("broom"), EntityFlyingBroom.class, "broom", id++, Bewitchment.instance, 64, 1, true);
    EntityRegistry.registerModEntity(getResource("swarm"), EntityBatSwarm.class, "swarm", id++, Bewitchment.instance, 64, 1, true);
    EntityRegistry.registerModEntity(getResource("brew_linger"), EntityBrewLinger.class, "brew_linger", id, Bewitchment.instance, 64, 1, false);
    BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(ModItems.brew_phial_linger, new IBehaviorDispenseItem() {

        @Override
        public ItemStack dispense(IBlockSource source, final ItemStack stack) {
            return (new BehaviorProjectileDispense() {

                @Override
                protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn) {
                    return new EntityBrew(worldIn, position.getX(), position.getY(), position.getZ(), stack.copy(), EntityBrew.BrewDispersion.LINGER);
                }

                @Override
                protected float getProjectileInaccuracy() {
                    return super.getProjectileInaccuracy() * 0.5F;
                }

                @Override
                protected float getProjectileVelocity() {
                    return super.getProjectileVelocity() * 1.25F;
                }
            }).dispense(source, stack);
        }
    });
}
Also used : IPosition(net.minecraft.dispenser.IPosition) IBehaviorDispenseItem(net.minecraft.dispenser.IBehaviorDispenseItem) IBlockSource(net.minecraft.dispenser.IBlockSource) BehaviorProjectileDispense(net.minecraft.dispenser.BehaviorProjectileDispense) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) IProjectile(net.minecraft.entity.IProjectile)

Aggregations

BehaviorProjectileDispense (net.minecraft.dispenser.BehaviorProjectileDispense)3 IPosition (net.minecraft.dispenser.IPosition)3 IProjectile (net.minecraft.entity.IProjectile)3 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 IBehaviorDispenseItem (net.minecraft.dispenser.IBehaviorDispenseItem)2 IBlockSource (net.minecraft.dispenser.IBlockSource)2 Nonnull (javax.annotation.Nonnull)1 BaublesCompatHandler (ladysnake.gaspunk.compat.BaublesCompatHandler)1 EntityGrenade (ladysnake.gaspunk.entity.EntityGrenade)1 EntityMeteorChunk (micdoodle8.mods.galacticraft.core.entities.EntityMeteorChunk)1 ItemBucketGC (micdoodle8.mods.galacticraft.core.items.ItemBucketGC)1 IBlockState (net.minecraft.block.state.IBlockState)1 BehaviorDefaultDispenseItem (net.minecraft.dispenser.BehaviorDefaultDispenseItem)1 Entity (net.minecraft.entity.Entity)1 BlockPos (net.minecraft.util.BlockPos)1 EnumFacing (net.minecraft.util.EnumFacing)1