net.minecraft.entity.damage.DamageSource Java Examples
The following examples show how to use
net.minecraft.entity.damage.DamageSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerEntity_parrotMixin.java From fabric-carpet with MIT License | 6 votes |
@Inject(method = "damage", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, target = "Lnet/minecraft/entity/player/PlayerEntity;dropShoulderEntities()V")) private void onDamage(DamageSource damageSource_1, float float_1, CallbackInfoReturnable<Boolean> cir) { if (CarpetSettings.persistentParrots && !this.isSneaking()) { if (this.random.nextFloat() < ((float_1)/15.0) ) { this.dismount_left(); } if (this.random.nextFloat() < ((float_1)/15.0) ) { this.dismount_right(); } } }
Example #2
Source File: HallowedEvents.java From the-hallow with MIT License | 6 votes |
public static void init() { WitchTickCallback.EVENT.register((witch) -> { if (!witch.hasStatusEffect(StatusEffects.WATER_BREATHING)) { if (witch.getEntityWorld().hasRain(witch.getBlockPos().up())) { witch.damage(DamageSource.DROWN, 4.0F); } else if (witch.checkWaterState() && !witch.updateMovementInFluid(HallowedTags.Fluids.WITCH_WATER)) { witch.damage(DamageSource.DROWN, 4.0F); } } return ActionResult.PASS; }); LootTableLoadingCallback.EVENT.register(((resourceManager, lootManager, id, supplier, setter) -> { if (id.equals(EntityType.WITCH.getLootTableId())) { supplier.withPool(FabricLootPoolBuilder.builder().withCondition(RandomChanceLootCondition.builder(0.01f)).withEntry(ItemEntry.builder(HallowedItems.GOLDEN_CANDY_CORN))); } })); }
Example #3
Source File: LivingEntityMixin.java From the-hallow with MIT License | 6 votes |
@Inject(method = "drop(Lnet/minecraft/entity/damage/DamageSource;)V", at = @At("HEAD")) public void drop(DamageSource damageSource, CallbackInfo info) { LivingEntity livingEntity = (LivingEntity) (Object) this; if (damageSource.getSource() instanceof LivingEntity && livingEntity.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT) && BeheadingEnchantment.hasBeheading((LivingEntity) damageSource.getSource())) { if (BeheadingEnchantment.getHead(damageSource)) { if (livingEntity.getType() == EntityType.WITHER_SKELETON) { livingEntity.dropStack(new ItemStack(Items.WITHER_SKELETON_SKULL)); } else if (livingEntity.getType() == EntityType.SKELETON) { livingEntity.dropStack(new ItemStack(Items.SKELETON_SKULL)); } else if (livingEntity.getType() == EntityType.ZOMBIE) { livingEntity.dropStack(new ItemStack(Items.ZOMBIE_HEAD)); } else if (livingEntity.getType() == EntityType.CREEPER) { livingEntity.dropStack(new ItemStack(Items.CREEPER_HEAD)); } else if (livingEntity.getType() == EntityType.PLAYER) { livingEntity.dropStack(new ItemStack(Items.PLAYER_HEAD)); } } } }
Example #4
Source File: ChickenEntityMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean interactMob(PlayerEntity playerEntity_1, Hand hand_1) { ItemStack stack = playerEntity_1.getStackInHand(hand_1); if (CarpetExtraSettings.chickenShearing && stack.getItem() == Items.SHEARS && !this.isBaby()) { if (!this.world.isClient) { this.damage(DamageSource.GENERIC, 1); this.dropItem(Items.FEATHER, 1); stack.damage(1, (LivingEntity)playerEntity_1, ((playerEntity_1x) -> { playerEntity_1x.sendToolBreakStatus(hand_1); })); } } return super.interactMob(playerEntity_1, hand_1); }
Example #5
Source File: LivingEntityMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 6 votes |
@Inject( method = "onDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/damage/DamageSource;getAttacker()Lnet/minecraft/entity/Entity;", shift = At.Shift.BEFORE) ) private void convertSandToSoulsand(DamageSource damageSource_1, CallbackInfo ci) { if (!CarpetExtraSettings.mobInFireConvertsSandToSoulsand) return; BlockPos pos = new BlockPos(this.getX(), this.getY(), this.getZ()); BlockState statePos = this.world.getBlockState(pos); BlockPos below = pos.down(1); BlockState stateBelow = this.world.getBlockState(below); if (statePos.getBlock() == Blocks.FIRE && stateBelow.getBlock().matches(BlockTags.SAND)) { this.world.setBlockState(below, Blocks.SOUL_SAND.getDefaultState()); } }
Example #6
Source File: EntityEventsGroup.java From fabric-carpet with MIT License | 5 votes |
@Override public List<Value> makeArgs(Entity entity, Object... providedArgs) { float amount = (Float)providedArgs[0]; DamageSource source = (DamageSource)providedArgs[1]; return Arrays.asList( new EntityValue(entity), new NumericValue(amount), new StringValue(source.getName()), source.getAttacker()==null?Value.NULL:new EntityValue(source.getAttacker()) ); }
Example #7
Source File: MixinLivingEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "onDeath", at = @At("HEAD"), cancellable = true) private void hookDeath(DamageSource source, CallbackInfo callback) { LivingEntity entity = (LivingEntity) (Object) this; if (EntityEvents.onLivingDeath(entity, source)) { callback.cancel(); } }
Example #8
Source File: MixinLivingEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "damage", at = @At("HEAD"), cancellable = true) private void hookDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> callback) { LivingEntity entity = (LivingEntity) (Object) this; if (EntityEvents.onLivingAttack(entity, source, amount)) { callback.setReturnValue(false); } }
Example #9
Source File: MixinLivingEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "drop", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/LivingEntity;playerHitTimer : I"), locals = LocalCapture.CAPTURE_FAILHARD) private void hookDropForCapturePre(DamageSource src, CallbackInfo info, int lootingLevel) { IForgeEntity forgeEntity = (IForgeEntity) this; forgeEntity.captureDrops(new ArrayList<>()); dropLootingLevel.set(lootingLevel); }
Example #10
Source File: MixinLivingEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "drop", at = @At("TAIL")) private void hookDropForDropsEvent(DamageSource src, CallbackInfo info) { LivingEntity entity = (LivingEntity) (Object) this; IForgeEntity forgeEntity = (IForgeEntity) this; Collection<ItemEntity> drops = forgeEntity.captureDrops(null); if (!MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, src, drops, dropLootingLevel.get(), playerHitTimer > 0))) { for (ItemEntity item : drops) { forgeEntity.getEntity().world.spawnEntity(item); } } dropLootingLevel.remove(); }
Example #11
Source File: MixinOtherClientPlayerEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "damage", at = @At("HEAD"), cancellable = true) private void hookDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> callback) { LivingEntity entity = (LivingEntity) (Object) this; if (EntityEvents.onLivingAttack(entity, source, amount)) { callback.setReturnValue(false); } }
Example #12
Source File: MixinPlayerEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "onDeath", at = @At("HEAD"), cancellable = true) private void hookDeath(DamageSource source, CallbackInfo callback) { LivingEntity entity = (LivingEntity) (Object) this; if (EntityEvents.onLivingDeath(entity, source)) { callback.cancel(); } }
Example #13
Source File: MixinPlayerEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "damage", at = @At("HEAD"), cancellable = true) private void hookDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> callback) { LivingEntity entity = (LivingEntity) (Object) this; if (EntityEvents.onLivingAttack(entity, source, amount)) { callback.setReturnValue(false); } }
Example #14
Source File: CarpetEventServer.java From fabric-carpet with MIT License | 5 votes |
@Override public void onDamage(Entity target, float amount, DamageSource source) { handler.call( () -> { return Arrays.asList( ((c, t) -> new EntityValue(target)), ((c, t) -> new NumericValue(amount)), ((c, t) ->new StringValue(source.getName())), ((c, t) -> source.getAttacker()==null?Value.NULL:new EntityValue(source.getAttacker())) ); }, target::getCommandSource); }
Example #15
Source File: CarpetEventServer.java From fabric-carpet with MIT License | 5 votes |
@Override public void onDamage(Entity target, float amount, DamageSource source) { handler.call( () -> { return Arrays.asList( ((c, t) -> new EntityValue(source.getAttacker())), ((c, t) -> new NumericValue(amount)), ((c, t) -> new EntityValue(target)) ); }, () -> source.getAttacker().getCommandSource()); }
Example #16
Source File: MixinServerPlayerEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "onDeath", at = @At("HEAD"), cancellable = true) private void hookDeath(DamageSource source, CallbackInfo callback) { LivingEntity entity = (LivingEntity) (Object) this; if (EntityEvents.onLivingDeath(entity, source)) { callback.cancel(); } }
Example #17
Source File: EntityPlayerMPFake.java From fabric-carpet with MIT License | 5 votes |
@Override public void onDeath(DamageSource cause) { super.onDeath(cause); setHealth(20); this.hungerManager = new HungerManager(); kill(); }
Example #18
Source File: DamageReporter.java From fabric-carpet with MIT License | 5 votes |
public static void register_damage(LivingEntity target, DamageSource source, float amount) { if (!LoggerRegistry.__damage) return; if (source.isFire() && (target.isFireImmune() || target.hasStatusEffect(StatusEffects.FIRE_RESISTANCE))) return; LoggerRegistry.getLogger("damage").log( (option, player)-> verifyAndProduceMessage(option, player, source.getSource(), target, () -> Messenger.c(target.getDisplayName(), "g receiving ", String.format("r %.2f", amount), String.format("g points of damage from %s", source.getName())) ) ); }
Example #19
Source File: DamageReporter.java From fabric-carpet with MIT License | 5 votes |
public static void register_final_damage(LivingEntity target, DamageSource source, float amount) { if (!LoggerRegistry.__damage) return; LoggerRegistry.getLogger("damage").log( (option, player)-> verifyAndProduceMessage(option, player, source.getSource(), target, () -> Messenger.c("g - total received ", String.format("r %.2f", amount), "g points of damage") ) ); }
Example #20
Source File: DamageReporter.java From fabric-carpet with MIT License | 5 votes |
public static void modify_damage(LivingEntity target, DamageSource source, float previous_amount, float final_amount, String component) { if (!LoggerRegistry.__damage) return; if (previous_amount == final_amount) return; if (source.isFire() && (target.isFireImmune() || target.hasStatusEffect(StatusEffects.FIRE_RESISTANCE))) return; LoggerRegistry.getLogger("damage").log( (option, player)-> verifyAndProduceMessage(option, player, source.getSource(), target, () -> { if (final_amount == 0.0f) { return Messenger.c("g - reduced to ","r 0.0","g due to: "+component); } else if (previous_amount > final_amount) { float reduction = previous_amount-final_amount; return Messenger.c("g - reduced to ", String.format("l %.2f",final_amount), String.format("g by %.2f (%.1f%% less) due to: %s",reduction,100.0*reduction/previous_amount, component)); } else { float increase = final_amount-previous_amount; return Messenger.c("g - increased to ", String.format("r %.2f",final_amount), String.format("g by %.2f (%.1f%% more) due to: %s",increase,100.0*increase/previous_amount, component)); } } ) ); }
Example #21
Source File: DamageTracker_scarpetEventMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "onDamage", at = @At("HEAD")) private void onDamageTaken(DamageSource damageSource_1, float float_1, float float_2, CallbackInfo ci) { ((EntityInterface)entity).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DAMAGE, entity, float_2, damageSource_1); if (entity instanceof ServerPlayerEntity && PLAYER_TAKES_DAMAGE.isNeeded()) { PLAYER_TAKES_DAMAGE.onDamage(entity, float_2, damageSource_1); } if (damageSource_1.getAttacker() instanceof ServerPlayerEntity && PLAYER_DEALS_DAMAGE.isNeeded()) { PLAYER_DEALS_DAMAGE.onDamage(entity, float_2, damageSource_1); } }
Example #22
Source File: LivingEntity_maxCollisionsMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "tickCramming", cancellable = true, at = @At("HEAD")) private void tickPushingReplacement(CallbackInfo ci) { List<Entity> list_1 = this.world.getEntities((Entity)this, this.getBoundingBox(), EntityPredicates.canBePushedBy(this)); if (!list_1.isEmpty()) { int int_1 = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING); int int_2; if (int_1 > 0 && list_1.size() > int_1 - 1 && this.random.nextInt(4) == 0) { int_2 = 0; for(int int_3 = 0; int_3 < list_1.size(); ++int_3) { if (!((Entity)list_1.get(int_3)).hasVehicle()) { ++int_2; } } if (int_2 > int_1 - 1) { this.damage(DamageSource.CRAMMING, 6.0F); } } int limit = list_1.size(); if (CarpetSettings.maxEntityCollisions > 0) limit = Math.min(limit, CarpetSettings.maxEntityCollisions); for(int_2 = 0; int_2 < limit; ++int_2) { Entity entity_1 = (Entity)list_1.get(int_2); this.pushAway(entity_1); } } ci.cancel(); }
Example #23
Source File: ServerPlayerEntity_scarpetEventMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "onDeath", at = @At("HEAD")) private void onDeathEvent(DamageSource source, CallbackInfo ci) { ((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, source.name); if (PLAYER_DIES.isNeeded()) { PLAYER_DIES.onPlayerEvent((ServerPlayerEntity) (Object)this); } }
Example #24
Source File: LivingEntityMixin.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Inject(method = "baseTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;tickStatusEffects()V", shift = At.Shift.BEFORE)) private void doOxygenChecks(CallbackInfo ci) { LivingEntity entity = (LivingEntity) (Object) this; //noinspection ConstantConditions if (this.isAlive() && !(entity instanceof PlayerEntity && ((PlayerEntity) entity).abilities.invulnerable)) { if (CelestialBodyType.getByDimType(world.getRegistryKey()).isPresent() && !CelestialBodyType.getByDimType(world.getRegistryKey()).get().getAtmosphere().getComposition().containsKey(AtmosphericGas.OXYGEN)) { updateAir(this); } else { if (this.isSubmergedIn(FluidTags.WATER) && this.world.getBlockState(new BlockPos(this.getX(), this.getEyeY(), this.getZ())).getBlock() != Blocks.BUBBLE_COLUMN) { if (!this.canBreatheInWater() && !StatusEffectUtil.hasWaterBreathing((LivingEntity) (Object) this) && !isInvulnerableTo(DamageSource.DROWN)) { this.setAir(this.getNextAirUnderwater(this.getAir())); } } } if (this.getAir() == -20) { this.setAir(0); if (this.isSubmergedIn(FluidTags.WATER) && this.world.getBlockState(new BlockPos(this.getX(), this.getEyeY(), this.getZ())).getBlock() != Blocks.BUBBLE_COLUMN) { if (!this.canBreatheInWater() && !StatusEffectUtil.hasWaterBreathing((LivingEntity) (Object) this) && !isInvulnerableTo(DamageSource.DROWN)) { Vec3d vec3d = this.getVelocity(); for (int i = 0; i < 8; ++i) { float f = this.random.nextFloat() - this.random.nextFloat(); float g = this.random.nextFloat() - this.random.nextFloat(); float h = this.random.nextFloat() - this.random.nextFloat(); this.world.addParticle(ParticleTypes.BUBBLE, this.getX() + (double) f, this.getY() + (double) g, this.getZ() + (double) h, vec3d.x, vec3d.y, vec3d.z); } } } this.damage(GalacticraftDamageSource.SUFFOCATION, 2.0F); } } }
Example #25
Source File: SpiderEntityMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onDeath(DamageSource source) { if (this.hasPassengers() && this.random.nextInt(100) + 1 < CarpetExtraSettings.spiderJockeysDropGapples) { this.dropStack(new ItemStack(Items.ENCHANTED_GOLDEN_APPLE)); } super.onDeath(source); }
Example #26
Source File: LivingDropsEvent.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
public LivingDropsEvent(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) { super(entity); this.source = source; this.drops = drops; this.lootingLevel = lootingLevel; this.recentlyHit = recentlyHit; }
Example #27
Source File: LivingEntityMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 5 votes |
@Inject(method = "onDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/damage/DamageSource;getAttacker()Lnet/minecraft/entity/Entity;")) private void onOnDeath(DamageSource source, CallbackInfo ci) { if ((this.getVehicle() instanceof SpiderEntity) && this.random.nextInt(100) + 1 < CarpetExtraSettings.spiderJockeysDropGapples) { this.dropStack(new ItemStack(Items.ENCHANTED_GOLDEN_APPLE)); } }
Example #28
Source File: AutoArmorHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
private int getArmorValue(ArmorItem item, ItemStack stack) { int armorPoints = item.getProtection(); int prtPoints = 0; int armorToughness = (int)((IArmorItem)item).getToughness(); int armorType = item.getMaterial().getProtectionAmount(EquipmentSlot.LEGS); if(useEnchantments.isChecked()) { Enchantment protection = Enchantments.PROTECTION; int prtLvl = EnchantmentHelper.getLevel(protection, stack); ClientPlayerEntity player = MC.player; DamageSource dmgSource = DamageSource.player(player); prtPoints = protection.getProtectionAmount(prtLvl, dmgSource); } return armorPoints * 5 + prtPoints * 3 + armorToughness + armorType; }
Example #29
Source File: LivingEntityMixin.java From the-hallow with MIT License | 5 votes |
@Inject(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", at = @At("RETURN")) public void applyDamage(DamageSource damageSource, float damage, CallbackInfo info) { LivingEntity attacked = (LivingEntity) (Object) this; if (damageSource.getSource() instanceof LivingEntity && attacked.getHealth() < damage) { LivingEntity attacker = (LivingEntity) damageSource.getSource(); if (!attacked.isInvulnerableTo(damageSource)) { float health = LifestealEnchantment.getLifeWithSteal(damageSource, damage, attacked); if (health != 0) { attacker.setHealth(health); } } } }
Example #30
Source File: LifestealEnchantment.java From the-hallow with MIT License | 5 votes |
public static float getLifeWithSteal(DamageSource damageSource, float damage, LivingEntity attackedEntity) { if (damageSource.getSource() instanceof LivingEntity && hasLifesteal((LivingEntity) damageSource.getSource()) && attackedEntity.getHealth() <= 0) { LivingEntity attacker = (LivingEntity) damageSource.getSource(); int enchantmentLevel = EnchantmentHelper.getEquipmentLevel(HallowedEnchantments.LIFESTEAL, attacker); float stolenHealth = damage * STEAL_MULTIPLIER.get(enchantmentLevel); return Math.min(attacker.getMaximumHealth(), attacker.getHealth() + stolenHealth); } else { return 0; } }