Search in sources :

Example 1 with ICartBattery

use of mods.railcraft.api.charge.ICartBattery in project Railcraft by Railcraft.

the class ItemChargeMeter method onEntityInteract.

@SuppressWarnings("unused")
@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
    EntityPlayer player = event.getEntityPlayer();
    Entity entity = event.getTarget();
    ItemStack stack = event.getItemStack();
    if (!InvTools.isEmpty(stack) && stack.getItem() instanceof ItemChargeMeter)
        player.swingArm(event.getHand());
    if (Game.isClient(player.worldObj))
        return;
    if (!InvTools.isEmpty(stack) && stack.getItem() instanceof ItemChargeMeter)
        try {
            if (entity.hasCapability(CapabilitiesCharge.CART_BATTERY, null)) {
                ICartBattery battery = entity.getCapability(CapabilitiesCharge.CART_BATTERY, null);
                if (battery != null) {
                    sendChat(player, "gui.railcraft.charge.meter.cart", battery.getCharge(), battery.getDraw(), battery.getLosses());
                    event.setCanceled(true);
                }
            }
        } catch (Throwable er) {
            Game.logErrorAPI(Railcraft.MOD_ID, er, ICartBattery.class);
            ChatPlugin.sendLocalizedChatFromServer(player, "chat.railcraft.api.error");
        }
}
Also used : Entity(net.minecraft.entity.Entity) ICartBattery(mods.railcraft.api.charge.ICartBattery) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ICartBattery

use of mods.railcraft.api.charge.ICartBattery in project Railcraft by Railcraft.

the class Train method getMaxSpeed.

public float getMaxSpeed() {
    float speed = 1.2F;
    int numLocomotives = getNumRunningLocomotives();
    for (EntityMinecart c : this) {
        float baseSpeed = c.getMaxCartSpeedOnRail();
        if (numLocomotives > 0 && !(c instanceof CartBaseEnergy) && c.hasCapability(CapabilitiesCharge.CART_BATTERY, null)) {
            ICartBattery battery = c.getCapability(CapabilitiesCharge.CART_BATTERY, null);
            if (battery.getType() != ICartBattery.Type.USER) {
                baseSpeed = Math.min(0.2F, 0.03F + (numLocomotives - 1) * 0.075F);
            }
        }
        speed = Math.min(speed, baseSpeed);
    }
    return speed;
}
Also used : ICartBattery(mods.railcraft.api.charge.ICartBattery) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Aggregations

ICartBattery (mods.railcraft.api.charge.ICartBattery)2 Entity (net.minecraft.entity.Entity)1 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1