Search in sources :

Example 1 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project MineFactoryReloaded by powercrystals.

the class BlockRailPassengerPickup method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (world.isRemote || !(entity instanceof EntityMinecartEmpty)) {
        return;
    }
    EntityMinecart minecart = (EntityMinecart) entity;
    if (minecart.riddenByEntity != null) {
        return;
    }
    AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(x - MFRConfig.passengerRailSearchMaxHorizontal.getInt(), y - MFRConfig.passengerRailSearchMaxVertical.getInt(), z - MFRConfig.passengerRailSearchMaxHorizontal.getInt(), x + MFRConfig.passengerRailSearchMaxHorizontal.getInt() + 1, y + MFRConfig.passengerRailSearchMaxVertical.getInt() + 1, z + MFRConfig.passengerRailSearchMaxHorizontal.getInt() + 1);
    @SuppressWarnings("rawtypes") List entities = world.getEntitiesWithinAABB(EntityPlayer.class, bb);
    for (Object o : entities) {
        if (!(o instanceof EntityPlayer)) {
            continue;
        }
        ((EntityPlayer) o).mountEntity(minecart);
        return;
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityMinecartEmpty(net.minecraft.entity.item.EntityMinecartEmpty) List(java.util.List) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 2 with EntityMinecart

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

the class SignalBlock method determineMyAspect.

private SignalAspect determineMyAspect(WorldCoordinate otherCoord) {
    WorldCoordinate myTrack = getTrackLocation();
    if (myTrack == null)
        return SignalAspect.RED;
    WorldCoordinate otherTrack = getOtherTrackLocation(otherCoord);
    if (otherTrack == null)
        return SignalAspect.YELLOW;
    TrackScanner.ScanResult scan = getOrCreateTrackScan(otherTrack);
    int y1 = scan.minY;
    int y2 = scan.maxY + 1;
    int x1 = Math.min(myTrack.x, otherTrack.x);
    int z1 = Math.min(myTrack.z, otherTrack.z);
    int x2 = Math.max(myTrack.x, otherTrack.x) + 1;
    int z2 = Math.max(myTrack.z, otherTrack.z) + 1;
    boolean zAxis = Math.abs(myTrack.x - otherTrack.x) < Math.abs(myTrack.z - otherTrack.z);
    int xOffset = otherTrack.x > myTrack.x ? -3 : 3;
    int zOffset = otherTrack.z > myTrack.z ? -3 : 3;
    List<EntityMinecart> carts = CartTools.getMinecartsIn(tile.getWorldObj(), x1, y1, z1, x2, y2, z2);
    //        System.out.printf("%d, %d, %d, %d, %d, %d\n", i1, j1, k1, i2, j2, k2);
    //        System.out.println("carts = " + carts.size());
    SignalAspect newAspect = SignalAspect.GREEN;
    for (EntityMinecart cart : carts) {
        int cartX = MathHelper.floor_double(cart.posX);
        int cartZ = MathHelper.floor_double(cart.posZ);
        if (Math.abs(cart.motionX) < 0.08 && Math.abs(cart.motionZ) < 0.08)
            return SignalAspect.RED;
        else if (zAxis)
            if (cartZ > myTrack.z + zOffset && cart.motionZ < 0)
                return SignalAspect.RED;
            else if (cartZ < myTrack.z + zOffset && cart.motionZ > 0)
                return SignalAspect.RED;
            else
                newAspect = SignalAspect.YELLOW;
        else if (cartX > myTrack.x + xOffset && cart.motionX < 0)
            return SignalAspect.RED;
        else if (cartX < myTrack.x + xOffset && cart.motionX > 0)
            return SignalAspect.RED;
        else
            newAspect = SignalAspect.YELLOW;
    }
    return newAspect;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) TrackScanner(mods.railcraft.api.tracks.TrackScanner) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 3 with EntityMinecart

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

the class CartTools method getMinecartsIn.

public static List<EntityMinecart> getMinecartsIn(World world, int i1, int j1, int k1, int i2, int j2, int k2) {
    List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i1, j1, k1, i2, j2, k2));
    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 4 with EntityMinecart

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

the class TileManipulatorCart method update.

@Override
public final void update() {
    super.update();
    if (Game.isClient(getWorld()))
        return;
    upkeep();
    if (pause > 0)
        pause--;
    boolean wasProcessing = isProcessing();
    setProcessing(false);
    // Find cart to play with
    EntityMinecart cart = getCart();
    setCurrentCart(cart);
    // Wait for reset timer (used by loaders that trickle fill forever)
    if (resetTimer > 0)
        resetTimer--;
    if (resetTimer > 0) {
        waitForReset(cart);
        return;
    }
    // We are alone
    if (cart == null) {
        onNoCart();
        return;
    }
    // We only like some carts
    if (!canHandleCart(cart)) {
        sendCart(cart);
        return;
    }
    // Time out
    if (isPaused())
        return;
    // Play time!
    processCart(cart);
    // We did something!
    if (isProcessing())
        setPowered(false);
    else
        // Are we done?
        trySendCart(cart);
    // Tell our twin
    if (isProcessing() != wasProcessing)
        sendUpdateToClient();
}
Also used : EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 5 with EntityMinecart

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

the class TrackKitDetector method getComparatorInputOverride.

@Override
public int getComparatorInputOverride() {
    if (isEmittingPower()) {
        World world = theWorldAsserted();
        List<EntityMinecart> carts = EntitySearcher.findMinecarts().inFloorBox(getPos(), 0.2F).at(world);
        if (!carts.isEmpty() && carts.get(0).getComparatorLevel() > -1)
            return carts.get(0).getComparatorLevel();
        List<EntityMinecartCommandBlock> commandCarts = EntitySearcher.find(EntityMinecartCommandBlock.class).inFloorBox(getPos(), 0.2F).with(EntitySelectors.HAS_INVENTORY).at(world);
        if (!commandCarts.isEmpty()) {
            return commandCarts.get(0).getCommandBlockLogic().getSuccessCount();
        }
        List<EntityMinecart> chestCarts = EntitySearcher.findMinecarts().inFloorBox(getPos(), 0.2F).andWith(EntitySelectors.HAS_INVENTORY).at(world);
        if (!chestCarts.isEmpty()) {
            return Container.calcRedstoneFromInventory((IInventory) chestCarts.get(0));
        }
    }
    return 0;
}
Also used : EntityMinecartCommandBlock(net.minecraft.entity.item.EntityMinecartCommandBlock) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

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