use of net.minecraft.world.level.storage.loot.predicates.LootItemCondition in project MinecraftForge by MinecraftForge.
the class LootModifierManager method deserializeModifier.
private IGlobalLootModifier deserializeModifier(ResourceLocation location, JsonElement element) {
if (!element.isJsonObject())
return null;
JsonObject object = element.getAsJsonObject();
LootItemCondition[] lootConditions = GSON_INSTANCE.fromJson(object.get("conditions"), LootItemCondition[].class);
ResourceLocation serializer = new ResourceLocation(GsonHelper.getAsString(object, "type"));
return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(serializer).read(location, object, lootConditions);
}
use of net.minecraft.world.level.storage.loot.predicates.LootItemCondition in project MinecraftForge by MinecraftForge.
the class ForgeLootTableProvider method findAndReplaceInLootPool.
private boolean findAndReplaceInLootPool(LootPool lootPool, Item from, ToolAction toolAction) {
LootPoolEntryContainer[] lootEntries = ObfuscationReflectionHelper.getPrivateValue(LootPool.class, lootPool, "f_7902" + "3_");
LootItemCondition[] lootConditions = ObfuscationReflectionHelper.getPrivateValue(LootPool.class, lootPool, "f_7902" + "4_");
boolean found = false;
if (lootEntries == null) {
throw new IllegalStateException(LootPool.class.getName() + " is missing field f_7902" + "3_");
}
for (LootPoolEntryContainer lootEntry : lootEntries) {
if (findAndReplaceInLootEntry(lootEntry, from, toolAction)) {
found = true;
}
if (lootEntry instanceof CompositeEntryBase) {
if (findAndReplaceInParentedLootEntry((CompositeEntryBase) lootEntry, from, toolAction)) {
found = true;
}
}
}
if (lootConditions == null) {
throw new IllegalStateException(LootPool.class.getName() + " is missing field f_7902" + "4_");
}
for (int i = 0; i < lootConditions.length; i++) {
LootItemCondition lootCondition = lootConditions[i];
if (lootCondition instanceof MatchTool && checkMatchTool((MatchTool) lootCondition, from)) {
lootConditions[i] = CanToolPerformAction.canToolPerformAction(toolAction).build();
found = true;
} else if (lootCondition instanceof InvertedLootItemCondition) {
LootItemCondition invLootCondition = ObfuscationReflectionHelper.getPrivateValue(InvertedLootItemCondition.class, (InvertedLootItemCondition) lootCondition, "f_8168" + "1_");
if (invLootCondition instanceof MatchTool && checkMatchTool((MatchTool) invLootCondition, from)) {
lootConditions[i] = InvertedLootItemCondition.invert(CanToolPerformAction.canToolPerformAction(toolAction)).build();
found = true;
} else if (invLootCondition instanceof AlternativeLootItemCondition && findAndReplaceInAlternative((AlternativeLootItemCondition) invLootCondition, from, toolAction)) {
found = true;
}
}
}
return found;
}
Aggregations