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