Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SubscribeEvent
- public void onItemUse(PlayerInteractEvent.RightClickItem event) {
- PlayerEntity player = event.getPlayer();
- ItemStack stack = event.getItemStack();
- if (!player.level.isClientSide) {
- if (stack.getItem() == Items.WRITTEN_BOOK) {
- if (stack.getTag() != null && stack.getTag().hasUUID("owner")) {
- ServerPlayerEntity players = player.getServer().getPlayerList().getPlayer(stack.getTag().getUUID("owner"));
- if (players != null) {
- players.getCapability(LifeCapability.STATS_CAPABILITY).ifPresent(life -> players.getCapability(TimeCapability.TIME_CAPABILITY).ifPresent(time -> {
- // Creates the books pages.
- ListNBT pages = new ListNBT();
- // Refresh books content.
- stack.getTag().put("pages", pages);
- stack.getTag().remove("resolved");
- if (life.getMaxHealth() >= 2.0F && life.getMaxHealth() <= 6.0F) {
- pages.add(HealthBookUtils.setPages(players, 1));
- } else if (life.getMaxHealth() >= 8.0F && life.getMaxHealth() <= 12.0F) {
- pages.add(HealthBookUtils.setPages(players, 1));
- pages.add(HealthBookUtils.setPages(players, 2));
- } else if (life.getMaxHealth() >= 14.0F && life.getMaxHealth() <= 18.0F) {
- pages.add(HealthBookUtils.setPages(players, 1));
- pages.add(HealthBookUtils.setPages(players, 2));
- pages.add(HealthBookUtils.setPages(players, 3));
- } else if (life.getMaxHealth() >= 20.0F) {
- pages.add(HealthBookUtils.setPages(players, 1));
- pages.add(HealthBookUtils.setPages(players, 2));
- pages.add(HealthBookUtils.setPages(players, 3));
- pages.add(HealthBookUtils.setPages(players, 4));
- }
- }));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement