-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
158 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/org/mesdag/advjs/configure/RemoveFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.mesdag.advjs.configure; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.mesdag.advjs.AdvJS; | ||
|
||
|
||
public class RemoveFilter { | ||
@Nullable Identifier path; | ||
@Nullable String modid; | ||
@Nullable Item icon; | ||
@Nullable String frame; | ||
@Nullable String parent; | ||
|
||
public static RemoveFilter of(JsonElement jsonElement) { | ||
RemoveFilter filter = new RemoveFilter(); | ||
if (jsonElement.isJsonObject()) { | ||
JsonObject object = jsonElement.getAsJsonObject(); | ||
if (object.has("mod")) { | ||
// TODO if check mod loaded | ||
filter.modid = object.get("mod").getAsString(); | ||
} | ||
|
||
if (object.has("icon")) { | ||
String icon = object.get("icon").getAsString(); | ||
Identifier id = new Identifier(icon); | ||
Item item = Registries.ITEM.containsId(id) ? Registries.ITEM.get(id) : Items.AIR; | ||
if (item != Items.AIR) { | ||
filter.icon = item; | ||
} else { | ||
AdvJS.LOGGER.warn("RemoveFilter: Icon '{}' not found", icon); | ||
} | ||
} | ||
|
||
if (object.has("frame")) { | ||
filter.frame = object.get("frame").getAsString(); | ||
} | ||
|
||
if (object.has("parent")) { | ||
filter.parent = object.get("parent").getAsString(); | ||
} | ||
} else if (jsonElement.isJsonPrimitive()) { | ||
filter.path = new Identifier(jsonElement.getAsString()); | ||
} | ||
|
||
return filter; | ||
} | ||
|
||
public boolean matches(Identifier path, Item icon, String frame, String parent) { | ||
if (this.path != null && !this.path.equals(path)) { | ||
return false; | ||
} else { | ||
boolean flag = this.modid != null || this.icon != null || this.frame != null || this.parent != null; | ||
if (flag && this.modid != null) { | ||
flag = this.modid.equals(path.getNamespace()); | ||
} | ||
if (flag && this.icon != null) { | ||
flag = this.icon == icon; | ||
} | ||
if (flag && this.frame != null) { | ||
flag = this.frame.equals(frame); | ||
} | ||
if (flag && this.parent != null) { | ||
flag = this.parent.equals(parent); | ||
} | ||
return flag; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters