Search in sources :

Example 26 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class ItemTunnelBore method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState existingState = WorldPlugin.getBlockState(world, pos);
    if (TrackTools.isRailBlock(existingState)) {
        if (Game.isHost(world) && !CartToolsAPI.isMinecartAt(world, pos, 0)) {
            BlockRailBase.EnumRailDirection trackShape = TrackTools.getTrackDirection(world, pos, existingState);
            if (TrackShapeHelper.isLevelStraight(trackShape)) {
                EnumFacing playerFacing = MiscTools.getHorizontalSideFacingPlayer(player).getOpposite();
                if (trackShape == BlockRailBase.EnumRailDirection.NORTH_SOUTH) {
                    if (playerFacing == EnumFacing.WEST)
                        playerFacing = EnumFacing.NORTH;
                    else if (playerFacing == EnumFacing.EAST)
                        playerFacing = EnumFacing.SOUTH;
                } else if (trackShape == BlockRailBase.EnumRailDirection.EAST_WEST) {
                    if (playerFacing == EnumFacing.SOUTH)
                        playerFacing = EnumFacing.EAST;
                    else if (playerFacing == EnumFacing.NORTH)
                        playerFacing = EnumFacing.WEST;
                }
                //					System.out.println("PlayerYaw = " + playerYaw + " Yaw = " + facing + " Meta = " + meta);
                EntityMinecart bore = new EntityTunnelBore(world, (float) pos.getX() + 0.5F, (float) pos.getY(), (float) pos.getZ() + 0.5F, playerFacing);
                CartToolsAPI.setCartOwner(bore, player);
                world.spawnEntityInWorld(bore);
            }
        }
        stack.stackSize--;
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) EntityMinecart(net.minecraft.entity.item.EntityMinecart) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 27 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class CartTools method getMinecartsOnAllSides.

public static List<EntityMinecart> getMinecartsOnAllSides(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
    List<EntityMinecart> list = new ArrayList<EntityMinecart>();
    List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
    for (int side = 0; side < 6; side++) {
        list.addAll(getMinecartsOnSide(world, i, j, k, sensitivity, ForgeDirection.getOrientation(side)));
    }
    for (EntityMinecart cart : list) {
        if ((subclass && type.isInstance(cart)) || cart.getClass() == type)
            carts.add(cart);
    }
    return carts;
}
Also used : ArrayList(java.util.ArrayList) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 28 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class CartTools method getMinecartsAt.

/**
     * @param world
     * @param i
     * @param j
     * @param k
     * @param sensitivity Controls the size of the search box, ranges from
     *                    (-inf, 0.49].
     * @return
     */
public static List<EntityMinecart> getMinecartsAt(World world, int i, int j, int k, float sensitivity) {
    sensitivity = Math.min(sensitivity, 0.49f);
    List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i + sensitivity, j + sensitivity, k + sensitivity, i + 1 - sensitivity, j + 1 - sensitivity, k + 1 - sensitivity));
    List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
    for (Object o : entities) {
        EntityMinecart cart = (EntityMinecart) o;
        if (!cart.isDead)
            carts.add((EntityMinecart) o);
    }
    return carts;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 29 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project ImmersiveEngineering by BluSunrize.

the class EventHandler method onCapabilitiesAttach.

@SubscribeEvent
public void onCapabilitiesAttach(AttachCapabilitiesEvent.Entity event) {
    if (event.getEntity() instanceof EntityMinecart) {
        EntityMinecart entityMinecart = (EntityMinecart) event.getEntity();
        event.addCapability(new ResourceLocation("immersiveengineering:shader"), new ShaderWrapper_Direct("immersiveengineering:minecart"));
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) EntityMinecart(net.minecraft.entity.item.EntityMinecart) ShaderWrapper_Direct(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper_Direct) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 30 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project ArsMagica2 by Mithion.

the class AMEventHandler method onEntityJump.

@SubscribeEvent
public void onEntityJump(LivingJumpEvent event) {
    if (event.entityLiving.isPotionActive(BuffList.agility.id)) {
        event.entityLiving.motionY *= 1.5f;
    }
    if (event.entityLiving.isPotionActive(BuffList.leap.id)) {
        Entity velocityTarget = event.entityLiving;
        if (event.entityLiving.ridingEntity != null) {
            if (event.entityLiving.ridingEntity instanceof EntityMinecart) {
                event.entityLiving.ridingEntity.setPosition(event.entityLiving.ridingEntity.posX, event.entityLiving.ridingEntity.posY + 1.5, event.entityLiving.ridingEntity.posZ);
            }
            velocityTarget = event.entityLiving.ridingEntity;
        }
        double yVelocity = 0;
        double xVelocity = 0;
        double zVelocity = 0;
        Vec3 vec = event.entityLiving.getLookVec().normalize();
        switch(event.entityLiving.getActivePotionEffect(BuffList.leap).getAmplifier() + 1) {
            case BuffPowerLevel.Low:
                yVelocity = 0.4;
                xVelocity = velocityTarget.motionX * 1.08 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.08 * Math.abs(vec.zCoord);
                break;
            case BuffPowerLevel.Medium:
                yVelocity = 0.7;
                xVelocity = velocityTarget.motionX * 1.25 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.25 * Math.abs(vec.zCoord);
                break;
            case BuffPowerLevel.High:
                yVelocity = 1;
                xVelocity = velocityTarget.motionX * 1.75 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.75 * Math.abs(vec.zCoord);
                break;
            default:
                break;
        }
        float maxHorizontalVelocity = 1.45f;
        if (event.entityLiving.ridingEntity != null && (event.entityLiving.ridingEntity instanceof EntityMinecart || event.entityLiving.ridingEntity instanceof EntityBoat) || event.entityLiving.isPotionActive(BuffList.haste.id)) {
            maxHorizontalVelocity += 25;
            xVelocity *= 2.5;
            zVelocity *= 2.5;
        }
        if (xVelocity > maxHorizontalVelocity) {
            xVelocity = maxHorizontalVelocity;
        } else if (xVelocity < -maxHorizontalVelocity) {
            xVelocity = -maxHorizontalVelocity;
        }
        if (zVelocity > maxHorizontalVelocity) {
            zVelocity = maxHorizontalVelocity;
        } else if (zVelocity < -maxHorizontalVelocity) {
            zVelocity = -maxHorizontalVelocity;
        }
        if (ExtendedProperties.For(event.entityLiving).getIsFlipped()) {
            yVelocity *= -1;
        }
        velocityTarget.addVelocity(xVelocity, yVelocity, zVelocity);
    }
    if (event.entityLiving.isPotionActive(BuffList.entangled.id)) {
        event.entityLiving.motionY = 0;
    }
    if (event.entityLiving instanceof EntityPlayer) {
        ItemStack boots = ((EntityPlayer) event.entityLiving).inventory.armorInventory[0];
        if (boots != null && boots.getItem() == ItemsCommonProxy.enderBoots && event.entityLiving.isSneaking()) {
            ExtendedProperties.For(event.entityLiving).toggleFlipped();
        }
        if (ExtendedProperties.For(event.entityLiving).getFlipRotation() > 0)
            ((EntityPlayer) event.entityLiving).addVelocity(0, -2 * event.entityLiving.motionY, 0);
    }
}
Also used : Vec3(net.minecraft.util.Vec3) EntityBoat(net.minecraft.entity.item.EntityBoat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityMinecart (net.minecraft.entity.item.EntityMinecart)45 ItemStack (net.minecraft.item.ItemStack)11 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 ILinkageManager (mods.railcraft.api.carts.ILinkageManager)6 World (net.minecraft.world.World)6 Nullable (javax.annotation.Nullable)5 Entity (net.minecraft.entity.Entity)5 List (java.util.List)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 ArrayList (java.util.ArrayList)3 IEnergyTransfer (mods.railcraft.api.carts.IEnergyTransfer)2 ILinkableCart (mods.railcraft.api.carts.ILinkableCart)2 ItemGoggles (mods.railcraft.common.items.ItemGoggles)2 EntityItem (net.minecraft.entity.item.EntityItem)2 Item (net.minecraft.item.Item)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 ShaderWrapper_Direct (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper_Direct)1 HashMultiset (com.google.common.collect.HashMultiset)1