use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.
the class FeatureSwordInfo method onEntityDamaged.
@SubscribeEvent
public void onEntityDamaged(LivingHurtEvent 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);
if (stack.getItemDamage() < stack.getMaxDamage() - 1) {
EntityLivingBase living = event.getEntityLiving();
if (living.getHealth() < event.getAmount()) {
tag.setInteger("DamageDealt", tag.getInteger("DamageDealt") + (int) living.getHealth());
} else {
tag.setInteger("DamageDealt", tag.getInteger("DamageDealt") + (int) event.getAmount());
}
}
}
}
}
use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.
the class TweakToolBreaking method onHitEntity.
@SubscribeEvent
public void onHitEntity(LivingHurtEvent event) {
if (!ModConfig.confBrokenTools) {
return;
}
if (!event.getSource().getDamageType().equals("player")) {
return;
}
if (!(event.getSource().getTrueSource() instanceof EntityPlayer)) {
return;
}
EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
ItemStack stack = player.getHeldItemMainhand();
if (stack.isEmpty()) {
return;
}
if (!(stack.getItem() instanceof ItemTool) && !(stack.getItem() instanceof ItemSword) && !(stack.getItem() instanceof ItemHoe)) {
return;
}
if (stack.isItemStackDamageable()) {
int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack);
if (isBroken(stack, (unbreaking > 0 ? 1 : 0))) {
if (overrides.containsKey(stack.getItem())) {
stack.setItemDamage(stack.getMaxDamage() - overrides.get(stack.getItem()));
} else {
stack.setItemDamage(stack.getMaxDamage() - 1);
}
event.setAmount(0.5F);
}
}
}
use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.
the class TweakToolBreaking method onItemTooltip.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
if (!ModConfig.confBrokenTools) {
return;
}
if (event.getEntityPlayer() == null) {
return;
}
ItemStack stack = event.getItemStack();
if (!(stack.getItem() instanceof ItemTool) && !(stack.getItem() instanceof ItemSword) && !(stack.getItem() instanceof ItemHoe) && !(stack.getItem() instanceof ItemBow)) {
return;
}
ListIterator<String> itr = event.getToolTip().listIterator();
if (stack.isItemStackDamageable()) {
if (isBroken(stack, (stack.getItem() instanceof ItemSword ? 1 : 0))) {
while (itr.hasNext()) {
itr.next();
itr.add(Colors.RED + Utils.localize("tooltip.pt.broken"));
break;
}
while (itr.hasNext()) {
if (itr.next().contains(I18n.translateToLocal("attribute.name.generic.attackDamage"))) {
itr.set(" 0.5 " + Utils.localize("attribute.name.generic.attackDamage"));
}
}
}
}
}
use of net.minecraft.item.ItemSword in project LiquidBouncePlus by WYSI-Foundation.
the class MixinEntityPlayerSP method onLivingUpdate.
/**
* @author CCBlueX
*/
@Overwrite
public void onLivingUpdate() {
LiquidBounce.eventManager.callEvent(new UpdateEvent());
if (this.sprintingTicksLeft > 0) {
--this.sprintingTicksLeft;
if (this.sprintingTicksLeft == 0) {
this.setSprinting(false);
}
}
if (this.sprintToggleTimer > 0) {
--this.sprintToggleTimer;
}
this.prevTimeInPortal = this.timeInPortal;
if (this.inPortal) {
if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame() && !LiquidBounce.moduleManager.getModule(PortalMenu.class).getState()) {
this.mc.displayGuiScreen(null);
}
if (this.timeInPortal == 0.0F) {
this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
}
this.timeInPortal += 0.0125F;
if (this.timeInPortal >= 1.0F) {
this.timeInPortal = 1.0F;
}
this.inPortal = false;
} else if (this.isPotionActive(Potion.confusion) && this.getActivePotionEffect(Potion.confusion).getDuration() > 60) {
this.timeInPortal += 0.006666667F;
if (this.timeInPortal > 1.0F) {
this.timeInPortal = 1.0F;
}
} else {
if (this.timeInPortal > 0.0F) {
this.timeInPortal -= 0.05F;
}
if (this.timeInPortal < 0.0F) {
this.timeInPortal = 0.0F;
}
}
if (this.timeUntilPortal > 0) {
--this.timeUntilPortal;
}
boolean flag = this.movementInput.jump;
boolean flag1 = this.movementInput.sneak;
float f = 0.8F;
boolean flag2 = this.movementInput.moveForward >= f;
this.movementInput.updatePlayerMoveState();
final NoSlow noSlow = (NoSlow) LiquidBounce.moduleManager.getModule(NoSlow.class);
final KillAura killAura = (KillAura) LiquidBounce.moduleManager.getModule(KillAura.class);
if (getHeldItem() != null && (this.isUsingItem() || (getHeldItem().getItem() instanceof ItemSword && killAura.getBlockingStatus())) && !this.isRiding()) {
final SlowDownEvent slowDownEvent = new SlowDownEvent(0.2F, 0.2F);
LiquidBounce.eventManager.callEvent(slowDownEvent);
this.movementInput.moveStrafe *= slowDownEvent.getStrafe();
this.movementInput.moveForward *= slowDownEvent.getForward();
this.sprintToggleTimer = 0;
}
this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
final Sprint sprint = (Sprint) LiquidBounce.moduleManager.getModule(Sprint.class);
boolean flag3 = !sprint.getFoodValue().get() || (float) this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
if (this.onGround && !flag1 && !flag2 && this.movementInput.moveForward >= f && !this.isSprinting() && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness)) {
if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.isKeyDown()) {
this.sprintToggleTimer = 7;
} else {
this.setSprinting(true);
}
}
if (!this.isSprinting() && this.movementInput.moveForward >= f && flag3 && (noSlow.getState() || !this.isUsingItem()) && !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.isKeyDown()) {
this.setSprinting(true);
}
final Scaffold scaffold = (Scaffold) LiquidBounce.moduleManager.getModule(Scaffold.class);
// final Tower tower = (Tower) LiquidBounce.moduleManager.getModule(Tower.class);
NoSlow noslow = (NoSlow) LiquidBounce.moduleManager.getModule(NoSlow.class);
if ((scaffold.getState() && scaffold.towerActivation() && scaffold.sprintModeValue.get().equalsIgnoreCase("Off")) || (scaffold.getState() && scaffold.sprintModeValue.get().equalsIgnoreCase("Off")) || (sprint.getState() && sprint.getCheckServerSide().get() && (onGround || !sprint.getCheckServerSideGround().get()) && !sprint.getAllDirectionsValue().get() && RotationUtils.targetRotation != null && RotationUtils.getRotationDifference(new Rotation(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch)) > 30))
this.setSprinting(false);
if (this.isSprinting() && ((!(sprint.getState() && sprint.getAllDirectionsValue().get()) && this.movementInput.moveForward < f) || this.isCollidedHorizontally || !flag3)) {
this.setSprinting(false);
}
if (this.capabilities.allowFlying) {
if (this.mc.playerController.isSpectatorMode()) {
if (!this.capabilities.isFlying) {
this.capabilities.isFlying = true;
this.sendPlayerAbilities();
}
} else if (!flag && this.movementInput.jump) {
if (this.flyToggleTimer == 0) {
this.flyToggleTimer = 7;
} else {
this.capabilities.isFlying = !this.capabilities.isFlying;
this.sendPlayerAbilities();
this.flyToggleTimer = 0;
}
}
}
if (this.capabilities.isFlying && this.isCurrentViewEntity()) {
if (this.movementInput.sneak) {
this.motionY -= (double) (this.capabilities.getFlySpeed() * 3.0F);
}
if (this.movementInput.jump) {
this.motionY += (double) (this.capabilities.getFlySpeed() * 3.0F);
}
}
if (this.isRidingHorse()) {
if (this.horseJumpPowerCounter < 0) {
++this.horseJumpPowerCounter;
if (this.horseJumpPowerCounter == 0) {
this.horseJumpPower = 0.0F;
}
}
if (flag && !this.movementInput.jump) {
this.horseJumpPowerCounter = -10;
this.sendHorseJump();
} else if (!flag && this.movementInput.jump) {
this.horseJumpPowerCounter = 0;
this.horseJumpPower = 0.0F;
} else if (flag) {
++this.horseJumpPowerCounter;
if (this.horseJumpPowerCounter < 10) {
this.horseJumpPower = (float) this.horseJumpPowerCounter * 0.1F;
} else {
this.horseJumpPower = 0.8F + 2.0F / (float) (this.horseJumpPowerCounter - 9) * 0.1F;
}
}
} else {
this.horseJumpPower = 0.0F;
}
super.onLivingUpdate();
if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode()) {
this.capabilities.isFlying = false;
this.sendPlayerAbilities();
}
}
use of net.minecraft.item.ItemSword in project LiquidBouncePlus by WYSI-Foundation.
the class TNTBlock method onMotionUpdate.
@EventTarget
public void onMotionUpdate(MotionEvent event) {
for (final Entity entity : mc.theWorld.loadedEntityList) {
if (entity instanceof EntityTNTPrimed && mc.thePlayer.getDistanceToEntity(entity) <= rangeValue.get()) {
final EntityTNTPrimed tntPrimed = (EntityTNTPrimed) entity;
if (tntPrimed.fuse <= fuseValue.get()) {
if (autoSwordValue.get()) {
int slot = -1;
float bestDamage = 1F;
for (int i = 0; i < 9; i++) {
final ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(i);
if (itemStack != null && itemStack.getItem() instanceof ItemSword) {
final float itemDamage = ((ItemSword) itemStack.getItem()).getDamageVsEntity() + 4F;
if (itemDamage > bestDamage) {
bestDamage = itemDamage;
slot = i;
}
}
}
if (slot != -1 && slot != mc.thePlayer.inventory.currentItem) {
mc.thePlayer.inventory.currentItem = slot;
mc.playerController.updateController();
}
}
if (mc.thePlayer.getHeldItem() != null && mc.thePlayer.getHeldItem().getItem() instanceof ItemSword) {
mc.gameSettings.keyBindUseItem.pressed = true;
blocked = true;
}
return;
}
}
}
if (blocked && !GameSettings.isKeyDown(mc.gameSettings.keyBindUseItem)) {
mc.gameSettings.keyBindUseItem.pressed = false;
blocked = false;
}
}
Aggregations