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");
}
}
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;
}
Aggregations