use of net.minecraft.item.ItemSword in project CumServerPro by MCUmbrella.
the class CraftEventFactory method callBlockBreakEvent.
// CumServer start
public static BlockBreakEvent callBlockBreakEvent(net.minecraft.world.World world, BlockPos pos, IBlockState iBlockState, net.minecraft.entity.player.EntityPlayerMP player) {
org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
org.bukkit.event.block.BlockBreakEvent blockBreakEvent = new org.bukkit.event.block.BlockBreakEvent(bukkitBlock, ((EntityPlayerMP) player).getBukkitEntity());
EntityPlayerMP playermp = (EntityPlayerMP) player;
net.minecraft.block.Block block = iBlockState.getBlock();
if (!(playermp instanceof FakePlayer)) {
boolean isSwordNoBreak = playermp.interactionManager.getGameType().isCreative() && !playermp.getHeldItemMainhand().isEmpty() && playermp.getHeldItemMainhand().getItem() instanceof ItemSword;
if (!isSwordNoBreak) {
int exp = 0;
if (!(// Handle empty block or player unable to break block scenario
block == null || !player.canHarvestBlock(block.getDefaultState()) || // If the block is being silk harvested, the exp dropped is 0
block.canSilkHarvest(world, pos, block.getBlockState().getBaseState(), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) {
int meta = block.getMetaFromState(block.getBlockState().getBaseState());
int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
exp = block.getExpDrop(iBlockState, world, pos, bonusLevel);
}
blockBreakEvent.setExpToDrop(exp);
} else
blockBreakEvent.setCancelled(true);
}
world.getServer().getPluginManager().callEvent(blockBreakEvent);
return blockBreakEvent;
}
use of net.minecraft.item.ItemSword in project CumServerPro by MCUmbrella.
the class EntityPlayer method attackTargetEntityWithCurrentItem.
public void attackTargetEntityWithCurrentItem(Entity targetEntity) {
if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget(this, targetEntity))
return;
if (targetEntity.canBeAttackedWithItem()) {
if (!targetEntity.hitByEntity(this)) {
float f = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
float f1;
if (targetEntity instanceof EntityLivingBase) {
f1 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) targetEntity).getCreatureAttribute());
} else {
f1 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), EnumCreatureAttribute.UNDEFINED);
}
float f2 = this.getCooledAttackStrength(0.5F);
f = f * (0.2F + f2 * f2 * 0.8F);
f1 = f1 * f2;
this.resetCooldown();
if (f > 0.0F || f1 > 0.0F) {
boolean flag = f2 > 0.9F;
boolean flag1 = false;
int i = 0;
i = i + EnchantmentHelper.getKnockbackModifier(this);
if (this.isSprinting() && flag) {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0F, 1.0F);
++i;
flag1 = true;
}
boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(MobEffects.BLINDNESS) && !this.isRiding() && targetEntity instanceof EntityLivingBase;
flag2 = flag2 && !this.isSprinting();
net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit(this, targetEntity, flag2, flag2 ? 1.5F : 1.0F);
flag2 = hitResult != null;
if (flag2) {
f *= hitResult.getDamageModifier();
}
f = f + f1;
boolean flag3 = false;
double d0 = (double) (this.distanceWalkedModified - this.prevDistanceWalkedModified);
if (flag && !flag2 && !flag1 && this.onGround && d0 < (double) this.getAIMoveSpeed()) {
ItemStack itemstack = this.getHeldItem(EnumHand.MAIN_HAND);
if (itemstack.getItem() instanceof ItemSword) {
flag3 = true;
}
}
float f4 = 0.0F;
boolean flag4 = false;
int j = EnchantmentHelper.getFireAspectModifier(this);
if (targetEntity instanceof EntityLivingBase) {
f4 = ((EntityLivingBase) targetEntity).getHealth();
if (j > 0 && !targetEntity.isBurning()) {
// flag4 = true;
// targetEntity.setFire(1);
// CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), targetEntity.getBukkitEntity(), 1);
org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
if (!combustEvent.isCancelled()) {
flag4 = true;
targetEntity.setFire(combustEvent.getDuration());
}
// CraftBukkit end
}
}
double d1 = targetEntity.motionX;
double d2 = targetEntity.motionY;
double d3 = targetEntity.motionZ;
boolean flag5 = targetEntity.attackEntityFrom(DamageSource.causePlayerDamage(this), f);
if (flag5) {
if (i > 0) {
if (targetEntity instanceof EntityLivingBase) {
((EntityLivingBase) targetEntity).knockBack(this, (float) i * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
} else {
targetEntity.addVelocity((double) (-MathHelper.sin(this.rotationYaw * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(this.rotationYaw * 0.017453292F) * (float) i * 0.5F));
}
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
this.setSprinting(false);
}
if (flag3) {
float f3 = 1.0F + EnchantmentHelper.getSweepingDamageRatio(this) * f;
for (EntityLivingBase entitylivingbase : this.world.getEntitiesWithinAABB(EntityLivingBase.class, targetEntity.getEntityBoundingBox().grow(1.0D, 0.25D, 1.0D))) {
if (entitylivingbase != this && entitylivingbase != targetEntity && !this.isOnSameTeam(entitylivingbase) && this.getDistanceSq(entitylivingbase) < 9.0D) {
// CraftBukkit start - Only apply knockback if the damage hits
if (entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage(this).sweep(), f3)) {
entitylivingbase.knockBack(this, 0.4F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
}
}
}
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0F, 1.0F);
this.spawnSweepParticles();
}
if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
// CraftBukkit start - Add Velocity Event
boolean cancelled = false;
Player player = (Player) targetEntity.getBukkitEntity();
org.bukkit.util.Vector velocity = new Vector(d1, d2, d3);
PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
cancelled = true;
} else if (!velocity.equals(event.getVelocity())) {
player.setVelocity(event.getVelocity());
}
if (!cancelled) {
((EntityPlayerMP) targetEntity).connection.sendPacket(new SPacketEntityVelocity(targetEntity));
targetEntity.velocityChanged = false;
targetEntity.motionX = d1;
targetEntity.motionY = d2;
targetEntity.motionZ = d3;
}
// CraftBukkit end
}
if (flag2) {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0F, 1.0F);
this.onCriticalHit(targetEntity);
}
if (!flag2 && !flag3) {
if (flag) {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0F, 1.0F);
} else {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0F, 1.0F);
}
}
if (f1 > 0.0F) {
this.onEnchantmentCritical(targetEntity);
}
this.setLastAttackedEntity(targetEntity);
if (targetEntity instanceof EntityLivingBase) {
EnchantmentHelper.applyThornEnchantments((EntityLivingBase) targetEntity, this);
}
EnchantmentHelper.applyArthropodEnchantments(this, targetEntity);
ItemStack itemstack1 = this.getHeldItemMainhand();
Entity entity = targetEntity;
if (targetEntity instanceof MultiPartEntityPart) {
IEntityMultiPart ientitymultipart = ((MultiPartEntityPart) targetEntity).parent;
if (ientitymultipart instanceof EntityLivingBase) {
entity = (EntityLivingBase) ientitymultipart;
}
}
if (!itemstack1.isEmpty() && entity instanceof EntityLivingBase) {
ItemStack beforeHitCopy = itemstack1.copy();
itemstack1.hitEntity((EntityLivingBase) entity, this);
if (itemstack1.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this, beforeHitCopy, EnumHand.MAIN_HAND);
this.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
}
if (targetEntity instanceof EntityLivingBase) {
float f5 = f4 - ((EntityLivingBase) targetEntity).getHealth();
this.addStat(StatList.DAMAGE_DEALT, Math.round(f5 * 10.0F));
if (j > 0) {
// targetEntity.setFire(j * 4);
// CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4);
org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
if (!combustEvent.isCancelled()) {
entity.setFire(combustEvent.getDuration());
}
// CraftBukkit end
}
if (this.world instanceof WorldServer && f5 > 2.0F) {
int k = (int) ((double) f5 * 0.5D);
((WorldServer) this.world).spawnParticle(EnumParticleTypes.DAMAGE_INDICATOR, targetEntity.posX, targetEntity.posY + (double) (targetEntity.height * 0.5F), targetEntity.posZ, k, 0.1D, 0.0D, 0.1D, 0.2D);
}
}
this.addExhaustion(1902490120.01F);
// Spigot - Change to use configurable value
this.addExhaustion(world.spigotConfig.combatExhaustion);
} else {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0F, 1.0F);
if (flag4) {
targetEntity.extinguish();
}
// CraftBukkit start - resync on cancelled event
if (this instanceof EntityPlayerMP) {
((EntityPlayerMP) this).getBukkitEntity().updateInventory();
}
// CraftBukkit end
}
}
}
}
}
use of net.minecraft.item.ItemSword in project CumServerPro by MCUmbrella.
the class EntityLiving method updateEquipmentIfNeeded.
protected void updateEquipmentIfNeeded(EntityItem itemEntity) {
ItemStack itemstack = itemEntity.getItem();
EntityEquipmentSlot entityequipmentslot = getSlotForItemStack(itemstack);
boolean flag = true;
ItemStack itemstack1 = this.getItemStackFromSlot(entityequipmentslot);
if (!itemstack1.isEmpty()) {
if (entityequipmentslot.getSlotType() == EntityEquipmentSlot.Type.HAND) {
if (itemstack.getItem() instanceof ItemSword && !(itemstack1.getItem() instanceof ItemSword)) {
flag = true;
} else if (itemstack.getItem() instanceof ItemSword && itemstack1.getItem() instanceof ItemSword) {
ItemSword itemsword = (ItemSword) itemstack.getItem();
ItemSword itemsword1 = (ItemSword) itemstack1.getItem();
if (itemsword.getAttackDamage() == itemsword1.getAttackDamage()) {
flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
} else {
flag = itemsword.getAttackDamage() > itemsword1.getAttackDamage();
}
} else if (itemstack.getItem() instanceof ItemBow && itemstack1.getItem() instanceof ItemBow) {
flag = itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
} else {
flag = false;
}
} else if (itemstack.getItem() instanceof ItemArmor && !(itemstack1.getItem() instanceof ItemArmor)) {
flag = true;
} else if (itemstack.getItem() instanceof ItemArmor && itemstack1.getItem() instanceof ItemArmor && !EnchantmentHelper.hasBindingCurse(itemstack1)) {
ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
ItemArmor itemarmor1 = (ItemArmor) itemstack1.getItem();
if (itemarmor.damageReduceAmount == itemarmor1.damageReduceAmount) {
flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
} else {
flag = itemarmor.damageReduceAmount > itemarmor1.damageReduceAmount;
}
} else {
flag = false;
}
}
// if (flag && this.canEquipItem(itemstack)) {
boolean canPickup = flag && this.canEquipItem(itemstack);
EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((LivingEntity) getBukkitEntity(), (org.bukkit.entity.Item) itemEntity.getBukkitEntity(), 0);
entityEvent.setCancelled(!canPickup);
this.world.getServer().getPluginManager().callEvent(entityEvent);
canPickup = !entityEvent.isCancelled();
if (canPickup) {
double d0;
switch(entityequipmentslot.getSlotType()) {
case HAND:
d0 = (double) this.inventoryHandsDropChances[entityequipmentslot.getIndex()];
break;
case ARMOR:
d0 = (double) this.inventoryArmorDropChances[entityequipmentslot.getIndex()];
break;
default:
d0 = 0.0D;
}
if (!itemstack1.isEmpty() && (double) (this.rand.nextFloat() - 0.1F) < d0) {
this.forceDrops = true;
this.entityDropItem(itemstack1, 0.0F);
this.forceDrops = false;
}
this.setItemStackToSlot(entityequipmentslot, itemstack);
switch(entityequipmentslot.getSlotType()) {
case HAND:
this.inventoryHandsDropChances[entityequipmentslot.getIndex()] = 2.0F;
break;
case ARMOR:
this.inventoryArmorDropChances[entityequipmentslot.getIndex()] = 2.0F;
}
this.persistenceRequired = true;
this.onItemPickup(itemEntity, itemstack.getCount());
itemEntity.setDead();
}
}
use of net.minecraft.item.ItemSword in project WizClient-1.8.9-Version by WizClient.
the class ItemInWorldManager method tryHarvestBlock.
/**
* Attempts to harvest a block
*/
public boolean tryHarvestBlock(BlockPos pos) {
if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword) {
return false;
} else {
IBlockState iblockstate = this.theWorld.getBlockState(pos);
TileEntity tileentity = this.theWorld.getTileEntity(pos);
if (this.gameType.isAdventure()) {
if (this.gameType == WorldSettings.GameType.SPECTATOR) {
return false;
}
if (!this.thisPlayerMP.isAllowEdit()) {
ItemStack itemstack = this.thisPlayerMP.getCurrentEquippedItem();
if (itemstack == null) {
return false;
}
if (!itemstack.canDestroy(iblockstate.getBlock())) {
return false;
}
}
}
this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
boolean flag1 = this.removeBlock(pos);
if (this.isCreative()) {
this.thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(this.theWorld, pos));
} else {
ItemStack itemstack1 = this.thisPlayerMP.getCurrentEquippedItem();
boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate.getBlock());
if (itemstack1 != null) {
itemstack1.onBlockDestroyed(this.theWorld, iblockstate.getBlock(), pos, this.thisPlayerMP);
if (itemstack1.stackSize == 0) {
this.thisPlayerMP.destroyCurrentEquippedItem();
}
}
if (flag1 && flag) {
iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity);
}
}
return flag1;
}
}
use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.
the class FeatureSwordInfo method addSwordInfoTooltip.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void addSwordInfoTooltip(ItemTooltipEvent event) {
if (!ModConfig.confSwordInfoTooltip)
return;
ItemStack stack = event.getItemStack();
ListIterator<String> tooltip = event.getToolTip().listIterator();
if (stack.getItem() instanceof ItemSword) {
ItemSword sword = (ItemSword) stack.getItem();
boolean shift = false;
if (Keyboard.isCreated()) {
shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
}
while (tooltip.hasNext()) {
tooltip.next();
if (shift) {
tooltip.add(Utils.localize("tooltip.pt.durability") + " " + Colors.WHITE + getDurability(stack));
tooltip.add(Utils.localize("tooltip.pt.enemies_killed") + " " + Colors.WHITE + getEnemiesKilled(stack));
tooltip.add(Utils.localize("tooltip.pt.damage_dealt") + " " + Colors.WHITE + getDamageDealt(stack));
} else {
tooltip.add(Utils.localize("tooltip.pt.hold_shift_for_info"));
}
break;
}
}
}
Aggregations