use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class GearData method hasPartOfType.
/**
* Check if the gear item has at least one part of the given type.
*
* @param stack The gear item
* @param type The part type
* @return True if and only if the construction parts include a part of the given type
*/
public static boolean hasPartOfType(ItemStack stack, PartType type) {
CompoundTag tags = getData(stack, NBT_ROOT_CONSTRUCTION);
ListTag tagList = tags.getList(NBT_CONSTRUCTION_PARTS, Tag.TAG_COMPOUND);
for (int i = 0; i < tagList.size(); ++i) {
CompoundTag nbt = tagList.getCompound(i);
String key = nbt.getString("ID");
IGearPart part = PartManager.get(key);
if (part != null && part.getType() == type) {
return true;
}
}
return false;
}
use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class GearGenerator method randomizeParts.
public static ItemStack randomizeParts(ItemStack stack, int tier) {
if (!(stack.getItem() instanceof ICoreItem)) {
throw new RuntimeException("Called GearGenerator.randomizeParts on non-gear");
}
ICoreItem item = (ICoreItem) stack.getItem();
GearType gearType = item.getGearType();
PartDataList parts = PartDataList.of();
for (PartType partType : item.getRequiredParts()) {
getRandomPart(gearType, partType, tier).ifPresent(parts::add);
}
if (parts.isEmpty()) {
return ItemStack.EMPTY;
}
ItemStack result = stack.copy();
parts.forEach(p -> p.onAddToGear(result));
GearData.writeConstructionParts(result, parts);
// Apply some random upgrades?
if (item instanceof ICoreTool && tier > 1 && SilentGear.RANDOM.nextFloat() < 0.2f * tier + 0.1f) {
getRandomPart(gearType, PartType.TIP, tier).ifPresent(part -> GearData.addUpgradePart(result, part));
}
GearData.recalculateStats(result, null);
return result;
}
use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class GearHelper method getExamplePartsFromRecipe.
public static Collection<IPartData> getExamplePartsFromRecipe(GearType gearType, Iterable<Ingredient> ingredients) {
Map<PartType, IPartData> map = new LinkedHashMap<>();
PartType.MAIN.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(PartType.MAIN, p));
for (Ingredient ingredient : ingredients) {
if (ingredient instanceof IGearIngredient) {
PartType type = ((IGearIngredient) ingredient).getPartType();
type.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(type, p));
}
}
return map.values();
}
use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class GearHelper method createSampleItem.
private static ItemStack createSampleItem(ICoreItem item, int tier) {
ItemStack result = GearGenerator.create(item, tier);
if (result.isEmpty()) {
Collection<IPartData> parts = new ArrayList<>();
for (PartType partType : item.getRequiredParts()) {
partType.makeCompoundPart(item.getGearType(), Const.Materials.EXAMPLE).ifPresent(parts::add);
}
result = item.construct(parts);
}
GearData.setExampleTag(result, true);
return result;
}
use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class SyncMaterialCraftingItemsPacket method decode.
public static SyncMaterialCraftingItemsPacket decode(FriendlyByteBuf buffer) {
SyncMaterialCraftingItemsPacket packet = new SyncMaterialCraftingItemsPacket();
int count = buffer.readVarInt();
for (int i = 0; i < count; ++i) {
packet.craftingItems.put(buffer.readResourceLocation(), Ingredient.fromNetwork(buffer));
}
int subCount = buffer.readVarInt();
for (int i = 0; i < subCount; ++i) {
Map<PartType, Ingredient> map = new HashMap<>();
ResourceLocation id = buffer.readResourceLocation();
int mapCount = buffer.readByte();
for (int j = 0; j < mapCount; ++j) {
PartType type = PartType.get(buffer.readResourceLocation());
Ingredient ingredient = Ingredient.fromNetwork(buffer);
map.put(type, ingredient);
}
packet.partSubs.put(id, map);
}
return packet;
}
Aggregations