use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.
the class AuraKeyHandler method tick.
@SubscribeEvent
public void tick(TickEvent.ClientTickEvent event) {
if (Minecraft.getMinecraft().currentScreen instanceof GuiChat)
return;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
for (Map.Entry<GoggleAura, KeyBinding> keyBinding : keyBindings.entrySet()) {
if (keyBinding.getValue().isPressed()) {
GoggleAura aura = keyBinding.getKey();
if (isAuraEnabled(aura)) {
activeAuras.remove(aura);
ChatPlugin.sendLocalizedChat(player, "gui.railcraft.aura.disable", "§5" + aura + "§7");
} else {
activeAuras.add(aura);
ChatPlugin.sendLocalizedChat(player, "gui.railcraft.aura.enable", "§5" + aura + "§7");
}
}
}
}
use of net.minecraft.entity.player.EntityPlayer in project Skree by Skelril.
the class MarketImplUtil method setBalanceTo.
public static boolean setBalanceTo(Player player, BigDecimal decimal, Cause cause) {
EntityPlayer playerEnt = tf(player);
net.minecraft.item.ItemStack[] mainInv = playerEnt.inventory.mainInventory;
Collection<ItemStack> results = CofferValueMap.inst().satisfy(decimal.toBigInteger());
Iterator<ItemStack> resultIt = results.iterator();
// Loop through replacing empty slots and the old coffers with the new balance
for (int i = 0; i < mainInv.length; ++i) {
Optional<BigInteger> value = CofferValueMap.inst().getValue(Lists.newArrayList(tf(mainInv[i])));
if (value.isPresent()) {
mainInv[i] = null;
}
if (mainInv[i] == null && resultIt.hasNext()) {
mainInv[i] = tf(resultIt.next());
resultIt.remove();
}
}
// Add remaining currency
new ItemDropper(player.getLocation()).dropStacks(results, SpawnTypes.PLUGIN);
return true;
}
use of net.minecraft.entity.player.EntityPlayer in project Skree by Skelril.
the class ICustomBow method onPlayerStoppedUsing.
/**
* Called when the player stops using an Item (stops holding the right mouse button).
*
* @param timeLeft The amount of ticks left before the using would have been complete
*/
default default void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entityLiving;
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = this.findAmmo(entityplayer);
int i = this.getMaxItemUseDuration(stack) - timeLeft;
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, i, itemstack != null || flag);
if (i < 0)
return;
if (itemstack != null || flag) {
if (itemstack == null) {
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
if ((double) f >= 0.1D) {
boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
if (!worldIn.isRemote) {
ItemArrow itemarrow = (ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0) {
entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0) {
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityarrow.setFire(100);
}
stack.damageItem(1, entityplayer);
if (flag1) {
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
worldIn.spawnEntityInWorld(entityarrow);
}
worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (__getItemRand().nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1) {
--itemstack.stackSize;
if (itemstack.stackSize == 0) {
entityplayer.inventory.deleteStack(itemstack);
}
}
entityplayer.addStat(StatList.getObjectUseStats(__getBowItem()));
}
}
}
}
use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.
the class MinecartHooks method onMinecartInteract.
@SubscribeEvent
public void onMinecartInteract(MinecartInteractEvent event) {
EntityMinecart cart = event.getMinecart();
EntityPlayer player = event.getPlayer();
if (!CartToolsAPI.doesCartHaveOwner(cart))
CartToolsAPI.setCartOwner(cart, player);
if (!(cart instanceof EntityTunnelBore) && player.getDistanceSqToEntity(cart) > MAX_INTERACT_DIST_SQ) {
event.setCanceled(true);
return;
}
if (cart.isDead) {
event.setCanceled(true);
return;
}
if (cart.canBeRidden()) {
//TODO: this will interfere with carts that multiple players can ride, re-evaluate
if (cart.isBeingRidden() && player.getRidingEntity() != cart) {
event.setCanceled(true);
return;
}
if (player.getRidingEntity() != null && player.getRidingEntity() != cart) {
event.setCanceled(true);
return;
}
if (player.getRidingEntity() != cart && player.isOnLadder()) {
event.setCanceled(true);
return;
}
}
if (!player.canEntityBeSeen(cart)) {
event.setCanceled(true);
}
}
use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.
the class MinecartHooks method onEntityCollision.
@Override
public void onEntityCollision(EntityMinecart cart, Entity other) {
if (Game.isClient(cart.worldObj) || cart.isPassenger(other) || !other.isEntityAlive() || !cart.isEntityAlive())
return;
ILinkageManager lm = LinkageManager.instance();
EntityMinecart link = lm.getLinkedCartA(cart);
if (link != null && (link == other || link.isPassenger(other)))
return;
link = lm.getLinkedCartB(cart);
if (link != null && (link == other || link.isPassenger(other)))
return;
boolean isLiving = other instanceof EntityLivingBase;
boolean isPlayer = other instanceof EntityPlayer;
//TODO: needs more thought in regards to passenger handling
if (isLiving && !isPlayer && cart.canBeRidden() && !(other instanceof EntityIronGolem) && cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0.001D && !cart.isBeingRidden() && !other.isRiding()) {
int mountPrevention = cart.getEntityData().getInteger("MountPrevention");
if (mountPrevention <= 0)
other.startRiding(cart);
}
if (isLiving && WorldPlugin.isBlockAt(cart.worldObj, cart.getPosition(), RailcraftBlocks.TRACK_ELEVATOR.block()))
return;
// System.out.println(cart.getClass().getSimpleName() + ": " + cart.entityId + " collided with " + other.getClass().getSimpleName() + ": " + other.entityId);
Vec2D cartPos = new Vec2D(cart.posX, cart.posZ);
Vec2D otherPos = new Vec2D(other.posX, other.posZ);
Vec2D unit = Vec2D.subtract(otherPos, cartPos);
unit.normalize();
double distance = cart.getDistanceToEntity(other);
double depth = distance - OPTIMAL_DISTANCE;
double forceX = 0;
double forceZ = 0;
if (depth < 0) {
double spring = isPlayer ? COEF_SPRING_PLAYER : COEF_SPRING;
double penaltyX = spring * depth * unit.getX();
double penaltyZ = spring * depth * unit.getY();
forceX += penaltyX;
forceZ += penaltyZ;
if (!isPlayer) {
double impulseX = unit.getX();
double impulseZ = unit.getY();
impulseX *= -(1.0 + COEF_RESTITUTION);
impulseZ *= -(1.0 + COEF_RESTITUTION);
Vec2D cartVel = new Vec2D(cart.motionX, cart.motionZ);
Vec2D otherVel = new Vec2D(other.motionX, other.motionZ);
double dot = Vec2D.subtract(otherVel, cartVel).dotProduct(unit);
impulseX *= dot;
impulseZ *= dot;
impulseX *= 0.5;
impulseZ *= 0.5;
forceX -= impulseX;
forceZ -= impulseZ;
}
}
if (other instanceof EntityMinecart) {
EntityMinecart otherCart = (EntityMinecart) other;
if (!cart.isPoweredCart() || otherCart.isPoweredCart())
if (!TrackToolsAPI.isCartLockedDown(cart))
cart.addVelocity(forceX, 0, forceZ);
if (!otherCart.isPoweredCart() || cart.isPoweredCart())
if (!TrackToolsAPI.isCartLockedDown(otherCart))
other.addVelocity(-forceX, 0, -forceZ);
} else {
// if(isPlayer) {
// forceX += Math.abs(cart.motionX - other.motionX) / 2;
// forceZ += Math.abs(cart.motionZ - other.motionZ) / 2;
// }
// System.out.printf("forceX=%f, forceZ=%f%n", forceX, forceZ);
Vec2D cartVel = new Vec2D(cart.motionX + forceX, cart.motionZ + forceZ);
Vec2D otherVel = new Vec2D(other.motionX - forceX, other.motionZ - forceZ);
double dot = Vec2D.subtract(otherVel, cartVel).dotProduct(unit);
double dampX = COEF_DAMPING * dot * unit.getX();
double dampZ = COEF_DAMPING * dot * unit.getY();
forceX += dampX;
forceZ += dampZ;
// System.out.printf("dampX=%f, dampZ=%f%n", dampX, dampZ);
if (!isPlayer)
other.addVelocity(-forceX, 0.0D, -forceZ);
if (!TrackToolsAPI.isCartLockedDown(cart))
cart.addVelocity(forceX, 0, forceZ);
}
}
Aggregations