use of net.minecraft.item.ItemSword in project WizClient-1.8.9-Version by WizClient.
the class EntityLiving method updateEquipmentIfNeeded.
/**
* Tests if this entity should pickup a weapon or an armor. Entity drops current weapon or armor if the new one is
* better.
*/
protected void updateEquipmentIfNeeded(EntityItem itemEntity) {
ItemStack itemstack = itemEntity.getEntityItem();
int i = getArmorPosition(itemstack);
if (i > -1) {
boolean flag = true;
ItemStack itemstack1 = this.getEquipmentInSlot(i);
if (itemstack1 != null) {
if (i == 0) {
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.getDamageVsEntity() != itemsword1.getDamageVsEntity()) {
flag = itemsword.getDamageVsEntity() > itemsword1.getDamageVsEntity();
} else {
flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
}
} 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) {
ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
ItemArmor itemarmor1 = (ItemArmor) itemstack1.getItem();
if (itemarmor.damageReduceAmount != itemarmor1.damageReduceAmount) {
flag = itemarmor.damageReduceAmount > itemarmor1.damageReduceAmount;
} else {
flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
}
} else {
flag = false;
}
}
if (flag && this.func_175448_a(itemstack)) {
if (itemstack1 != null && this.rand.nextFloat() - 0.1F < this.equipmentDropChances[i]) {
this.entityDropItem(itemstack1, 0.0F);
}
if (itemstack.getItem() == Items.diamond && itemEntity.getThrower() != null) {
EntityPlayer entityplayer = this.worldObj.getPlayerEntityByName(itemEntity.getThrower());
if (entityplayer != null) {
entityplayer.triggerAchievement(AchievementList.diamondsToYou);
}
}
this.setCurrentItemOrArmor(i, itemstack);
this.equipmentDropChances[i] = 2.0F;
this.persistenceRequired = true;
this.onItemPickup(itemEntity, 1);
itemEntity.setDead();
}
}
}
use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.
the class ReinforcementHandler method onBreakBlock.
@SubscribeEvent
public void onBreakBlock(BlockEvent.BreakEvent event) {
if (event.getPlayer() == null)
return;
ItemStack stack = event.getPlayer().getHeldItemMainhand();
if (stack.isEmpty())
return;
if (!blockBreakTool(stack.getItem()))
return;
if (!isBlockHardEnough(event.getState(), event.getWorld(), event.getPos()))
return;
if (ReinforcementHelper.isReinforced(stack) && stack.isItemDamaged()) {
int extra = ReinforcementHelper.useReinforcement(stack, stack.getItem() instanceof ItemSword ? 2 : 1);
stack.setItemDamage(ReinforcementHelper.getDurability(stack) + extra);
}
}
use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.
the class ReinforcementRecipe method getReinforcementOutput.
public ItemStack getReinforcementOutput(InventoryCrafting inv) {
ItemStack tool = ItemStack.EMPTY;
boolean foundTool = false;
NonNullList<ItemStack> inputs = NonNullList.<ItemStack>create();
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack slotStack = inv.getStackInSlot(i);
if (slotStack.isEmpty()) {
continue;
}
ItemStack newSlotStack = slotStack.copy();
newSlotStack.setCount(1);
if (!foundTool && newSlotStack.isItemStackDamageable()) {
tool = newSlotStack;
foundTool = true;
continue;
} else {
inputs.add(newSlotStack);
}
}
if (tool.isEmpty()) {
return ItemStack.EMPTY;
}
if (inputs.isEmpty()) {
return ItemStack.EMPTY;
}
if (tool.getItem().hasContainerItem(tool)) {
return ItemStack.EMPTY;
}
if (ModConfig.confBrokenTools && TweakToolBreaking.isBroken(tool, tool.getItem() instanceof ItemSword ? 1 : 0)) {
return ItemStack.EMPTY;
}
if (ReinforcementBlacklist.isBlacklisted(tool.getItem())) {
return ItemStack.EMPTY;
}
int reeCount = 0;
boolean maxed = false;
int currentCount = ReinforcementHelper.getReinforcement(tool);
for (ItemStack mat : inputs) {
if (maxed)
return ItemStack.EMPTY;
if (ReinforcementHelper.isReinforcement(mat)) {
reeCount += ReinforcementHelper.getReinforcementValue(mat);
if ((reeCount + currentCount) > ModConfig.confMaxReinforcement) {
maxed = true;
}
} else {
return ItemStack.EMPTY;
}
}
if (reeCount == 0) {
return ItemStack.EMPTY;
}
ReinforcementHelper.reinforce(tool, reeCount);
return tool;
}
use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.
the class FeatureSwordInfo method onEntityKilled.
@SubscribeEvent
public void onEntityKilled(LivingDeathEvent event) {
if (!ModConfig.confSwordInfoTooltip) {
return;
}
DamageSource source = event.getSource();
Entity entity = source.getTrueSource();
if (entity != null && entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
ItemStack stack = player.getHeldItemMainhand();
if (!stack.isEmpty() && stack.getItem() instanceof ItemSword) {
NBTTagCompound tag = stack.getOrCreateSubCompound(PickleTweaks.MOD_ID);
tag.setInteger("EnemiesKilled", tag.getInteger("EnemiesKilled") + 1);
}
}
}
use of net.minecraft.item.ItemSword in project MinecraftForge by MinecraftForge.
the class ForgeHooks method onBlockBreakEvent.
public static int onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, BlockPos pos) {
// Logic from tryHarvestBlock for pre-canceling the event
boolean preCancelEvent = false;
if (gameType.isCreative() && !entityPlayer.getHeldItemMainhand().isEmpty() && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
preCancelEvent = true;
if (gameType.isAdventure()) {
if (gameType == GameType.SPECTATOR)
preCancelEvent = true;
if (!entityPlayer.isAllowEdit()) {
ItemStack itemstack = entityPlayer.getHeldItemMainhand();
if (itemstack.isEmpty() || !itemstack.canDestroy(world.getBlockState(pos).getBlock()))
preCancelEvent = true;
}
}
// Tell client the block is gone immediately then process events
if (world.getTileEntity(pos) == null) {
SPacketBlockChange packet = new SPacketBlockChange(world, pos);
packet.blockState = Blocks.AIR.getDefaultState();
entityPlayer.connection.sendPacket(packet);
}
// Post the block break event
IBlockState state = world.getBlockState(pos);
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, entityPlayer);
event.setCanceled(preCancelEvent);
MinecraftForge.EVENT_BUS.post(event);
// Handle if the event is canceled
if (event.isCanceled()) {
// Let the client know the block still exists
entityPlayer.connection.sendPacket(new SPacketBlockChange(world, pos));
// Update any tile entity data for this block
TileEntity tileentity = world.getTileEntity(pos);
if (tileentity != null) {
Packet<?> pkt = tileentity.getUpdatePacket();
if (pkt != null) {
entityPlayer.connection.sendPacket(pkt);
}
}
}
return event.isCanceled() ? -1 : event.getExpToDrop();
}
Aggregations