Search in sources :

Example 1 with EntityCartBed

use of mods.railcraft.common.carts.EntityCartBed 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

GameProfile (com.mojang.authlib.GameProfile)1 EntityCartBed (mods.railcraft.common.carts.EntityCartBed)1 EntityLocomotive (mods.railcraft.common.carts.EntityLocomotive)1 Entity (net.minecraft.entity.Entity)1 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1