Search in sources :

Example 1 with EntityLocomotive

use of mods.railcraft.common.carts.EntityLocomotive in project Railcraft by Railcraft.

the class LocomotiveRenderer method render.

@Override
public void render(RenderCart renderer, EntityMinecart cart, float light, float time) {
    EntityLocomotive loco = (EntityLocomotive) cart;
    boolean ghost = SeasonPlugin.isGhostTrain(cart);
    EnumColor pColor = ghost ? EnumColor.SILVER : EnumColor.fromDye(loco.getPrimaryDyeColor());
    EnumColor sColor = ghost ? EnumColor.SILVER : EnumColor.fromDye(loco.getSecondaryDyeColor());
    int primaryColor = pColor.getHexColor();
    int secondaryColor = sColor.getHexColor();
    String emblem = loco.getEmblem();
    ResourceLocation emblemTexture = null;
    if (!StringUtils.isNullOrEmpty(emblem) && EmblemToolsClient.packageManager != null)
        emblemTexture = EmblemToolsClient.packageManager.getEmblemTextureLocation(emblem);
    LocomotiveRenderType renderType = loco.getRenderType();
    LocomotiveModelRenderer locoRenderer = renderType.getRenderer(loco.getModel());
    locoRenderer.renderLocomotive(renderer, loco, primaryColor, secondaryColor, emblemTexture, light, time);
}
Also used : EnumColor(mods.railcraft.common.plugins.color.EnumColor) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive)

Example 2 with EntityLocomotive

use of mods.railcraft.common.carts.EntityLocomotive 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);
            boolean matches = EnumColor.fromItemStack(primary).map(c -> c == loco.getPrimaryColor()).orElse(false);
            ItemStack secondary = getFilters().getStackInSlot(1);
            matches &= EnumColor.fromItemStack(secondary).map(c -> c == loco.getSecondaryColor()).orElse(false);
            if (matches)
                return FULL_POWER;
        }
    }
    return NO_POWER;
}
Also used : EnumGui(mods.railcraft.common.gui.EnumGui) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) EnumDetector(mods.railcraft.common.blocks.detector.EnumDetector) NO_POWER(mods.railcraft.common.plugins.forge.PowerPlugin.NO_POWER) EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumColor(mods.railcraft.common.plugins.color.EnumColor) EntityMinecart(net.minecraft.entity.item.EntityMinecart) DetectorFilter(mods.railcraft.common.blocks.detector.DetectorFilter) FULL_POWER(mods.railcraft.common.plugins.forge.PowerPlugin.FULL_POWER) EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive) ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 3 with EntityLocomotive

use of mods.railcraft.common.carts.EntityLocomotive in project Railcraft by Railcraft.

the class LocomotiveRenderer method render.

@Override
public boolean render(ICartRenderer renderer, EntityMinecart cart, float light, float time) {
    EntityLocomotive loco = (EntityLocomotive) cart;
    EnumColor pColor = SeasonPlugin.isGhostTrain(cart) ? EnumColor.SILVER : EnumColor.fromDye(loco.getPrimaryColor());
    EnumColor sColor = SeasonPlugin.isGhostTrain(cart) ? EnumColor.SILVER : EnumColor.fromDye(loco.getSecondaryColor());
    int primaryColor = pColor.getHexColor();
    int secondaryColor = sColor.getHexColor();
    String emblem = loco.getEmblem();
    ResourceLocation emblemTexture = null;
    if (!StringUtils.isNullOrEmpty(emblem) && EmblemToolsClient.packageManager != null)
        emblemTexture = EmblemToolsClient.packageManager.getEmblemTextureLocation(emblem);
    LocomotiveRenderType renderType = loco.getRenderType();
    mods.railcraft.api.carts.locomotive.LocomotiveModelRenderer locoRenderer = renderType.getRenderer(loco.getModel());
    locoRenderer.renderLocomotive(renderer, loco, primaryColor, secondaryColor, emblemTexture, light, time);
    return false;
}
Also used : LocomotiveRenderType(mods.railcraft.api.carts.locomotive.LocomotiveRenderType) EnumColor(mods.railcraft.common.plugins.color.EnumColor) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive)

Example 4 with EntityLocomotive

use of mods.railcraft.common.carts.EntityLocomotive in project Railcraft by Railcraft.

the class TrackKitBooster method onMinecartPassHighSpeed.

private void onMinecartPassHighSpeed(EntityMinecart cart) {
    if (isPowered()) {
        double speed = Math.sqrt(cart.motionX * cart.motionX + cart.motionZ * cart.motionZ);
        EnumRailDirection dir = getRailDirectionRaw();
        if (speed > BOOST_THRESHOLD) {
            cart.motionX += (cart.motionX / speed) * BOOST_FACTOR_HS;
            cart.motionZ += (cart.motionZ / speed) * BOOST_FACTOR_HS;
        } else {
            CartTools.startBoost(cart, getPos(), dir, START_BOOST);
        }
    } else {
        boolean highSpeed = HighSpeedTools.isTravellingHighSpeed(cart);
        if (highSpeed) {
            if (cart instanceof EntityLocomotive) {
                ((EntityLocomotive) cart).forceIdle(20);
            }
            cart.motionX *= SLOW_FACTOR_HS;
            cart.motionY = 0.0D;
            cart.motionZ *= SLOW_FACTOR_HS;
        } else {
            if (Math.abs(cart.motionX) > 0) {
                cart.motionX = Math.copySign(0.38f, cart.motionX);
            }
            if (Math.abs(cart.motionZ) > 0) {
                cart.motionZ = Math.copySign(0.38f, cart.motionZ);
            }
        }
    }
}
Also used : EnumRailDirection(net.minecraft.block.BlockRailBase.EnumRailDirection) EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive)

Example 5 with EntityLocomotive

use of mods.railcraft.common.carts.EntityLocomotive in project Railcraft by Railcraft.

the class PacketKeyPress method readData.

@Override
public void readData(RailcraftInputStream data) throws IOException {
    int type = data.readByte();
    binding = VALUES[type];
    if (!(player.getRidingEntity() instanceof EntityMinecart))
        return;
    EntityMinecart cart = (EntityMinecart) player.getRidingEntity();
    GameProfile gameProfile = player.getGameProfile();
    switch(binding) {
        case LOCOMOTIVE_REVERSE:
            EntityLocomotive.applyAction(gameProfile, cart, false, loco -> loco.setReverse(!loco.isReverse()));
            break;
        case LOCOMOTIVE_INCREASE_SPEED:
            EntityLocomotive.applyAction(gameProfile, cart, false, EntityLocomotive::increaseSpeed);
            break;
        case LOCOMOTIVE_DECREASE_SPEED:
            EntityLocomotive.applyAction(gameProfile, cart, false, EntityLocomotive::decreaseSpeed);
            break;
        case LOCOMOTIVE_MODE_CHANGE:
            EntityLocomotive.applyAction(gameProfile, cart, false, loco -> {
                EntityLocomotive.LocoMode mode = loco.getMode();
                if (mode == EntityLocomotive.LocoMode.RUNNING)
                    loco.setMode(EntityLocomotive.LocoMode.IDLE);
                else
                    loco.setMode(EntityLocomotive.LocoMode.RUNNING);
            });
            break;
        case LOCOMOTIVE_WHISTLE:
            EntityLocomotive.applyAction(gameProfile, cart, true, EntityLocomotive::whistle);
            break;
        case BED_CART_SLEEP:
            Entity ridden = player.getRidingEntity();
            if (ridden instanceof EntityCartBed) {
                ((EntityCartBed) ridden).attemptSleep();
            }
            break;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityCartBed(mods.railcraft.common.carts.EntityCartBed) GameProfile(com.mojang.authlib.GameProfile) EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Aggregations

EntityLocomotive (mods.railcraft.common.carts.EntityLocomotive)5 EnumColor (mods.railcraft.common.plugins.color.EnumColor)3 EntityMinecart (net.minecraft.entity.item.EntityMinecart)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 GameProfile (com.mojang.authlib.GameProfile)1 List (java.util.List)1 LocomotiveRenderType (mods.railcraft.api.carts.locomotive.LocomotiveRenderType)1 DetectorFilter (mods.railcraft.common.blocks.detector.DetectorFilter)1 EnumDetector (mods.railcraft.common.blocks.detector.EnumDetector)1 EntityCartBed (mods.railcraft.common.carts.EntityCartBed)1 EnumGui (mods.railcraft.common.gui.EnumGui)1 FULL_POWER (mods.railcraft.common.plugins.forge.PowerPlugin.FULL_POWER)1 NO_POWER (mods.railcraft.common.plugins.forge.PowerPlugin.NO_POWER)1 EnumRailDirection (net.minecraft.block.BlockRailBase.EnumRailDirection)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1