use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class MaterialManager method handleSyncPacket.
public static void handleSyncPacket(SyncMaterialsPacket msg, Supplier<NetworkEvent.Context> ctx) {
synchronized (MATERIALS) {
Map<ResourceLocation, IMaterial> oldMaterials = ImmutableMap.copyOf(MATERIALS);
MATERIALS.clear();
for (IMaterial mat : msg.getMaterials()) {
mat.retainData(oldMaterials.get(mat.getId()));
MATERIALS.put(mat.getId(), mat);
}
SilentGear.LOGGER.info("Read {} materials from server", MATERIALS.size());
}
ctx.get().setPacketHandled(true);
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class TraitsCommand method getMaterialsWithTrait.
private static String getMaterialsWithTrait(ITrait trait) {
StringBuilder str = new StringBuilder();
boolean foundAny = false;
for (IMaterial material : MaterialManager.getValues(false)) {
MaterialInstance instance = MaterialInstance.of(material);
Collection<PartType> typesWithTrait = new ArrayList<>();
for (PartType partType : PartType.getValues()) {
Collection<TraitInstance> traits = instance.getTraits(partType);
for (TraitInstance inst : traits) {
if (inst.getTrait().equals(trait) && material.isVisible(partType)) {
typesWithTrait.add(partType);
break;
}
}
}
if (!typesWithTrait.isEmpty()) {
if (foundAny) {
str.append(", ");
}
foundAny = true;
str.append("**").append(instance.getDisplayName(PartType.MAIN).getString()).append("**").append(" _(").append(typesWithTrait.stream().map(pt -> pt.getDisplayName(0).getString()).collect(Collectors.joining(", "))).append(")_");
}
}
return str.toString();
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class MaterialsCommand method runDumpClient.
public static void runDumpClient(boolean includeChildren) {
Player player = SilentGear.PROXY.getClientPlayer();
if (player == null) {
SilentGear.LOGGER.error("MaterialsCommand#runDumpClient: player is null?");
return;
}
String fileName = "material_export.tsv";
String dirPath = "output/silentgear";
File output = new File(dirPath, fileName);
File directory = output.getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
player.sendMessage(new TextComponent("Could not create directory: " + output.getParent()), Util.NIL_UUID);
return;
}
try (Writer writer = new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UTF_8)) {
StringBuilder builder = new StringBuilder("Pack\tName\tType\tID\tParent\tTraits\tTier\t");
ItemStats.allStatsOrdered().forEach(s -> builder.append(s.getDisplayName().getString()).append("\t"));
writer.write(builder + "\n");
List<PartType> partTypes = new ArrayList<>(PartType.getValues());
partTypes.sort((o1, o2) -> Comparator.comparing(o -> ((PartType) o).getDisplayName(0).getString()).compare(o1, o2));
for (PartType partType : partTypes) {
for (IMaterial material : MaterialManager.getValues()) {
if (includeChildren || getParentId(material).isEmpty()) {
MaterialInstance inst = MaterialInstance.of(material);
if (material.allowedInPart(inst, partType)) {
writer.write(makeTsvLine(inst, partType) + "\n");
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
Component fileNameText = (new TextComponent(output.getAbsolutePath())).withStyle(ChatFormatting.UNDERLINE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, output.getAbsolutePath())));
player.sendMessage(new TextComponent("Wrote materials info to ").append(fileNameText), Util.NIL_UUID);
}
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class GearModel method buildFakeModel.
private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
// This method will display an example tool for items with no data (ie, for advancements)
MaterialInstance mat = MaterialInstance.of(material);
IMaterialDisplay model = mat.getDisplayProperties();
if (!gearType.isArmor()) {
MaterialLayer exampleRod = model.getLayerList(this.gearType, PartType.ROD, mat).getFirstLayer();
if (exampleRod != null) {
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleRod.getTexture(gearType, 0))), rotation, exampleRod.getColor()));
}
}
MaterialLayer exampleMain = model.getLayerList(this.gearType, PartType.MAIN, mat).getFirstLayer();
if (exampleMain != null) {
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(gearType, 0))), rotation, exampleMain.getColor()));
}
if (gearType.matches(GearType.RANGED_WEAPON)) {
MaterialLayer exampleBowstring = model.getLayerList(this.gearType, PartType.CORD, mat).getFirstLayer();
if (exampleBowstring != null) {
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleBowstring.getTexture(gearType, 0))), rotation, exampleBowstring.getColor()));
}
}
}
Aggregations