use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class RepairHandler method onAnvilUpdate.
@SubscribeEvent
public static void onAnvilUpdate(AnvilUpdateEvent event) {
if (event.getLeft().getItem() instanceof ICoreItem) {
MaterialInstance material = MaterialInstance.from(event.getRight());
PartData part = PartData.from(event.getRight());
if (material != null) {
handleGearRepair(event, material);
} else if (part != null && part.get() instanceof UpgradePart) {
handleUpgradeApplication(event, part);
}
}
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class GearData method getStatModifiers.
public static StatModifierMap getStatModifiers(ItemStack stack, ICoreItem item, PartDataList parts) {
GearType gearType = item.getGearType();
StatModifierMap stats = new StatModifierMap();
for (ItemStat stat : ItemStats.allStatsOrderedExcluding(item.getExcludedStats(stack))) {
StatGearKey itemKey = StatGearKey.of(stat, gearType);
for (PartData part : parts) {
for (StatInstance mod : part.getStatModifiers(itemKey, stack)) {
StatInstance modCopy = StatInstance.of(mod.getValue(), mod.getOp(), itemKey);
stats.put(modCopy.getKey(), modCopy);
}
}
}
return stats;
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class GearData method getStat.
public static float getStat(ItemStack stack, IItemStat stat, boolean calculateIfMissing) {
CompoundTag tags = getData(stack, NBT_ROOT_PROPERTIES).getCompound(NBT_STATS);
String key = stat.getStatId().toString();
if (tags.contains(key)) {
return tags.getFloat(key);
}
if (calculateIfMissing) {
// Stat is missing, notify server to recalculate
Level level = SilentGear.PROXY.getClientLevel();
if (level != null && GearHelper.isValidGear(stack) && ((ICoreItem) stack.getItem()).getRelevantStats(stack).contains(stat)) {
SilentGear.LOGGER.debug("Sending recalculate stats packet for item with missing {} stat: {}", stat.getStatId(), stack.getHoverName().getString());
Network.channel.sendToServer(new RecalculateStatsPacket(level, stack, stat));
// Prevent the packet from being spammed...
putStatInNbtIfMissing(stack, stat);
}
}
return stat.getDefaultValue();
}
use of net.silentchaos512.gear.api.item.ICoreItem 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.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class GearHelper method getDisplayName.
public static Component getDisplayName(ItemStack gear) {
PartData part = GearData.getPrimaryPart(gear);
if (part == null)
return new TranslatableComponent(gear.getDescriptionId());
Component partName = part.getMaterialName(gear);
if (TimedEvents.isAprilFools()) {
partName = partName.copy().append(new TextComponent(" & Knuckles"));
}
Component gearName = new TranslatableComponent(gear.getDescriptionId() + ".nameProper", partName);
Component result = gearName;
if (gear.getItem() instanceof ICoreTool) {
ICoreItem item = (ICoreItem) gear.getItem();
if (item.requiresPartOfType(PartType.ROD) && GearData.getPartOfType(gear, PartType.ROD) == null) {
result = new TranslatableComponent(gear.getDescriptionId() + ".noRod", gearName);
} else if (item.requiresPartOfType(PartType.CORD) && GearData.getPartOfType(gear, PartType.CORD) == null) {
result = new TranslatableComponent(gear.getDescriptionId() + ".unstrung", gearName);
}
}
// Prefixes
for (Component t : getNamePrefixes(gear, GearData.getConstructionParts(gear))) {
result = t.copy().append(new TextComponent(" ")).append(result);
}
return result;
}
Aggregations