use of net.silentchaos512.gear.gear.part.AbstractGearPart in project Silent-Gear by SilentChaos512.
the class PartManager method onResourceManagerReload.
@Override
public void onResourceManagerReload(ResourceManager resourceManager) {
Gson gson = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
Collection<ResourceLocation> resources = getAllResources(resourceManager);
if (resources.isEmpty())
return;
synchronized (MAP) {
MAP.clear();
ERROR_LIST.clear();
SilentGear.LOGGER.info(MARKER, "Reloading part files");
for (ResourceLocation id : resources) {
String path = id.getPath().substring(DATA_PATH.length() + 1, id.getPath().length() - ".json".length());
ResourceLocation name = new ResourceLocation(id.getNamespace(), path);
String packName = "ERROR";
try (Resource iresource = resourceManager.getResource(id)) {
packName = iresource.getSourceName();
if (SilentGear.LOGGER.isTraceEnabled()) {
SilentGear.LOGGER.trace(MARKER, "Found likely part file: {}, trying to read as part {}", id, name);
}
JsonObject json = GsonHelper.fromJson(gson, IOUtils.toString(iresource.getInputStream(), StandardCharsets.UTF_8), JsonObject.class);
if (json == null) {
SilentGear.LOGGER.error(MARKER, "Could not load part {} as it's null or empty", name);
} else if (!CraftingHelper.processConditions(json, "conditions")) {
SilentGear.LOGGER.info("Skipping loading gear part {} as it's conditions were not met", name);
} else {
IGearPart part = PartSerializers.deserialize(name, json);
if (part instanceof AbstractGearPart) {
((AbstractGearPart) part).packName = iresource.getSourceName();
}
addPart(part);
highestMainPartTier = Math.max(highestMainPartTier, part.getTier());
}
} catch (IllegalArgumentException | JsonParseException ex) {
SilentGear.LOGGER.error(MARKER, "Parsing error loading gear part {}", name, ex);
ERROR_LIST.add(String.format("%s (%s)", name, packName));
} catch (IOException ex) {
SilentGear.LOGGER.error(MARKER, "Could not read gear part {}", name, ex);
ERROR_LIST.add(String.format("%s (%s)", name, packName));
}
}
SilentGear.LOGGER.info(MARKER, "Registered {} parts", MAP.size());
}
}
use of net.silentchaos512.gear.gear.part.AbstractGearPart in project Silent-Gear by SilentChaos512.
the class TooltipHandler method onPartTooltip.
private static void onPartTooltip(ItemTooltipEvent event, ItemStack stack, PartData part) {
if (event.getFlags().isAdvanced() && KeyTracker.isControlDown()) {
event.getToolTip().add(new TextComponent("* Part ID: " + part.getId()).withStyle(ChatFormatting.DARK_GRAY));
event.getToolTip().add(new TextComponent("* Part data pack: " + part.get().getPackName()).withStyle(ChatFormatting.DARK_GRAY));
}
if (!Config.Client.showPartTooltips.get()) {
return;
}
// Type, tier
event.getToolTip().add(TextUtil.withColor(part.getType().getDisplayName(part.getTier()), Color.AQUAMARINE));
// Traits
List<TraitInstance> traits = new ArrayList<>();
for (TraitInstance traitInstance : part.getTraits()) {
if (traitInstance.getTrait().showInTooltip(event.getFlags())) {
traits.add(traitInstance);
}
}
int numTraits = traits.size();
int traitIndex = getTraitDisplayIndex(numTraits);
int i = 0;
for (TraitInstance inst : traits) {
if (traitIndex < 0 || traitIndex == i) {
inst.addInformation(event.getToolTip(), event.getFlags());
}
++i;
}
// Stats
if (KeyTracker.isControlDown()) {
event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.stats").withStyle(ChatFormatting.GOLD).append(new TextComponent(" (Silent Gear)").withStyle(ChatFormatting.RESET).withStyle(ChatFormatting.ITALIC)));
getPartStatLines(event, stack, part);
} else {
event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.ctrlForStats").withStyle(ChatFormatting.GOLD));
}
// Gear type blacklist?
if (part.get() instanceof AbstractGearPart) {
List<GearType> blacklist = ((AbstractGearPart) part.get()).getBlacklistedGearTypes();
if (!blacklist.isEmpty()) {
int index = (ClientTicks.ticksInGame() / 20) % blacklist.size();
GearType gearType = blacklist.get(index);
Component blacklistedType = gearType.getDisplayName();
event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.blacklist", blacklistedType).withStyle(ChatFormatting.RED));
}
}
}
use of net.silentchaos512.gear.gear.part.AbstractGearPart in project Silent-Gear by SilentChaos512.
the class SyncGearCraftingItemsPacket method handle.
public void handle(Supplier<NetworkEvent.Context> context) {
SilentGear.LOGGER.debug("Correcting part crafting items");
this.craftingItems.forEach((id, ingredient) -> {
IGearPart part = PartManager.get(id);
if (part instanceof AbstractGearPart) {
((AbstractGearPart) part).updateCraftingItems(ingredient);
}
});
context.get().setPacketHandled(true);
}
Aggregations