-
Notifications
You must be signed in to change notification settings - Fork 8
/
KilledByWither.java
50 lines (39 loc) · 1.6 KB
/
KilledByWither.java
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
package com.draco18s.farming.loot;
import java.util.Random;
import org.apache.logging.log4j.Level;
import com.draco18s.farming.FarmingBase;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import net.minecraft.util.DamageSource;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraft.world.storage.loot.conditions.RandomChance;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
public class KilledByWither implements LootCondition {
private boolean invert;
public KilledByWither(boolean wasKilled) {
invert = !wasKilled;
}
@Override
public boolean testCondition(Random rand, LootContext context) {
DamageSource damage = ReflectionHelper.getPrivateValue(LootContext.class, context, "damageSource","field_186503_f");
if(invert)return (damage == DamageSource.wither);
else return (damage != DamageSource.wither);
}
public static class Serializer extends LootCondition.Serializer<KilledByWither> {
public Serializer() {
super(new ResourceLocation("killed_by_wither_damage"), KilledByWither.class);
}
@Override
public void serialize(JsonObject json, KilledByWither value, JsonSerializationContext context) {
json.addProperty("invert", value.invert);
}
@Override
public KilledByWither deserialize(JsonObject json, JsonDeserializationContext context) {
return new KilledByWither(JsonUtils.getBoolean(json, "invert"));
}
}
}