use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.
the class TooltipDescriptionHandler method renderState.
private static void renderState(ItemStack stack, List<ITextComponent> tooltip, PlayerEntity player) {
if (player == null || stack == null)
return;
Item item = stack.getItem();
if (item instanceof IRepairableItem) {
if (DurabilityUtils.isBroken(stack))
tooltip.add((new StringTextComponent("▶ ").withStyle(TextFormatting.GOLD)).append((new TranslationTextComponent("tooltip.relics.relic.broken")).withStyle(TextFormatting.YELLOW)));
else if (stack.getDamageValue() >= stack.getMaxDamage() * 0.1F)
tooltip.add((new StringTextComponent("▶ ").withStyle(TextFormatting.GOLD)).append((new TranslationTextComponent("tooltip.relics.relic.damaged")).withStyle(TextFormatting.YELLOW)));
}
for (String tag : CuriosApi.getCuriosHelper().getCurioTags(item)) {
CuriosApi.getCuriosHelper().getCuriosHandler(player).ifPresent(handler -> {
Map<String, ICurioStacksHandler> curios = handler.getCurios();
if (curios.size() == 0)
return;
List<ITextComponent> list = new ArrayList<>();
if (curios.get(tag) == null || curios.get(tag).getSlots() > 0)
return;
for (Item curio : ItemRegistry.getSlotModifiers()) {
RelicItem<?> relic = (RelicItem<?>) curio;
for (Pair<String, Integer> pair : relic.getSlotModifiers(stack).getModifiers()) {
String identifier = pair.getLeft();
int amount = pair.getRight();
if (identifier.equals(tag) && amount > 0)
list.add((new StringTextComponent(" ◆ ").withStyle(TextFormatting.YELLOW)).append(new StringTextComponent(new ItemStack(curio).getHoverName().getString()).withStyle(TextFormatting.GREEN)).append((new StringTextComponent(String.format(" [+%d]", amount)).withStyle(TextFormatting.WHITE))));
}
}
StringTextComponent info = new StringTextComponent("");
info.append((new StringTextComponent("▶ ").withStyle(TextFormatting.GOLD)).append((new TranslationTextComponent("tooltip.relics.relic.requires_slot")).withStyle(TextFormatting.YELLOW)).append(" ").append((new TranslationTextComponent("curios.identifier." + tag).withStyle(TextFormatting.GREEN))));
if (!list.isEmpty())
info.append(". ").withStyle(TextFormatting.YELLOW).append(new TranslationTextComponent("tooltip.relics.relic.allowed_modifiers").withStyle(TextFormatting.YELLOW));
tooltip.add(info);
if (!list.isEmpty())
tooltip.addAll(list);
});
}
}
use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.
the class TooltipDescriptionHandler method getAbilitiesTooltip.
private static List<ITextComponent> getAbilitiesTooltip(ItemStack stack) {
List<ITextComponent> tooltip = new ArrayList<>();
if (!(stack.getItem() instanceof RelicItem))
return tooltip;
RelicItem<?> relic = (RelicItem<?>) stack.getItem();
RelicTooltip data = relic.getTooltip(stack);
if (data == null)
return tooltip;
List<AbilityTooltip> abilities = data.getAbilities();
if (abilities.isEmpty())
return tooltip;
for (int i = 0; i < abilities.size(); i++) {
AbilityTooltip ability = abilities.get(i);
String path = "tooltip." + Reference.MODID + "." + Objects.requireNonNull(relic.getRegistryName()).getPath() + ".ability." + (i + 1) + ".";
String key = ability.getKeybinding();
tooltip.add((new StringTextComponent(" ◆ ").withStyle(ability.isNegative() ? TextFormatting.RED : TextFormatting.GREEN)).append((new TranslationTextComponent(path + "name")).withStyle(TextFormatting.YELLOW)).append((new StringTextComponent(key == null ? "" : String.format(" [%s]", key)).withStyle(TextFormatting.DARK_GRAY))).append((new StringTextComponent(" - ").withStyle(TextFormatting.WHITE))).append(new TranslationTextComponent(path + "description", ability.getArgs().toArray(new Object[0])).withStyle(TextFormatting.GRAY)));
}
return tooltip;
}
use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.
the class HUDEventHandler method onEntityUpdate.
@SubscribeEvent
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
if (!(event.getEntityLiving() instanceof PlayerEntity))
return;
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
if (!player.getCommandSenderWorld().isClientSide() || player.tickCount % 10 != 0)
return;
CuriosApi.getCuriosHelper().getEquippedCurios(player).ifPresent(handler -> {
relics.clear();
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i);
if (!(stack.getItem() instanceof RelicItem))
continue;
RelicItem<?> relic = (RelicItem<?>) stack.getItem();
if (DurabilityUtils.isBroken(stack) || !relic.getData().hasAbility())
continue;
relics.add(new ImmutablePair<>(stack, i));
}
offset = offset / slots * slots;
if (offset == relics.size())
offset = Math.max(0, offset - 1) / slots * slots;
});
}
use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.
the class HUDEventHandler method onKeyPressed.
@SubscribeEvent
public static void onKeyPressed(InputEvent.KeyInputEvent event) {
ClientPlayerEntity player = Minecraft.getInstance().player;
if (player == null)
return;
if (relics.size() > slots) {
if (HotkeyRegistry.HUD_UP.isDown()) {
animation = 500;
offset = offset - slots;
if (offset < 0)
offset = (relics.size() - 1) / slots * slots;
player.getCommandSenderWorld().playSound(player, player.blockPosition(), SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 1.0F, 1.0F);
} else if (HotkeyRegistry.HUD_DOWN.isDown()) {
animation = 500;
offset = offset + slots;
if (offset >= relics.size())
offset = 0;
player.getCommandSenderWorld().playSound(player, player.blockPosition(), SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 1.0F, 1.0F);
}
}
for (int i = 0; i < keyBindings.size(); i++) {
KeyBinding key = keyBindings.get(i);
if (!key.isDown())
continue;
animation = 500;
int id = i + offset;
if (id >= relics.size())
continue;
ImmutablePair<ItemStack, Integer> pair = relics.get(i + offset);
ItemStack stack = pair.getLeft();
if (!(stack.getItem() instanceof RelicItem))
continue;
RelicItem<?> relic = (RelicItem<?>) stack.getItem();
if (!relic.getData().hasAbility())
continue;
NetworkHandler.sendToServer(new PacketRelicAbility(pair.getRight()));
relic.castAbility(player, stack);
}
}
use of it.hurts.sskirillss.relics.items.relics.base.RelicItem in project relics by SSKirillSS.
the class PacketRelicAbility method handle.
public boolean handle(Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
PlayerEntity player = ctx.get().getSender();
if (player == null || !player.isAlive())
return;
CuriosApi.getCuriosHelper().getEquippedCurios(player).ifPresent(handler -> {
ItemStack stack = handler.getStackInSlot(this.slot);
if (stack.isEmpty() || !(stack.getItem() instanceof RelicItem))
return;
RelicItem relic = (RelicItem) stack.getItem();
if (!relic.getData().hasAbility())
return;
relic.castAbility(player, stack);
});
});
return true;
}
Aggregations