Search in sources :

Example 11 with EntityMinecart

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

the class DetectorLocomotive method testCarts.

@Override
public int testCarts(List<EntityMinecart> carts) {
    for (EntityMinecart cart : carts) {
        if (cart instanceof EntityLocomotive) {
            EntityLocomotive loco = (EntityLocomotive) cart;
            ItemStack primary = getFilters().getStackInSlot(0);
            if (primary != null && EnumColor.fromItemStack(primary) != EnumColor.fromDye(loco.getPrimaryColor())) {
                continue;
            }
            ItemStack secondary = getFilters().getStackInSlot(1);
            if (secondary != null && EnumColor.fromItemStack(secondary) != EnumColor.fromDye(loco.getSecondaryColor())) {
                continue;
            }
            return FULL_POWER;
        }
    }
    return NO_POWER;
}
Also used : EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive) ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 12 with EntityMinecart

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

the class DetectorTank method testCarts.

@Override
public int testCarts(List<EntityMinecart> carts) {
    for (EntityMinecart cart : carts) {
        IFluidHandler fluidHandler = FluidTools.getFluidHandler(null, cart);
        if (fluidHandler != null) {
            AdvancedFluidHandler tank = new AdvancedFluidHandler(fluidHandler);
            boolean liquidMatches = false;
            Fluid filterFluid = getFilterFluid();
            FluidStack tankLiquid = tank.drain(1, false);
            if (filterFluid == null)
                liquidMatches = true;
            else if (Fluids.areEqual(filterFluid, tankLiquid))
                liquidMatches = true;
            else if (tank.canPutFluid(new FluidStack(filterFluid, 1)))
                liquidMatches = true;
            boolean quantityMatches = false;
            ButtonState state = buttonController.getButtonState();
            switch(state) {
                case VOID:
                    quantityMatches = true;
                    break;
                case EMPTY:
                    if (filterFluid != null && tank.isTankEmpty(filterFluid))
                        quantityMatches = true;
                    else if (filterFluid == null && tank.areTanksEmpty())
                        quantityMatches = true;
                    break;
                case NOT_EMPTY:
                    if (filterFluid != null && tank.getFluidQty(filterFluid) > 0)
                        quantityMatches = true;
                    else if (filterFluid == null && tank.isFluidInTank())
                        quantityMatches = true;
                    break;
                case FULL:
                    if (filterFluid != null && tank.isTankFull(filterFluid))
                        quantityMatches = true;
                    else if (filterFluid == null && tank.areTanksFull())
                        quantityMatches = true;
                    break;
                default:
                    float level = filterFluid != null ? tank.getFluidLevel(filterFluid) : tank.getFluidLevel();
                    switch(state) {
                        case ANALOG:
                            return (int) (FULL_POWER * level);
                        case QUARTER:
                            quantityMatches = level >= 0.25f;
                            break;
                        case HALF:
                            quantityMatches = level >= 0.5f;
                            break;
                        case MOST:
                            quantityMatches = level >= 0.75f;
                            break;
                        case LESS_THAN_QUARTER:
                            quantityMatches = level < 0.25f;
                            break;
                        case LESS_THAN_HALF:
                            quantityMatches = level < 0.5f;
                            break;
                        case LESS_THAN_MOST:
                            quantityMatches = level < 0.75f;
                            break;
                        case LESS_THAN_FULL:
                            quantityMatches = level < 1f;
                            break;
                    }
            }
            return liquidMatches && quantityMatches ? FULL_POWER : NO_POWER;
        }
    }
    return NO_POWER;
}
Also used : AdvancedFluidHandler(mods.railcraft.common.fluids.AdvancedFluidHandler) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) EntityMinecart(net.minecraft.entity.item.EntityMinecart) IMultiButtonState(mods.railcraft.common.gui.buttons.IMultiButtonState) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 13 with EntityMinecart

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

the class CommandDebug method executeSubCommand.

@Override
public void executeSubCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length != 0)
        CommandHelpers.throwWrongUsage(sender, this);
    RayTraceResult rayTraceResult = MiscTools.rayTracePlayerLook((EntityPlayer) sender);
    List<String> debug = Collections.emptyList();
    switch(rayTraceResult.typeOfHit) {
        case ENTITY:
            Entity entity = rayTraceResult.entityHit;
            if (entity instanceof EntityMinecart) {
                debug = CartTools.getDebugOutput((EntityMinecart) entity);
            } else {
                CommandHelpers.throwWrongUsage(sender, this);
            }
            break;
        case BLOCK:
            World world = CommandHelpers.getWorld(sender);
            TileEntity tile = WorldPlugin.getBlockTile(world, rayTraceResult.getBlockPos());
            if (tile instanceof RailcraftTileEntity) {
                debug = ((RailcraftTileEntity) tile).getDebugOutput();
            } else {
                CommandHelpers.throwWrongUsage(sender, this);
            }
            break;
    }
    for (String s : debug) {
        printLine(sender, s);
    }
}
Also used : RailcraftTileEntity(mods.railcraft.common.blocks.RailcraftTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) RailcraftTileEntity(mods.railcraft.common.blocks.RailcraftTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) RailcraftTileEntity(mods.railcraft.common.blocks.RailcraftTileEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 14 with EntityMinecart

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

the class LinkageManager method linkIterator.

public Iterable<EntityMinecart> linkIterator(final EntityMinecart start, final LinkType type) {
    return () -> new Iterator<EntityMinecart>() {

        private final LinkageManager lm = LinkageManager.instance();

        private EntityMinecart last;

        private EntityMinecart current = start;

        @Override
        public boolean hasNext() {
            if (last == null) {
                EntityMinecart next = lm.getLinkedCart(current, type);
                return next != null;
            }
            EntityMinecart next = lm.getLinkedCartA(current);
            if (next != null && next != last)
                return true;
            next = lm.getLinkedCartB(current);
            return next != null && next != last;
        }

        @Override
        public EntityMinecart next() {
            if (last == null) {
                EntityMinecart next = lm.getLinkedCart(current, type);
                if (next == null)
                    throw new NoSuchElementException();
                last = current;
                current = next;
                return current;
            }
            EntityMinecart next = lm.getLinkedCartA(current);
            if (next != null && next != last) {
                last = current;
                current = next;
                return current;
            }
            next = lm.getLinkedCartB(current);
            if (next != null && next != last) {
                last = current;
                current = next;
                return current;
            }
            throw new NoSuchElementException();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Removal not supported.");
        }
    };
}
Also used : Iterator(java.util.Iterator) EntityMinecart(net.minecraft.entity.item.EntityMinecart) ILinkageManager(mods.railcraft.api.carts.ILinkageManager) NoSuchElementException(java.util.NoSuchElementException)

Example 15 with EntityMinecart

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

the class LinkageHandler method adjustLinkedCart.

private boolean adjustLinkedCart(EntityMinecart cart, LinkageManager.LinkType linkType) {
    boolean linked = false;
    LinkageManager lm = LinkageManager.instance();
    EntityMinecart link = lm.getLinkedCart(cart, linkType);
    if (link != null) {
        // sanity check to ensure links are consistent
        if (!lm.areLinked(cart, link)) {
            lm.repairLink(cart, link);
        }
        if (!isLaunched(link) && !isOnElevator(link)) {
            linked = true;
            adjustVelocity(cart, link, linkType);
        //                adjustCartFromHistory(cart, link);
        }
    }
    return linked;
}
Also used : EntityMinecart(net.minecraft.entity.item.EntityMinecart) ILinkageManager(mods.railcraft.api.carts.ILinkageManager)

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