Search in sources :

Example 91 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.

the class GoggleAuraWorldRenderer method onWorldRender.

@SubscribeEvent
public void onWorldRender(final RenderWorldLastEvent event) {
    if (cartInfos.isEmpty())
        return;
    final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    if (ItemGoggles.isPlayerWearing(player)) {
        ItemStack goggles = ItemGoggles.getGoggles(player);
        ItemGoggles.GoggleAura aura = ItemGoggles.getCurrentAura(goggles);
        if (aura == ItemGoggles.GoggleAura.SHUNTING) {
            OpenGL.glPushMatrix();
            final double px = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
            final double py = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
            final double pz = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
            GlStateManager.translate(-px, -py, -pz);
            GL11.glNormal3f(0.0F, 0.0F, 1.0F);
            OpenGL.glDisable(GL11.GL_LIGHTING);
            OpenGL.glEnable(GL11.GL_BLEND);
            OpenGL.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            OpenGL.glDisable(GL11.GL_TEXTURE_2D);
            OpenGL.glEnable(GL11.GL_LINE_SMOOTH);
            OpenGL.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
            OpenGL.glLineWidth(4F);
            OpenGL.glBegin(GL11.GL_LINES);
            World world = Minecraft.getMinecraft().theWorld;
            for (CartInfo cartInfo : cartInfos) {
                EntityMinecart cart = CartTools.getCartFromUUID(world, cartInfo.id);
                if (cart == null)
                    continue;
                setColor(cartInfo.train.hashCode());
                OpenGL.glVertex(cart.getPositionVector());
                Vec3d top = cart.getPositionVector().addVector(0.0, 2.0, 0.0);
                OpenGL.glVertex(top);
                renderLink(world, top, cartInfo.linkA);
                renderLink(world, top, cartInfo.linkB);
            }
            OpenGL.glEnd();
            OpenGL.glLineWidth(2F);
            OpenGL.glEnable(GL11.GL_TEXTURE_2D);
            OpenGL.glPopMatrix();
        }
    }
}
Also used : ItemGoggles(mods.railcraft.common.items.ItemGoggles) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 92 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.

the class CrowbarHandler method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(MinecartInteractEvent event) {
    EntityPlayer thePlayer = event.getPlayer();
    Entity entity = event.getEntity();
    EnumHand hand = event.getHand();
    if (event.getItem() != null && event.getItem().getItem() instanceof IToolCrowbar)
        event.setCanceled(true);
    ItemStack stack = event.getItem();
    if (!InvTools.isEmpty(stack) && stack.getItem() instanceof IToolCrowbar) {
        thePlayer.swingArm(event.getHand());
        event.setCanceled(true);
    } else
        return;
    if (Game.isClient(thePlayer.worldObj))
        return;
    boolean used = false;
    IToolCrowbar crowbar = (IToolCrowbar) stack.getItem();
    if (entity instanceof EntityMinecart) {
        EntityMinecart cart = (EntityMinecart) entity;
        if (RailcraftModuleManager.isModuleEnabled(ModuleTrain.class) && crowbar.canLink(thePlayer, hand, stack, cart)) {
            boolean linkable = cart instanceof ILinkableCart;
            if (!linkable || ((ILinkableCart) cart).isLinkable()) {
                EntityMinecart last = linkMap.remove(thePlayer);
                if (last != null && last.isEntityAlive()) {
                    LinkageManager lm = LinkageManager.instance();
                    if (lm.areLinked(cart, last, false)) {
                        lm.breakLink(cart, last);
                        used = true;
                        ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.broken");
                        LinkageManager.printDebug("Reason For Broken Link: User removed link.");
                    } else {
                        used = lm.createLink(last, (EntityMinecart) entity);
                        if (used)
                            ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.created");
                    }
                    if (!used)
                        ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.failed");
                } else {
                    linkMap.put(thePlayer, (EntityMinecart) entity);
                    ChatPlugin.sendLocalizedChatFromServer(thePlayer, "gui.railcraft.link.started");
                }
            }
            if (used)
                crowbar.onLink(thePlayer, hand, stack, cart);
        } else if (crowbar.canBoost(thePlayer, hand, stack, cart)) {
            thePlayer.addExhaustion(1F);
            //noinspection StatementWithEmptyBody
            if (thePlayer.getRidingEntity() != null) {
            // NOOP
            } else //noinspection StatementWithEmptyBody
            if (cart instanceof EntityTunnelBore) {
            // NOOP
            } else if (cart instanceof IDirectionalCart)
                ((IDirectionalCart) cart).reverse();
            else {
                int lvl = RailcraftEnchantments.SMACK.getLevel(stack);
                if (lvl == 0) {
                    CartTools.smackCart(cart, thePlayer, SMACK_VELOCITY);
                }
                float smackVelocity = SMACK_VELOCITY * (float) Math.pow(1.7, lvl);
                Train train = Train.getTrain(cart);
                smackVelocity /= (float) Math.pow(train.size(), 1D / (1 + lvl));
                for (EntityMinecart each : train) {
                    CartTools.smackCart(cart, each, thePlayer, smackVelocity);
                }
            }
            crowbar.onBoost(thePlayer, hand, stack, cart);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ILinkableCart(mods.railcraft.api.carts.ILinkableCart) IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar) ModuleTrain(mods.railcraft.common.modules.ModuleTrain) EntityMinecart(net.minecraft.entity.item.EntityMinecart) EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ModuleTrain(mods.railcraft.common.modules.ModuleTrain) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 93 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer 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 94 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.

the class CartTools method getCartOwnerEntity.

public static EntityPlayer getCartOwnerEntity(EntityMinecart cart) {
    GameProfile owner = CartToolsAPI.getCartOwner(cart);
    EntityPlayer player = null;
    if (!RailcraftConstantsAPI.UNKNOWN_PLAYER.equals(owner.getName()))
        player = PlayerPlugin.getPlayer(cart.worldObj, owner);
    if (player == null)
        player = RailcraftFakePlayer.get((WorldServer) cart.worldObj, cart.posX, cart.posY, cart.posZ);
    return player;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 95 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.

the class PlayerPlugin method getUsername.

public static String getUsername(@Nonnull World world, @Nonnull GameProfile gameProfile) {
    UUID playerId = gameProfile.getId();
    if (playerId != null) {
        EntityPlayer player = world.getPlayerEntityByUUID(playerId);
        if (player != null)
            return player.getDisplayNameString();
    }
    String username = gameProfile.getName();
    if (username != null && !username.equals(""))
        return username;
    return UNKNOWN_PLAYER_NAME;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) UUID(java.util.UUID)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)625 ItemStack (net.minecraft.item.ItemStack)169 EntityLivingBase (net.minecraft.entity.EntityLivingBase)104 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)81 Entity (net.minecraft.entity.Entity)77 World (net.minecraft.world.World)73 BlockPos (net.minecraft.util.math.BlockPos)61 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)49 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)44 TileEntity (net.minecraft.tileentity.TileEntity)43 PotionEffect (net.minecraft.potion.PotionEffect)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)38 EntityItem (net.minecraft.entity.item.EntityItem)37 Block (net.minecraft.block.Block)36 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)35 ArrayList (java.util.ArrayList)33 IBlockState (net.minecraft.block.state.IBlockState)33 List (java.util.List)28 TextComponentString (net.minecraft.util.text.TextComponentString)27 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)23