Search in sources :

Example 1 with IProjectile

use of net.minecraft.entity.IProjectile 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 IProjectile

use of net.minecraft.entity.IProjectile 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)

Example 3 with IProjectile

use of net.minecraft.entity.IProjectile in project BloodMagic by WayofTime.

the class PotionEventHandlers method onEntityUpdate.

@SubscribeEvent
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
    if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.WHIRLWIND)) {
        int d0 = 3;
        AxisAlignedBB axisAlignedBB = new AxisAlignedBB(event.getEntityLiving().posX - 0.5, event.getEntityLiving().posY - 0.5, event.getEntityLiving().posZ - 0.5, event.getEntityLiving().posX + 0.5, event.getEntityLiving().posY + 0.5, event.getEntityLiving().posZ + 0.5).expand(d0, d0, d0);
        List<Entity> entityList = event.getEntityLiving().getEntityWorld().getEntitiesWithinAABB(Entity.class, axisAlignedBB);
        for (Entity projectile : entityList) {
            if (projectile == null)
                continue;
            if (!(projectile instanceof IProjectile))
                continue;
            Entity throwingEntity = null;
            if (projectile instanceof EntityArrow)
                throwingEntity = ((EntityArrow) projectile).shootingEntity;
            else if (projectile instanceof EntityThrowable)
                throwingEntity = ((EntityThrowable) projectile).getThrower();
            if (throwingEntity != null && throwingEntity.equals(event.getEntityLiving()))
                continue;
            double delX = projectile.posX - event.getEntityLiving().posX;
            double delY = projectile.posY - event.getEntityLiving().posY;
            double delZ = projectile.posZ - event.getEntityLiving().posZ;
            double angle = (delX * projectile.motionX + delY * projectile.motionY + delZ * projectile.motionZ) / (Math.sqrt(delX * delX + delY * delY + delZ * delZ) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
            angle = Math.acos(angle);
            if (angle < 3 * (Math.PI / 4))
                // angle is < 135 degrees
                continue;
            if (throwingEntity != null) {
                delX = -projectile.posX + throwingEntity.posX;
                delY = -projectile.posY + (throwingEntity.posY + throwingEntity.getEyeHeight());
                delZ = -projectile.posZ + throwingEntity.posZ;
            }
            double curVel = Math.sqrt(delX * delX + delY * delY + delZ * delZ);
            delX /= curVel;
            delY /= curVel;
            delZ /= curVel;
            double newVel = Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ);
            projectile.motionX = newVel * delX;
            projectile.motionY = newVel * delY;
            projectile.motionZ = newVel * delZ;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) IProjectile(net.minecraft.entity.IProjectile) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IProjectile

use of net.minecraft.entity.IProjectile 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 5 with IProjectile

use of net.minecraft.entity.IProjectile in project SpongeCommon by SpongePowered.

the class EntityTickPhaseState method fireMovementEvents.

private void fireMovementEvents(net.minecraft.entity.Entity entity) {
    // Note: Projectiles are handled with CollideBlockEvent.Impact
    if (entity.isDead || entity instanceof IProjectile || entity instanceof EntityItem) {
        return;
    }
    Entity spongeEntity = (Entity) entity;
    if (entity.lastTickPosX != entity.posX || entity.lastTickPosY != entity.posY || entity.lastTickPosZ != entity.posZ || entity.rotationPitch != entity.prevRotationPitch || entity.rotationYaw != entity.prevRotationYaw) {
        // yes we have a move event.
        final double currentPosX = entity.posX;
        final double currentPosY = entity.posY;
        final double currentPosZ = entity.posZ;
        final Vector3d oldPositionVector = new Vector3d(entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ);
        final Vector3d currentPositionVector = new Vector3d(currentPosX, currentPosY, currentPosZ);
        Vector3d oldRotationVector = new Vector3d(entity.prevRotationPitch, entity.prevRotationYaw, 0);
        Vector3d currentRotationVector = new Vector3d(entity.rotationPitch, entity.rotationYaw, 0);
        final Transform<World> oldTransform = new Transform<>(spongeEntity.getWorld(), oldPositionVector, oldRotationVector, spongeEntity.getScale());
        final Transform<World> newTransform = new Transform<>(spongeEntity.getWorld(), currentPositionVector, currentRotationVector, spongeEntity.getScale());
        final MoveEntityEvent event = SpongeEventFactory.createMoveEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), oldTransform, newTransform, spongeEntity);
        if (SpongeImpl.postEvent(event)) {
            entity.posX = entity.lastTickPosX;
            entity.posY = entity.lastTickPosY;
            entity.posZ = entity.lastTickPosZ;
            entity.rotationPitch = entity.prevRotationPitch;
            entity.rotationYaw = entity.prevRotationYaw;
        } else {
            Vector3d newPosition = event.getToTransform().getPosition();
            if (!newPosition.equals(currentPositionVector)) {
                entity.posX = newPosition.getX();
                entity.posY = newPosition.getY();
                entity.posZ = newPosition.getZ();
            }
            if (!event.getToTransform().getRotation().equals(currentRotationVector)) {
                entity.rotationPitch = (float) currentRotationVector.getX();
                entity.rotationYaw = (float) currentRotationVector.getY();
            }
        // entity.setPositionWithRotation(position.getX(), position.getY(), position.getZ(), rotation.getFloorX(), rotation.getFloorY());
        /*
                    Some thoughts from gabizou: The interesting thing here is that while this is only called
                    in World.updateEntityWithOptionalForce, by default, it supposedly handles updating the rider entity
                    of the entity being handled here. The interesting issue is that since we are setting the transform,
                    the rider entity (and the rest of the rider entities) are being updated as well with the new position
                    and potentially world, which results in a dirty world usage (since the world transfer is handled by
                    us). Now, the thing is, the previous position is not updated either, and likewise, the current position
                    is being set by us as well. So, there's some issue I'm sure that is bound to happen with this
                    logic.
                     */
        // ((Entity) entity).setTransform(event.getToTransform());
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) Vector3d(com.flowpowered.math.vector.Vector3d) World(org.spongepowered.api.world.World) Transform(org.spongepowered.api.entity.Transform) EntityItem(net.minecraft.entity.item.EntityItem) IProjectile(net.minecraft.entity.IProjectile)

Aggregations

IProjectile (net.minecraft.entity.IProjectile)6 BehaviorProjectileDispense (net.minecraft.dispenser.BehaviorProjectileDispense)3 IPosition (net.minecraft.dispenser.IPosition)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 Entity (net.minecraft.entity.Entity)2 IPortalCache (cavern.api.IPortalCache)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 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 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)1 BehaviorDefaultDispenseItem (net.minecraft.dispenser.BehaviorDefaultDispenseItem)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1