85 lines
4.8 KiB
Diff
85 lines
4.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: nostalgic853 <yuu8583@proton.me>
|
|
Date: Thu, 20 Oct 2022 10:31:11 +0800
|
|
Subject: [PATCH] Raid optimizations
|
|
|
|
Original code by CaffeineMC, licensed under GNU Lesser General Public License v3.0
|
|
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
index 6a0a1731fd6804eb69d3641213712d31bce085b2..06110d58342d07cf454f1829140855ac762c8b80 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -79,6 +79,7 @@ public class Raid {
|
|
public static final int TICKS_PER_DAY = 24000;
|
|
public static final int DEFAULT_MAX_BAD_OMEN_LEVEL = 5;
|
|
private static final int LOW_MOB_THRESHOLD = 2;
|
|
+ private static final ItemStack CACHED_LEADER_BANNER; // KeYi - cache the banner
|
|
private static final Component RAID_NAME_COMPONENT = Component.translatable("event.minecraft.raid");
|
|
private static final Component VICTORY = Component.translatable("event.minecraft.raid.victory");
|
|
private static final Component DEFEAT = Component.translatable("event.minecraft.raid.defeat");
|
|
@@ -108,6 +109,20 @@ public class Raid {
|
|
private int celebrationTicks;
|
|
private Optional<BlockPos> waveSpawnPos;
|
|
|
|
+ // KeYi start - cache the banner
|
|
+ static {
|
|
+ ItemStack itemstack = new ItemStack(Items.WHITE_BANNER);
|
|
+ CompoundTag nbttagcompound = new CompoundTag();
|
|
+ ListTag nbttaglist = (new BannerPattern.Builder()).addPattern(BannerPatterns.RHOMBUS_MIDDLE, DyeColor.CYAN).addPattern(BannerPatterns.STRIPE_BOTTOM, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.STRIPE_CENTER, DyeColor.GRAY).addPattern(BannerPatterns.BORDER, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.STRIPE_MIDDLE, DyeColor.BLACK).addPattern(BannerPatterns.HALF_HORIZONTAL, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.CIRCLE_MIDDLE, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.BORDER, DyeColor.BLACK).toListTag();
|
|
+
|
|
+ nbttagcompound.put("Patterns", nbttaglist);
|
|
+ BlockItem.setBlockEntityData(itemstack, BlockEntityType.BANNER, nbttagcompound);
|
|
+ itemstack.hideTooltipPart(ItemStack.TooltipPart.ADDITIONAL);
|
|
+ itemstack.setHoverName(Component.translatable("block.minecraft.ominous_banner").withStyle(ChatFormatting.GOLD));
|
|
+ CACHED_LEADER_BANNER = itemstack;
|
|
+ }
|
|
+ // KeYi end
|
|
+
|
|
public Raid(int id, ServerLevel world, BlockPos pos) {
|
|
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
|
|
this.random = RandomSource.create();
|
|
@@ -270,6 +285,13 @@ public class Raid {
|
|
}
|
|
|
|
public void tick() {
|
|
+ // KeYi start - Lithium - ai.raid: reduce updates
|
|
+ if (this.isBarDirty) {
|
|
+ this.raidEvent.setProgress(Mth.clamp(this.getHealthOfLivingRaiders() / this.totalHealth, 0.0F, 1.0F));
|
|
+ this.isBarDirty = false;
|
|
+ }
|
|
+ // KeYi end
|
|
+
|
|
if (!this.isStopped()) {
|
|
if (this.status == Raid.RaidStatus.ONGOING) {
|
|
boolean flag = this.active;
|
|
@@ -625,8 +647,10 @@ public class Raid {
|
|
|
|
}
|
|
|
|
+ private boolean isBarDirty = false; // KeYi - Lithium - ai.raid: reduce updates
|
|
+
|
|
public void updateBossbar() {
|
|
- this.raidEvent.setProgress(Mth.clamp(this.getHealthOfLivingRaiders() / this.totalHealth, 0.0F, 1.0F));
|
|
+ this.isBarDirty = true; // KeYi - Lithium - ai.raid: reduce updates
|
|
}
|
|
|
|
public float getHealthOfLivingRaiders() {
|
|
@@ -678,15 +702,7 @@ public class Raid {
|
|
}
|
|
|
|
public static ItemStack getLeaderBannerInstance() {
|
|
- ItemStack itemstack = new ItemStack(Items.WHITE_BANNER);
|
|
- CompoundTag nbttagcompound = new CompoundTag();
|
|
- ListTag nbttaglist = (new BannerPattern.Builder()).addPattern(BannerPatterns.RHOMBUS_MIDDLE, DyeColor.CYAN).addPattern(BannerPatterns.STRIPE_BOTTOM, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.STRIPE_CENTER, DyeColor.GRAY).addPattern(BannerPatterns.BORDER, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.STRIPE_MIDDLE, DyeColor.BLACK).addPattern(BannerPatterns.HALF_HORIZONTAL, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.CIRCLE_MIDDLE, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.BORDER, DyeColor.BLACK).toListTag();
|
|
-
|
|
- nbttagcompound.put("Patterns", nbttaglist);
|
|
- BlockItem.setBlockEntityData(itemstack, BlockEntityType.BANNER, nbttagcompound);
|
|
- itemstack.hideTooltipPart(ItemStack.TooltipPart.ADDITIONAL);
|
|
- itemstack.setHoverName(Component.translatable("block.minecraft.ominous_banner").withStyle(ChatFormatting.GOLD));
|
|
- return itemstack;
|
|
+ return CACHED_LEADER_BANNER; // KeYi - cache the banner
|
|
}
|
|
|
|
@Nullable
|