Skip to content

Commit

Permalink
Merge branch 'Winds-Studio:ver/1.21.4' into api/async-structure-locate
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH authored Feb 9, 2025
2 parents 27ba6b2 + c4b9d82 commit a805878
Show file tree
Hide file tree
Showing 35 changed files with 196 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
open_collective: Winds-Studio
custom: ["https://afdian.com/a/Dreeam"]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

> [!WARNING]
> Leaf is an **EXPERIMENTAL** fork of [Paper](https://papermc.io/) there MAY BE issues depending on server to server, test and backup servers before switching to it.
> Leaf is a performance-oriented fork. Make sure to take backups **before** switching to it. Everyone is welcome to contribute by optimizing or reporting issues.
## 🍃 Features
- **Based on [Gale](https://github.com/Dreeam-qwq/Gale)** for better performance
Expand All @@ -35,8 +35,7 @@
- QQ Group: `619278377`

## 📫 Donation
If you love my work, feel free to donate :)
- AFDIAN: https://afdian.com/a/Dreeam
If you love our work, feel free to donate via our [Open Collective](https://opencollective.com/Winds-Studio) or [Dreeam's AFDIAN](https://afdian.com/a/Dreeam) :)

## 📥 Download
You can find the latest successful build in [GitHub Action](https://github.com/Winds-Studio/Leaf/actions) or [Releases](https://github.com/Winds-Studio/Leaf/releases)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: TheFloodDragon <[email protected]>
Date: Fri, 7 Feb 2025 18:41:55 +0800
Subject: [PATCH] Hide specified item components


diff --git a/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java b/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
index 828fbe03e7beb860cd0816c7ac8adbffe196533b..f602c4c55483a189f973929b982f1834ca7e9952 100644
--- a/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
@@ -53,8 +53,8 @@ public class ClientboundContainerSetContentPacket implements Packet<ClientGamePa
private void write(RegistryFriendlyByteBuf buffer) {
buffer.writeContainerId(this.containerId);
buffer.writeVarInt(this.stateId);
- ItemStack.OPTIONAL_LIST_STREAM_CODEC.encode(buffer, this.items);
- ItemStack.OPTIONAL_STREAM_CODEC.encode(buffer, this.carriedItem);
+ ItemStack.OPTIONAL_LIST_STREAM_CODEC.encode(buffer, org.dreeam.leaf.util.item.ItemStackStripper.strip(this.items, true)); // Leaf - Hide specified item components
+ ItemStack.OPTIONAL_STREAM_CODEC.encode(buffer, org.dreeam.leaf.util.item.ItemStackStripper.strip(this.carriedItem, true)); // Leaf - Hide specified item components
}

@Override
diff --git a/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java b/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
index c1130f596cf3443eeb62eb1b12587172fe0859ee..18590e0b1d94ee3266637c5f3ab65ead4f8fb394 100644
--- a/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
@@ -33,7 +33,7 @@ public class ClientboundContainerSetSlotPacket implements Packet<ClientGamePacke
buffer.writeContainerId(this.containerId);
buffer.writeVarInt(this.stateId);
buffer.writeShort(this.slot);
- ItemStack.OPTIONAL_STREAM_CODEC.encode(buffer, this.itemStack);
+ ItemStack.OPTIONAL_STREAM_CODEC.encode(buffer, org.dreeam.leaf.util.item.ItemStackStripper.strip(this.itemStack, true)); // Leaf - Hide specified item components
}

@Override
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
index 3dcd8df0b395a8fed8bc0cbe0ff78f4ae0056fd3..6033f629ac457472ad10f8e346732a596aea52d9 100644
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
@@ -306,7 +306,7 @@ public abstract class AbstractContainerMenu {

private void synchronizeCarriedToRemote() {
if (!this.suppressRemoteUpdates) {
- if (!ItemStack.matches(this.getCarried(), this.remoteCarried)) {
+ if (!org.dreeam.leaf.util.item.ItemStackStripper.matchesStripped(this.getCarried(), this.remoteCarried)) { // Leaf - Hide specified item components - Avoid some frequent client animations
this.remoteCarried = this.getCarried().copy();
if (this.synchronizer != null) {
this.synchronizer.sendCarriedChange(this, this.remoteCarried);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In non-strict testing, this can give ~20-40% improvement (54MSPT -> 44MSPT),
under 625 villagers situation.

diff --git a/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java b/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..66374b79ade5cd10fa6e1d9187bf6b1112da4827 100644
index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..7f67848eff9f74881e7a9cd56a2e69ec6fd81e44 100644
--- a/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
+++ b/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
@@ -13,6 +13,21 @@ import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;
Expand All @@ -39,7 +39,7 @@ index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..66374b79ade5cd10fa6e1d9187bf6b11
@Override
protected void doTick(ServerLevel level, T entity) {
double attributeValue = entity.getAttributeValue(Attributes.FOLLOW_RANGE);
@@ -20,11 +35,150 @@ public class NearestLivingEntitySensor<T extends LivingEntity> extends Sensor<T>
@@ -20,11 +35,145 @@ public class NearestLivingEntitySensor<T extends LivingEntity> extends Sensor<T>
List<LivingEntity> entitiesOfClass = level.getEntitiesOfClass(
LivingEntity.class, aabb, matchableEntity -> matchableEntity != entity && matchableEntity.isAlive()
);
Expand Down Expand Up @@ -139,12 +139,7 @@ index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..66374b79ade5cd10fa6e1d9187bf6b11
+ }
+ double invMaxDist = 1.0 / maxDist;
+
+ for (int i = 0; i < NUM_BUCKETS; i++) {
+ buckets[i] = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
+ }
+
+ for (int idx = 0; idx < arr.length; idx++) {
+ EntityDistance e = arr[idx];
+ for (EntityDistance e : arr) {
+ int bucketIndex = (int) (e.distance * invMaxDist * NUM_BUCKETS_MINUS_1);
+ buckets[bucketIndex].add(e);
+ }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.dreeam.leaf.config.modules.gameplay;

import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import org.dreeam.leaf.config.ConfigModules;
import org.dreeam.leaf.config.EnumConfigCategory;
import org.dreeam.leaf.config.LeafConfig;

import java.util.ArrayList;
import java.util.List;

/**
* HideItemComponent
*
* @author TheFloodDragon
* @since 2025/2/4 18:30
*/
public class HideItemComponent extends ConfigModules {

public String getBasePath() {
return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".hide-item-component";
}

public static boolean enabled = false;
public static List<DataComponentType<?>> hiddenTypes = List.of();

@Override
public void onLoaded() {
config.addCommentRegionBased(getBasePath(), """
Controls whether specified component information would be sent to clients.
It may break resource packs and mods that rely on the information.
Also, it can avoid some frequent client animations.
Attention: This is not same as Paper's item-obfuscation, we only hide specified component information from player's inventory.""",
"""
控制哪些物品组件信息会被发送至客户端.
可能会导致依赖物品组件的资源包/模组无法正常工作.
可以避免一些客户端动画效果.
注意: 此项与 Paper 的 item-obfuscation 不同, 我们只从玩家背包中隐藏物品指定的组件信息.""");
List<String> list = config.getList(getBasePath() + ".hidden-types", new ArrayList<>(), config.pickStringRegionBased("""
Which type of components will be hidden from clients.
It needs a component type list, incorrect things will not work.""",
"""
被隐藏的物品组件类型列表.
该配置项接受一个物品组件列表, 格式不正确将不会启用."""));
enabled = config.getBoolean(getBasePath() + ".enabled", enabled, config.pickStringRegionBased(
"If enabled, specified item component information from player's inventory will be hided.",
"启用后, 玩家背包内物品的指定组件信息会被隐藏."
));

final List<DataComponentType<?>> types = new ArrayList<>(list.size());

for (String componentType : list) {
BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(componentType)).ifPresentOrElse(
optional -> types.add(optional.value()),
() -> LeafConfig.LOGGER.warn("Unknown component type: {}", componentType)
);
}

hiddenTypes = types;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.dreeam.leaf.util.item;

import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.world.item.ItemStack;
import org.dreeam.leaf.config.modules.gameplay.HideItemComponent;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* ItemStackStripper
*
* @author TheFloodDragon
* @since 2025/2/4 19:04
*/
public class ItemStackStripper {

public static ItemStack strip(final ItemStack itemStack, final boolean copy) {
if (!HideItemComponent.enabled || itemStack.isEmpty() || itemStack.getComponentsPatch().isEmpty())
return itemStack;

final ItemStack copied = copy ? itemStack.copy() : itemStack;

// Remove specified types
for (DataComponentType<?> type : HideItemComponent.hiddenTypes) {
// Only remove, no others
copied.remove(type);
}

return copied;
}

public static List<ItemStack> strip(final List<ItemStack> itemStacks, final boolean copy) {
if (!HideItemComponent.enabled) return itemStacks;

final List<ItemStack> copiedItems = new ArrayList<>();

for (ItemStack itemStack : itemStacks) {
if (itemStack.isEmpty() || itemStack.getComponentsPatch().isEmpty()) {
copiedItems.add(itemStack);
continue;
}

final ItemStack copied = copy ? itemStack.copy() : itemStack;

// Remove specified types
for (DataComponentType<?> type : HideItemComponent.hiddenTypes) {
// Only remove, no others
copied.remove(type);
}

copiedItems.add(copied);
}

return copiedItems;
}

/**
* Check if two ItemStacks are the same after stripping components
*/
public static boolean matchesStripped(ItemStack left, ItemStack right) {
if (HideItemComponent.enabled) {
return left == right || (
left.is(right.getItem()) && left.getCount() == right.getCount() &&
(left.isEmpty() && right.isEmpty() || Objects.equals(strip(left.getComponents()), strip(right.getComponents())))
);
}

return ItemStack.matches(left, right);
}

/**
* @return a new DataComponentMap with all hidden components removed
*/
private static DataComponentMap strip(final DataComponentMap map) {
return map.filter(c -> !HideItemComponent.hiddenTypes.contains(c));
}
}

0 comments on commit a805878

Please sign in to comment.