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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
--- a/net/minecraft/world/entity/projectile/Arrow.java
+++ b/net/minecraft/world/entity/projectile/Arrow.java
@@ -2,6 +2,7 @@
import com.google.common.collect.Sets;
import java.util.Collection;
+import java.util.Iterator;
import java.util.Set;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
@@ -22,73 +23,89 @@
import net.minecraft.world.level.Level;
public class Arrow extends AbstractArrow {
+
private static final int EXPOSED_POTION_DECAY_TIME = 600;
private static final int NO_EFFECT_COLOR = -1;
private static final EntityDataAccessor<Integer> ID_EFFECT_COLOR = SynchedEntityData.defineId(Arrow.class, EntityDataSerializers.INT);
private static final byte EVENT_POTION_PUFF = 0;
private static final ItemStack DEFAULT_ARROW_STACK = new ItemStack(Items.ARROW);
- private Potion potion = Potions.EMPTY;
- private final Set<MobEffectInstance> effects = Sets.newHashSet();
+ public Potion potion;
+ public final Set<MobEffectInstance> effects;
private boolean fixedColor;
public Arrow(EntityType<? extends Arrow> entityType, Level level) {
- super(entityType, level, DEFAULT_ARROW_STACK);
+ super(entityType, level, Arrow.DEFAULT_ARROW_STACK);
+ this.potion = Potions.EMPTY;
+ this.effects = Sets.newHashSet();
}
- public Arrow(Level level, double d, double d1, double d2, ItemStack itemStack) {
- super(EntityType.ARROW, d, d1, d2, level, itemStack);
+ public Arrow(Level world, double d0, double d1, double d2, ItemStack itemstack) {
+ super(EntityType.ARROW, d0, d1, d2, world, itemstack);
+ this.potion = Potions.EMPTY;
+ this.effects = Sets.newHashSet();
}
- public Arrow(Level level, LivingEntity livingEntity, ItemStack itemStack) {
- super(EntityType.ARROW, livingEntity, level, itemStack);
+ public Arrow(Level world, LivingEntity entityliving, ItemStack itemstack) {
+ super(EntityType.ARROW, entityliving, world, itemstack);
+ this.potion = Potions.EMPTY;
+ this.effects = Sets.newHashSet();
}
public void setEffectsFromItem(ItemStack stack) {
if (stack.is(Items.TIPPED_ARROW)) {
this.potion = PotionUtils.getPotion(stack);
- Collection<MobEffectInstance> customEffects = PotionUtils.getCustomEffects(stack);
- if (!customEffects.isEmpty()) {
- for (MobEffectInstance mobEffectInstance : customEffects) {
- this.effects.add(new MobEffectInstance(mobEffectInstance));
+ Collection<MobEffectInstance> collection = PotionUtils.getCustomEffects(stack);
+
+ if (!collection.isEmpty()) {
+ Iterator iterator = collection.iterator();
+
+ while (iterator.hasNext()) {
+ MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
+
+ this.effects.add(new MobEffectInstance(mobeffect));
}
}
- int customColor = getCustomColor(stack);
- if (customColor == -1) {
+ int i = getCustomColor(stack);
+
+ if (i == -1) {
this.updateColor();
} else {
- this.setFixedColor(customColor);
+ this.setFixedColor(i);
}
} else if (stack.is(Items.ARROW)) {
this.potion = Potions.EMPTY;
this.effects.clear();
- this.entityData.set(ID_EFFECT_COLOR, -1);
+ this.entityData.set(Arrow.ID_EFFECT_COLOR, -1);
}
+
}
public static int getCustomColor(ItemStack stack) {
- CompoundTag tag = stack.getTag();
- return tag != null && tag.contains("CustomPotionColor", 99) ? tag.getInt("CustomPotionColor") : -1;
+ CompoundTag nbttagcompound = stack.getTag();
+
+ return nbttagcompound != null && nbttagcompound.contains("CustomPotionColor", 99) ? nbttagcompound.getInt("CustomPotionColor") : -1;
}
- private void updateColor() {
+ public void updateColor() {
this.fixedColor = false;
if (this.potion == Potions.EMPTY && this.effects.isEmpty()) {
- this.entityData.set(ID_EFFECT_COLOR, -1);
+ this.entityData.set(Arrow.ID_EFFECT_COLOR, -1);
} else {
- this.entityData.set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects)));
+ this.entityData.set(Arrow.ID_EFFECT_COLOR, PotionUtils.getColor((Collection) PotionUtils.getAllEffects(this.potion, this.effects)));
}
+
}
public void addEffect(MobEffectInstance effectInstance) {
this.effects.add(effectInstance);
- this.getEntityData().set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects)));
+ this.getEntityData().set(Arrow.ID_EFFECT_COLOR, PotionUtils.getColor((Collection) PotionUtils.getAllEffects(this.potion, this.effects)));
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
- this.entityData.define(ID_EFFECT_COLOR, -1);
+ this.entityData.define(Arrow.ID_EFFECT_COLOR, -1);
}
@Override
@@ -103,33 +120,36 @@
this.makeParticle(2);
}
} else if (this.inGround && this.inGroundTime != 0 && !this.effects.isEmpty() && this.inGroundTime >= 600) {
- this.level().broadcastEntityEvent(this, (byte)0);
+ this.level().broadcastEntityEvent(this, (byte) 0);
this.potion = Potions.EMPTY;
this.effects.clear();
- this.entityData.set(ID_EFFECT_COLOR, -1);
+ this.entityData.set(Arrow.ID_EFFECT_COLOR, -1);
}
+
}
private void makeParticle(int particleAmount) {
- int color = this.getColor();
- if (color != -1 && particleAmount > 0) {
- double d = (double)(color >> 16 & 0xFF) / 255.0;
- double d1 = (double)(color >> 8 & 0xFF) / 255.0;
- double d2 = (double)(color >> 0 & 0xFF) / 255.0;
+ int j = this.getColor();
- for (int i = 0; i < particleAmount; i++) {
- this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5), this.getRandomY(), this.getRandomZ(0.5), d, d1, d2);
+ if (j != -1 && particleAmount > 0) {
+ double d0 = (double) (j >> 16 & 255) / 255.0D;
+ double d1 = (double) (j >> 8 & 255) / 255.0D;
+ double d2 = (double) (j >> 0 & 255) / 255.0D;
+
+ for (int k = 0; k < particleAmount; ++k) {
+ this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5D), this.getRandomY(), this.getRandomZ(0.5D), d0, d1, d2);
}
+
}
}
public int getColor() {
- return this.entityData.get(ID_EFFECT_COLOR);
+ return (Integer) this.entityData.get(Arrow.ID_EFFECT_COLOR);
}
- private void setFixedColor(int fixedColor) {
+ public void setFixedColor(int fixedColor) {
this.fixedColor = true;
- this.entityData.set(ID_EFFECT_COLOR, fixedColor);
+ this.entityData.set(Arrow.ID_EFFECT_COLOR, fixedColor);
}
@Override
@@ -144,14 +164,18 @@
}
if (!this.effects.isEmpty()) {
- ListTag list = new ListTag();
+ ListTag nbttaglist = new ListTag();
+ Iterator iterator = this.effects.iterator();
- for (MobEffectInstance mobEffectInstance : this.effects) {
- list.add(mobEffectInstance.save(new CompoundTag()));
+ while (iterator.hasNext()) {
+ MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
+
+ nbttaglist.add(mobeffect.save(new CompoundTag()));
}
- compound.put("custom_potion_effects", list);
+ compound.put("custom_potion_effects", nbttaglist);
}
+
}
@Override
@@ -161,8 +185,12 @@
this.potion = PotionUtils.getPotion(compound);
}
- for (MobEffectInstance mobEffectInstance : PotionUtils.getCustomEffects(compound)) {
- this.addEffect(mobEffectInstance);
+ Iterator iterator = PotionUtils.getCustomEffects(compound).iterator();
+
+ while (iterator.hasNext()) {
+ MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
+
+ this.addEffect(mobeffect);
}
if (compound.contains("Color", 99)) {
@@ -170,64 +198,69 @@
} else {
this.updateColor();
}
+
}
@Override
protected void doPostHurtEffects(LivingEntity living) {
super.doPostHurtEffects(living);
- Entity effectSource = this.getEffectSource();
+ Entity entity = this.getEffectSource();
+ Iterator iterator = this.potion.getEffects().iterator();
- for (MobEffectInstance mobEffectInstance : this.potion.getEffects()) {
- living.addEffect(
- new MobEffectInstance(
- mobEffectInstance.getEffect(),
- Math.max(mobEffectInstance.mapDuration(i -> i / 8), 1),
- mobEffectInstance.getAmplifier(),
- mobEffectInstance.isAmbient(),
- mobEffectInstance.isVisible()
- ),
- effectSource
- );
+ MobEffectInstance mobeffect;
+
+ while (iterator.hasNext()) {
+ mobeffect = (MobEffectInstance) iterator.next();
+ living.addEffect(new MobEffectInstance(mobeffect.getEffect(), Math.max(mobeffect.mapDuration((i) -> {
+ return i / 8;
+ }), 1), mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()), entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ARROW); // CraftBukkit
}
if (!this.effects.isEmpty()) {
- for (MobEffectInstance mobEffectInstance : this.effects) {
- living.addEffect(mobEffectInstance, effectSource);
+ iterator = this.effects.iterator();
+
+ while (iterator.hasNext()) {
+ mobeffect = (MobEffectInstance) iterator.next();
+ living.addEffect(mobeffect, entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ARROW); // CraftBukkit
}
}
+
}
@Override
protected ItemStack getPickupItem() {
- ItemStack itemStack = super.getPickupItem();
+ ItemStack itemstack = super.getPickupItem();
+
if (this.effects.isEmpty() && this.potion == Potions.EMPTY) {
- return itemStack;
+ return itemstack;
} else {
- PotionUtils.setPotion(itemStack, this.potion);
- PotionUtils.setCustomEffects(itemStack, this.effects);
+ PotionUtils.setPotion(itemstack, this.potion);
+ PotionUtils.setCustomEffects(itemstack, this.effects);
if (this.fixedColor) {
- itemStack.getOrCreateTag().putInt("CustomPotionColor", this.getColor());
+ itemstack.getOrCreateTag().putInt("CustomPotionColor", this.getColor());
}
- return itemStack;
+ return itemstack;
}
}
@Override
public void handleEntityEvent(byte id) {
if (id == 0) {
- int color = this.getColor();
- if (color != -1) {
- double d = (double)(color >> 16 & 0xFF) / 255.0;
- double d1 = (double)(color >> 8 & 0xFF) / 255.0;
- double d2 = (double)(color >> 0 & 0xFF) / 255.0;
+ int i = this.getColor();
- for (int i = 0; i < 20; i++) {
- this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5), this.getRandomY(), this.getRandomZ(0.5), d, d1, d2);
+ if (i != -1) {
+ double d0 = (double) (i >> 16 & 255) / 255.0D;
+ double d1 = (double) (i >> 8 & 255) / 255.0D;
+ double d2 = (double) (i >> 0 & 255) / 255.0D;
+
+ for (int j = 0; j < 20; ++j) {
+ this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5D), this.getRandomY(), this.getRandomZ(0.5D), d0, d1, d2);
}
}
} else {
super.handleEntityEvent(id);
}
+
}
}
|