File size: 9,542 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package net.minecraft.world.damagesource;

import javax.annotation.Nullable;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Fireball;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.entity.projectile.WitherSkull;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.phys.Vec3;

public class DamageSources {
    private final Registry<DamageType> damageTypes;
    private final DamageSource inFire;
    private final DamageSource campfire;
    private final DamageSource lightningBolt;
    private final DamageSource onFire;
    private final DamageSource lava;
    private final DamageSource hotFloor;
    private final DamageSource inWall;
    private final DamageSource cramming;
    private final DamageSource drown;
    private final DamageSource starve;
    private final DamageSource cactus;
    private final DamageSource fall;
    private final DamageSource enderPearl;
    private final DamageSource flyIntoWall;
    private final DamageSource fellOutOfWorld;
    private final DamageSource generic;
    private final DamageSource magic;
    private final DamageSource wither;
    private final DamageSource dragonBreath;
    private final DamageSource dryOut;
    private final DamageSource sweetBerryBush;
    private final DamageSource freeze;
    private final DamageSource stalagmite;
    private final DamageSource outsideBorder;
    private final DamageSource genericKill;

    public DamageSources(RegistryAccess p_270740_) {
        this.damageTypes = p_270740_.lookupOrThrow(Registries.DAMAGE_TYPE);
        this.inFire = this.source(DamageTypes.IN_FIRE);
        this.campfire = this.source(DamageTypes.CAMPFIRE);
        this.lightningBolt = this.source(DamageTypes.LIGHTNING_BOLT);
        this.onFire = this.source(DamageTypes.ON_FIRE);
        this.lava = this.source(DamageTypes.LAVA);
        this.hotFloor = this.source(DamageTypes.HOT_FLOOR);
        this.inWall = this.source(DamageTypes.IN_WALL);
        this.cramming = this.source(DamageTypes.CRAMMING);
        this.drown = this.source(DamageTypes.DROWN);
        this.starve = this.source(DamageTypes.STARVE);
        this.cactus = this.source(DamageTypes.CACTUS);
        this.fall = this.source(DamageTypes.FALL);
        this.enderPearl = this.source(DamageTypes.ENDER_PEARL);
        this.flyIntoWall = this.source(DamageTypes.FLY_INTO_WALL);
        this.fellOutOfWorld = this.source(DamageTypes.FELL_OUT_OF_WORLD);
        this.generic = this.source(DamageTypes.GENERIC);
        this.magic = this.source(DamageTypes.MAGIC);
        this.wither = this.source(DamageTypes.WITHER);
        this.dragonBreath = this.source(DamageTypes.DRAGON_BREATH);
        this.dryOut = this.source(DamageTypes.DRY_OUT);
        this.sweetBerryBush = this.source(DamageTypes.SWEET_BERRY_BUSH);
        this.freeze = this.source(DamageTypes.FREEZE);
        this.stalagmite = this.source(DamageTypes.STALAGMITE);
        this.outsideBorder = this.source(DamageTypes.OUTSIDE_BORDER);
        this.genericKill = this.source(DamageTypes.GENERIC_KILL);
    }

    private DamageSource source(ResourceKey<DamageType> p_270957_) {
        return new DamageSource(this.damageTypes.getOrThrow(p_270957_));
    }

    private DamageSource source(ResourceKey<DamageType> p_270142_, @Nullable Entity p_270696_) {
        return new DamageSource(this.damageTypes.getOrThrow(p_270142_), p_270696_);
    }

    private DamageSource source(ResourceKey<DamageType> p_270076_, @Nullable Entity p_270656_, @Nullable Entity p_270242_) {
        return new DamageSource(this.damageTypes.getOrThrow(p_270076_), p_270656_, p_270242_);
    }

    public DamageSource inFire() {
        return this.inFire;
    }

    public DamageSource campfire() {
        return this.campfire;
    }

    public DamageSource lightningBolt() {
        return this.lightningBolt;
    }

    public DamageSource onFire() {
        return this.onFire;
    }

    public DamageSource lava() {
        return this.lava;
    }

    public DamageSource hotFloor() {
        return this.hotFloor;
    }

    public DamageSource inWall() {
        return this.inWall;
    }

    public DamageSource cramming() {
        return this.cramming;
    }

    public DamageSource drown() {
        return this.drown;
    }

    public DamageSource starve() {
        return this.starve;
    }

    public DamageSource cactus() {
        return this.cactus;
    }

    public DamageSource fall() {
        return this.fall;
    }

    public DamageSource enderPearl() {
        return this.enderPearl;
    }

    public DamageSource flyIntoWall() {
        return this.flyIntoWall;
    }

    public DamageSource fellOutOfWorld() {
        return this.fellOutOfWorld;
    }

    public DamageSource generic() {
        return this.generic;
    }

    public DamageSource magic() {
        return this.magic;
    }

    public DamageSource wither() {
        return this.wither;
    }

    public DamageSource dragonBreath() {
        return this.dragonBreath;
    }

    public DamageSource dryOut() {
        return this.dryOut;
    }

    public DamageSource sweetBerryBush() {
        return this.sweetBerryBush;
    }

    public DamageSource freeze() {
        return this.freeze;
    }

    public DamageSource stalagmite() {
        return this.stalagmite;
    }

    public DamageSource fallingBlock(Entity p_270643_) {
        return this.source(DamageTypes.FALLING_BLOCK, p_270643_);
    }

    public DamageSource anvil(Entity p_270112_) {
        return this.source(DamageTypes.FALLING_ANVIL, p_270112_);
    }

    public DamageSource fallingStalactite(Entity p_270720_) {
        return this.source(DamageTypes.FALLING_STALACTITE, p_270720_);
    }

    public DamageSource sting(LivingEntity p_270689_) {
        return this.source(DamageTypes.STING, p_270689_);
    }

    public DamageSource mobAttack(LivingEntity p_270357_) {
        return this.source(DamageTypes.MOB_ATTACK, p_270357_);
    }

    public DamageSource noAggroMobAttack(LivingEntity p_270502_) {
        return this.source(DamageTypes.MOB_ATTACK_NO_AGGRO, p_270502_);
    }

    public DamageSource playerAttack(Player p_270723_) {
        return this.source(DamageTypes.PLAYER_ATTACK, p_270723_);
    }

    public DamageSource arrow(AbstractArrow p_270570_, @Nullable Entity p_270857_) {
        return this.source(DamageTypes.ARROW, p_270570_, p_270857_);
    }

    public DamageSource trident(Entity p_270146_, @Nullable Entity p_270358_) {
        return this.source(DamageTypes.TRIDENT, p_270146_, p_270358_);
    }

    public DamageSource mobProjectile(Entity p_270210_, @Nullable LivingEntity p_270757_) {
        return this.source(DamageTypes.MOB_PROJECTILE, p_270210_, p_270757_);
    }

    public DamageSource spit(Entity p_330027_, @Nullable LivingEntity p_334967_) {
        return this.source(DamageTypes.SPIT, p_330027_, p_334967_);
    }

    public DamageSource windCharge(Entity p_336392_, @Nullable LivingEntity p_335043_) {
        return this.source(DamageTypes.WIND_CHARGE, p_336392_, p_335043_);
    }

    public DamageSource fireworks(FireworkRocketEntity p_270571_, @Nullable Entity p_270768_) {
        return this.source(DamageTypes.FIREWORKS, p_270571_, p_270768_);
    }

    public DamageSource fireball(Fireball p_270147_, @Nullable Entity p_270824_) {
        return p_270824_ == null ? this.source(DamageTypes.UNATTRIBUTED_FIREBALL, p_270147_) : this.source(DamageTypes.FIREBALL, p_270147_, p_270824_);
    }

    public DamageSource witherSkull(WitherSkull p_270367_, Entity p_270887_) {
        return this.source(DamageTypes.WITHER_SKULL, p_270367_, p_270887_);
    }

    public DamageSource thrown(Entity p_270388_, @Nullable Entity p_270485_) {
        return this.source(DamageTypes.THROWN, p_270388_, p_270485_);
    }

    public DamageSource indirectMagic(Entity p_270560_, @Nullable Entity p_270646_) {
        return this.source(DamageTypes.INDIRECT_MAGIC, p_270560_, p_270646_);
    }

    public DamageSource thorns(Entity p_270917_) {
        return this.source(DamageTypes.THORNS, p_270917_);
    }

    public DamageSource explosion(@Nullable Explosion p_270369_) {
        return p_270369_ != null ? this.explosion(p_270369_.getDirectSourceEntity(), p_270369_.getIndirectSourceEntity()) : this.explosion(null, null);
    }

    public DamageSource explosion(@Nullable Entity p_271016_, @Nullable Entity p_270814_) {
        return this.source(p_270814_ != null && p_271016_ != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION, p_271016_, p_270814_);
    }

    public DamageSource sonicBoom(Entity p_270401_) {
        return this.source(DamageTypes.SONIC_BOOM, p_270401_);
    }

    public DamageSource badRespawnPointExplosion(Vec3 p_270175_) {
        return new DamageSource(this.damageTypes.getOrThrow(DamageTypes.BAD_RESPAWN_POINT), p_270175_);
    }

    public DamageSource outOfBorder() {
        return this.outsideBorder;
    }

    public DamageSource genericKill() {
        return this.genericKill;
    }

    public DamageSource mace(Entity p_366510_) {
        return this.source(DamageTypes.MACE_SMASH, p_366510_);
    }
}