Search in sources :

Example 1 with EntityMeteorChunk

use of micdoodle8.mods.galacticraft.core.entities.EntityMeteorChunk 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 2 with EntityMeteorChunk

use of micdoodle8.mods.galacticraft.core.entities.EntityMeteorChunk in project Galacticraft by micdoodle8.

the class ItemMeteorChunk method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    if (!player.capabilities.isCreativeMode) {
        --itemStack.stackSize;
    }
    world.playSoundAtEntity(player, "random.bow", 1.0F, 0.0001F / (Item.itemRand.nextFloat() * 0.1F));
    if (!world.isRemote) {
        EntityMeteorChunk meteor = new EntityMeteorChunk(world, player, 1.0F);
        if (itemStack.getItemDamage() > 0) {
            meteor.setFire(20);
            meteor.isHot = true;
        }
        meteor.canBePickedUp = player.capabilities.isCreativeMode ? 2 : 1;
        world.spawnEntityInWorld(meteor);
    }
    player.swingItem();
    return itemStack;
}
Also used : EntityMeteorChunk(micdoodle8.mods.galacticraft.core.entities.EntityMeteorChunk)

Aggregations

EntityMeteorChunk (micdoodle8.mods.galacticraft.core.entities.EntityMeteorChunk)2 ItemBucketGC (micdoodle8.mods.galacticraft.core.items.ItemBucketGC)1 IBlockState (net.minecraft.block.state.IBlockState)1 BehaviorDefaultDispenseItem (net.minecraft.dispenser.BehaviorDefaultDispenseItem)1 BehaviorProjectileDispense (net.minecraft.dispenser.BehaviorProjectileDispense)1 IBehaviorDispenseItem (net.minecraft.dispenser.IBehaviorDispenseItem)1 IBlockSource (net.minecraft.dispenser.IBlockSource)1 IPosition (net.minecraft.dispenser.IPosition)1 Entity (net.minecraft.entity.Entity)1 IProjectile (net.minecraft.entity.IProjectile)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.BlockPos)1 EnumFacing (net.minecraft.util.EnumFacing)1 World (net.minecraft.world.World)1