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