9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-04 15:41:38 +00:00

字体字符id自动分配

This commit is contained in:
XiaoMoMi
2025-09-29 00:26:57 +08:00
parent 7d24430a40
commit 5c06d8af13
53 changed files with 676 additions and 574 deletions

View File

@@ -13,7 +13,7 @@ import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.ItemBuildContext;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ReflectionUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -42,7 +42,7 @@ public class MythicItemDrop extends ItemDrop implements IItemDrop {
context = ItemBuildContext.of(player);
}
}
int amountInt = MCUtils.fastFloor(amount + 0.5F);
int amountInt = MiscUtils.fastFloor(amount + 0.5F);
ItemStack itemStack = this.customItem.buildItemStack(context, amountInt);
return adapt(itemStack).amount(amountInt);
}

View File

@@ -362,7 +362,7 @@ public final class BukkitBlockManager extends AbstractBlockManager {
// 注册服务端侧的真实方块
private void registerServerSideCustomBlocks(int count) {
// 这个会影响全局调色盘
if (MCUtils.ceilLog2(this.vanillaBlockStateCount + count) == MCUtils.ceilLog2(this.vanillaBlockStateCount)) {
if (MiscUtils.ceilLog2(this.vanillaBlockStateCount + count) == MiscUtils.ceilLog2(this.vanillaBlockStateCount)) {
PalettedContainer.NEED_DOWNGRADE = false;
}
try {

View File

@@ -20,7 +20,7 @@ import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
import net.momirealms.craftengine.core.sound.SoundData;
import net.momirealms.craftengine.core.util.AdventureHelper;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.BlockPos;
import net.momirealms.craftengine.core.world.CEWorld;
@@ -166,7 +166,7 @@ public class SimpleStorageBlockBehavior extends BukkitBlockBehavior implements E
}
}
signal /= (float) inventory.getSize();
return MCUtils.lerpDiscrete(signal, 0, 15);
return MiscUtils.lerpDiscrete(signal, 0, 15);
}
}
return 0;
@@ -194,7 +194,7 @@ public class SimpleStorageBlockBehavior extends BukkitBlockBehavior implements E
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
String title = arguments.getOrDefault("title", "").toString();
int rows = MCUtils.clamp(ResourceConfigUtils.getAsInt(arguments.getOrDefault("rows", 1), "rows"), 1, 6);
int rows = MiscUtils.clamp(ResourceConfigUtils.getAsInt(arguments.getOrDefault("rows", 1), "rows"), 1, 6);
Map<String, Object> sounds = (Map<String, Object>) arguments.get("sounds");
boolean hasAnalogOutputSignal = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("has-signal", true), "has-signal");
SoundData openSound = null;

View File

@@ -171,7 +171,7 @@ public class ShulkerHitBox extends AbstractHitBox {
}
private static float getPhysicalPeek(float peek) {
return 0.5F - MCUtils.sin((0.5F + peek) * 3.1415927F) * 0.5F;
return 0.5F - MiscUtils.sin((0.5F + peek) * 3.1415927F) * 0.5F;
}
public boolean interactionEntity() {

View File

@@ -17,7 +17,6 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.block.UpdateOption;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -119,7 +118,7 @@ public class DebugStickListener implements Listener {
}
private static <T> T getRelative(Iterable<T> elements, @Nullable T current, boolean inverse) {
return inverse ? MCUtils.findPreviousInIterable(elements, current) : MCUtils.findNextInIterable(elements, current);
return inverse ? MiscUtils.findPreviousInIterable(elements, current) : MiscUtils.findNextInIterable(elements, current);
}
private static <T extends Comparable<T>> String getNameHelper(ImmutableBlockState state, Property<T> property) {

View File

@@ -474,9 +474,9 @@ public class ItemEventListener implements Listener {
if (foodData == null) return;
event.setCancelled(true);
int oldFoodLevel = player.getFoodLevel();
if (foodData.nutrition() != 0) player.setFoodLevel(MCUtils.clamp(oldFoodLevel + foodData.nutrition(), 0, 20));
if (foodData.nutrition() != 0) player.setFoodLevel(MiscUtils.clamp(oldFoodLevel + foodData.nutrition(), 0, 20));
float oldSaturation = player.getSaturation();
if (foodData.saturation() != 0) player.setSaturation(MCUtils.clamp(oldSaturation, 0, 10));
if (foodData.saturation() != 0) player.setSaturation(MiscUtils.clamp(oldSaturation, 0, 10));
}
private boolean cancelEventIfHasInteraction(PlayerInteractEvent event, BukkitServerPlayer player, InteractionHand hand) {

View File

@@ -12,7 +12,6 @@ import net.momirealms.craftengine.bukkit.util.InventoryUtils;
import net.momirealms.craftengine.bukkit.util.LegacyInventoryUtils;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.gui.*;
import net.momirealms.craftengine.core.util.ReflectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -23,11 +22,9 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.MenuType;
public class BukkitGuiManager implements GuiManager, Listener {
private static final boolean useNewOpenInventory = ReflectionUtils.getDeclaredMethod(InventoryView.class, void.class, new String[]{"open"}) != null;
// private static final boolean useNewOpenInventory = ReflectionUtils.getDeclaredMethod(InventoryView.class, void.class, new String[]{"open"}) != null;
private static BukkitGuiManager instance;
private final BukkitCraftEngine plugin;
@@ -46,21 +43,21 @@ public class BukkitGuiManager implements GuiManager, Listener {
HandlerList.unregisterAll(this);
}
@SuppressWarnings("UnstableApiUsage")
// @SuppressWarnings("UnstableApiUsage")
@Override
public void openInventory(net.momirealms.craftengine.core.entity.player.Player player, GuiType guiType) {
Player bukkitPlayer = (Player) player.platformPlayer();
if (useNewOpenInventory) {
switch (guiType) {
case ANVIL -> MenuType.ANVIL.create(bukkitPlayer).open();
case LOOM -> MenuType.LOOM.create(bukkitPlayer).open();
case ENCHANTMENT -> MenuType.ENCHANTMENT.create(bukkitPlayer).open();
case CRAFTING -> MenuType.CRAFTING.create(bukkitPlayer).open();
case CARTOGRAPHY -> MenuType.CARTOGRAPHY_TABLE.create(bukkitPlayer).open();
case SMITHING -> MenuType.SMITHING.create(bukkitPlayer).open();
case GRINDSTONE -> MenuType.GRINDSTONE.create(bukkitPlayer).open();
}
} else {
// if (useNewOpenInventory) {
// switch (guiType) {
// case ANVIL -> MenuType.ANVIL.create(bukkitPlayer).open();
// case LOOM -> MenuType.LOOM.create(bukkitPlayer).open();
// case ENCHANTMENT -> MenuType.ENCHANTMENT.create(bukkitPlayer).open();
// case CRAFTING -> MenuType.CRAFTING.create(bukkitPlayer).open();
// case CARTOGRAPHY -> MenuType.CARTOGRAPHY_TABLE.create(bukkitPlayer).open();
// case SMITHING -> MenuType.SMITHING.create(bukkitPlayer).open();
// case GRINDSTONE -> MenuType.GRINDSTONE.create(bukkitPlayer).open();
// }
// } else {
switch (guiType) {
case ANVIL -> LegacyInventoryUtils.openAnvil(bukkitPlayer);
case LOOM -> LegacyInventoryUtils.openLoom(bukkitPlayer);
@@ -70,7 +67,7 @@ public class BukkitGuiManager implements GuiManager, Listener {
case ENCHANTMENT -> LegacyInventoryUtils.openEnchanting(bukkitPlayer);
case CARTOGRAPHY -> LegacyInventoryUtils.openCartographyTable(bukkitPlayer);
}
}
// }
}
@Override

View File

@@ -16,7 +16,7 @@ import net.momirealms.craftengine.core.plugin.network.EntityPacketHandler;
import net.momirealms.craftengine.core.plugin.network.NMSPacketEvent;
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.Vec3d;
import org.bukkit.inventory.ItemStack;
@@ -89,8 +89,8 @@ public class ProjectilePacketHandler implements EntityPacketHandler {
buf.writeDouble(y);
buf.writeDouble(z);
if (VersionHelper.isOrAbove1_21_9()) buf.writeLpVec3(movement);
buf.writeByte(MCUtils.packDegrees(MCUtils.clamp(-MCUtils.unpackDegrees(xRot), -90.0F, 90.0F)));
buf.writeByte(MCUtils.packDegrees(-MCUtils.unpackDegrees(yRot)));
buf.writeByte(MiscUtils.packDegrees(MiscUtils.clamp(-MiscUtils.unpackDegrees(xRot), -90.0F, 90.0F)));
buf.writeByte(MiscUtils.packDegrees(-MiscUtils.unpackDegrees(yRot)));
buf.writeByte(yHeadRot);
buf.writeVarInt(data);
if (!VersionHelper.isOrAbove1_21_9()) buf.writeShort(xa);
@@ -142,12 +142,12 @@ public class ProjectilePacketHandler implements EntityPacketHandler {
short xa = FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$xa(packet);
short ya = FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$ya(packet);
short za = FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$za(packet);
float xRot = MCUtils.unpackDegrees(FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$xRot(packet));
float yRot = MCUtils.unpackDegrees(FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$yRot(packet));
float xRot = MiscUtils.unpackDegrees(FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$xRot(packet));
float yRot = MiscUtils.unpackDegrees(FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$yRot(packet));
boolean onGround = FastNMS.INSTANCE.field$ClientboundMoveEntityPacket$onGround(packet);
return FastNMS.INSTANCE.constructor$ClientboundMoveEntityPacket$PosRot(
entityId, xa, ya, za,
MCUtils.packDegrees(-yRot), MCUtils.packDegrees(MCUtils.clamp(-xRot, -90.0F, 90.0F)),
MiscUtils.packDegrees(-yRot), MiscUtils.packDegrees(MiscUtils.clamp(-xRot, -90.0F, 90.0F)),
onGround
);
}

View File

@@ -175,7 +175,7 @@ equipment:
block:
# This decides the amount of real blocks on serverside. Requires a restart to apply.
serverside-blocks: 2000
serverside-blocks: 2025
# Enables the sound system, which prevents the client from hearing some non-custom block sounds and improves the client experience.
sound-system:
enable: true
@@ -232,12 +232,17 @@ image:
chat: true
command: true
sign: true
# Decided the starting value for automatic codepoint assignment.
codepoint-starting-value:
default: 19968
overrides:
minecraft:default: 57344 # 57344 ~ 63743 (U+E000 ~ U+F8FF)
# Defines Unicode characters used for <shift:xxx> positioning
# - Must match the font defined in resource packs
# - Do NOT modify unless you understand text rendering mechanics
offset-characters:
font: minecraft:offset_chars
font: minecraft:default
-1: '\uf800'
-2: '\uf801'
-3: '\uf802'

View File

@@ -122,8 +122,4 @@ images:
ascent: 9
font: minecraft:emoji
file: minecraft:font/image/emojis.png
chars:
- \ub000\ub001\ub002\ub003
- \ub004\ub005\ub006\ub007
- \ub008\ub009\ub00a\ub00b
- \ub00c\ub00d\ub00e\ub00f
grid-size: 4,4

View File

@@ -4,73 +4,61 @@ images:
ascent: 18
font: minecraft:gui
file: minecraft:font/gui/custom/item_browser.png
char: \ub000
internal:category:
height: 140
ascent: 18
font: minecraft:gui
file: minecraft:font/gui/custom/category.png
char: \ub001
internal:crafting_recipe:
height: 142
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/crafting_recipe.png
char: \ub002
internal:cooking_recipe:
height: 138
ascent: 16
font: minecraft:gui
file: minecraft:font/gui/custom/cooking_recipe.png
char: \ub003
internal:smelting:
height: 23
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/smelting.png
char: \ub004
internal:smoking:
height: 23
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/smoking.png
char: \ub005
internal:blasting:
height: 23
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/blasting.png
char: \ub006
internal:campfire:
height: 23
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/campfire.png
char: \ub007
internal:stonecutting_recipe:
height: 142
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/stonecutting_recipe.png
char: \ub008
internal:smithing_transform_recipe:
height: 142
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/smithing_transform_recipe.png
char: \ub009
internal:brewing_recipe:
height: 142
ascent: 20
font: minecraft:gui
file: minecraft:font/gui/custom/brewing_recipe.png
char: \ub00a
internal:no_recipe:
height: 140
ascent: 18
font: minecraft:gui
file: minecraft:font/gui/custom/no_recipe.png
char: \ub00b
templates:
internal:icon/2d:
material: arrow

View File

@@ -2,264 +2,264 @@ images:
internal:neg_1:
height: -3
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf800
internal:neg_2:
height: -4
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf801
internal:neg_3:
height: -5
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf802
internal:neg_4:
height: -6
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf803
internal:neg_5:
height: -7
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf804
internal:neg_6:
height: -8
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf805
internal:neg_7:
height: -9
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf806
internal:neg_8:
height: -10
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf807
internal:neg_9:
height: -11
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf808
internal:neg_10:
height: -12
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf809
internal:neg_11:
height: -13
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf80a
internal:neg_12:
height: -14
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf80b
internal:neg_13:
height: -15
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf80c
internal:neg_14:
height: -16
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf80d
internal:neg_15:
height: -17
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf80e
internal:neg_16:
height: -18
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf80f
internal:neg_24:
height: -26
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf810
internal:neg_32:
height: -34
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf811
internal:neg_48:
height: -50
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf812
internal:neg_64:
height: -66
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf813
internal:neg_128:
height: -130
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf814
internal:neg_256:
height: -258
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf815
internal:pos_1:
height: -1
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf830
internal:pos_2:
height: 1
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf831
internal:pos_3:
height: 2
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf832
internal:pos_4:
height: 3
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf833
internal:pos_5:
height: 4
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf834
internal:pos_6:
height: 5
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf835
internal:pos_7:
height: 6
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf836
internal:pos_8:
height: 7
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf837
internal:pos_9:
height: 8
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf838
internal:pos_10:
height: 9
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf839
internal:pos_11:
height: 10
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf83a
internal:pos_12:
height: 11
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf83b
internal:pos_13:
height: 12
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf83c
internal:pos_14:
height: 13
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf83d
internal:pos_15:
height: 14
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf83e
internal:pos_16:
height: 15
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf83f
internal:pos_24:
height: 23
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf840
internal:pos_32:
height: 31
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf841
internal:pos_48:
height: 47
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf842
internal:pos_64:
height: 63
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf843
internal:pos_128:
height: 127
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf844
internal:pos_256:
height: 255
ascent: -5000
font: minecraft:offset_chars
font: minecraft:default
file: minecraft:font/offset/space_split.png
char: \uf845

View File

@@ -115,7 +115,7 @@ warning.config.image.missing_file: "<yellow>Problem in Datei <arg:0> gefunden -
warning.config.image.invalid_file_chars: "<yellow>Problem in Datei <arg:0> gefunden - Das Image '<arg:1>' hat ein 'file'-Argument '<arg:2>', das ungültige Zeichen enthält. Bitte lies https://minecraft.wiki/w/Resource_location#Legal_characters.</yellow>"
warning.config.image.invalid_font_chars: "<yellow>Problem in Datei <arg:0> gefunden - Das Image '<arg:1>' hat ein 'font'-Argument '<arg:2>', das ungültige Zeichen enthält. Bitte lies https://minecraft.wiki/w/Resource_location#Legal_characters.</yellow>"
warning.config.image.missing_char: "<yellow>Problem in Datei <arg:0> gefunden - Beim Image '<arg:1>' fehlt das erforderliche 'char'-Argument.</yellow>"
warning.config.image.codepoint_conflict: "<yellow>Problem in Datei <arg:0> gefunden - Das Image '<arg:1>' verwendet ein Zeichen '<arg:3>(<arg:4>)' im Font <arg:2>, das bereits von einem anderen Image '<arg:5>' verwendet wird.</yellow>"
warning.config.image.codepoint.conflict: "<yellow>Problem in Datei <arg:0> gefunden - Das Image '<arg:1>' verwendet ein Zeichen '<arg:3>(<arg:4>)' im Font <arg:2>, das bereits von einem anderen Image '<arg:5>' verwendet wird.</yellow>"
warning.config.image.invalid_codepoint_grid: "<yellow>Problem in Datei <arg:0> gefunden - Image '<arg:1>' hat ein ungültiges 'chars' Codepoint-Grid.</yellow>"
warning.config.image.invalid_char: "<yellow>Problem in Datei <arg:0> gefunden - Image '<arg:1>' hat einen char-Parameter, der kombinierende Zeichen enthält, was zur Aufteilung des Bildes führen kann.</yellow>"
warning.config.image.invalid_hex_value: "<yellow>Problem in Datei <arg:0> gefunden - Das Image '<arg:1>' verwendet ein Unicode-Zeichen '<arg:2>', das kein gültiger hexadezimaler (Basis 16) Wert ist.</yellow>"
@@ -407,7 +407,7 @@ warning.config.selector.invalid_target: "<yellow>Problem in Datei <arg:0> gefund
warning.config.resource_pack.item_model.already_exist: "<yellow>Generierung des Item-Models für '<arg:0>' fehlgeschlagen, da die Datei '<arg:1>' bereits existiert.</yellow>"
warning.config.resource_pack.model.generation.already_exist: "<yellow>Generierung des Models fehlgeschlagen, da die Model-Datei '<arg:0>' bereits existiert.</yellow>"
warning.config.resource_pack.generation.missing_font_texture: "<yellow>Beim Font '<arg:0>' fehlt die erforderliche Textur: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>Textur '<arg:0>' ist nicht im Atlas aufgeführt. Du musst den Texturpfad zum Atlas hinzufügen oder die 'obfuscation'-Option in der config.yml aktivieren.</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>Textur '<arg:0>' ist nicht im Atlas aufgeführt. Du musst den Texturpfad zum Atlas hinzufügen oder die 'obfuscation'/'fix-atlas'-Option in der config.yml aktivieren.</yellow>"
warning.config.resource_pack.generation.missing_model_texture: "<yellow>Beim Model '<arg:0>' fehlt die Textur '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_item_model: "<yellow>Beim Item '<arg:0>' fehlt die Model-Datei: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_block_model: "<yellow>Beim Block-State '<arg:0>' fehlt die Model-Datei: '<arg:1>'</yellow>"

View File

@@ -122,8 +122,10 @@ warning.config.image.height_ascent_conflict: "<yellow>Issue found in file <arg:0
warning.config.image.missing_file: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'file' argument.</yellow>"
warning.config.image.invalid_file_chars: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' has a 'file' argument '<arg:2>' that contains illegal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters.</yellow>"
warning.config.image.invalid_font_chars: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' has a 'font' argument '<arg:2>' that contains illegal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters.</yellow>"
warning.config.image.invalid_grid_size: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is using an incorrect grid size format '<arg:2>'. Correct example: '3,5'</yellow>"
warning.config.image.missing_char: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'char' argument.</yellow>"
warning.config.image.codepoint_conflict: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is using a character '<arg:3>(<arg:4>)' in font <arg:2> that has been used by another image '<arg:5>'.</yellow>"
warning.config.image.codepoint.conflict: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is using a character '<arg:3>(<arg:4>)' in font <arg:2> that has been used by another image '<arg:5>'.</yellow>"
warning.config.image.codepoint.exhausted: "<yellow>Issue found in file <arg:0> - Cannot allocate codepoint for image '<arg:1>' as the codepoints have already been exhausted for font '<arg:2>'.</yellow>"
warning.config.image.invalid_codepoint_grid: "<yellow>Issue found in file <arg:0> - Image '<arg:1>' has an invalid 'chars' codepoint grid.</yellow>"
warning.config.image.invalid_char: "<yellow>Issue found in file <arg:0> - Image '<arg:1>' has a char parameter containing combining characters, which may result in image splitting.</yellow>"
warning.config.image.invalid_hex_value: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is using a unicode character '<arg:2>' that is not a valid hexadecimal (radix 16) value.</yellow>"
@@ -193,7 +195,7 @@ warning.config.item.invalid_custom_model_data: "<yellow>Issue found in file <arg
warning.config.item.bad_custom_model_data: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using a custom model data '<arg:2>' that is too large. It's recommended to use a value lower than 16,777,216.</yellow>"
warning.config.item.item_model.conflict: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an invalid 'item-model' option because this item model has been occupied by a vanilla item.</yellow>"
warning.config.item.custom_model_data.conflict: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using a custom model data '<arg:2>' that has been occupied by item '<arg:3>'.</yellow>"
warning.config.item.custom_model_data.exhausted: "<yellow>Issue found in file <arg:0> - Cannot allocate custom model data for item '<arg:1>' as the custom model data has already been exhausted.</yellow>"
warning.config.item.custom_model_data.exhausted: "<yellow>Issue found in file <arg:0> - Cannot allocate custom model data for item '<arg:1>' as the custom model data has already been exhausted for material '<arg:2>'.</yellow>"
warning.config.item.invalid_component: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using a non-existing component type '<arg:2>'.</yellow>"
warning.config.item.missing_model_id: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'custom-model-data' or 'item-model' argument.</yellow>"
warning.config.item.missing_model: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'model' section for 1.21.4+ resource pack support.</yellow>"
@@ -461,7 +463,7 @@ warning.config.resource_pack.generation.missing_item_model: "<yellow>Item '<arg:
warning.config.resource_pack.generation.missing_block_model: "<yellow>Block state '<arg:0>' is missing model file: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_parent_model: "<yellow>Model '<arg:0>' cannot find parent model: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_equipment_texture: "<yellow>Equipment '<arg:0>' is missing texture '<arg:1>'</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>Texture '<arg:0>' is not listed in the atlas. You need to add the texture path to the atlas or enable 'obfuscation' option in config.yml.</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>Texture '<arg:0>' is not listed in the atlas. You need to add the texture path to the atlas or enable 'obfuscation' or 'fix-atlas' option in config.yml.</yellow>"
warning.config.resource_pack.invalid_overlay_format: "<yellow>Issue found in config.yml at 'resource-pack.overlay-format' - Invalid overlay format '<arg:0>'. Overlay format must contain the placeholder '{version}'.</yellow>"
warning.config.equipment.duplicate: "<yellow>Issue found in file <arg:0> - Duplicated equipment '<arg:1>'. Please check if there is the same configuration in other files.</yellow>"
warning.config.equipment.missing_type: "<yellow>Issue found in file <arg:0> - The equipment '<arg:1>' is missing the required 'type' argument.</yellow>"

View File

@@ -77,7 +77,7 @@ warning.config.image.missing_file: "<yellow>Problema encontrado en el archivo <a
warning.config.image.invalid_file_chars: "<yellow>Problema encontrado en el archivo <arg:0> - La imagen '<arg:1>' tiene un argumento 'file' '<arg:2>' que contiene caracteres prohibidos. Por favor lee https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
warning.config.image.invalid_font_chars: "<yellow>Problema encontrado en el archivo <arg:0> - La imagen '<arg:1>' tiene un argumento 'font' '<arg:2>' que contiene caracteres prohibidos. Por favor lee https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
warning.config.image.missing_char: "<yellow>Problema encontrado en el archivo <arg:0> - La imagen '<arg:1>' carece del argumento requerido 'char'.</yellow>"
warning.config.image.codepoint_conflict: "<yellow>Problema encontrado en el archivo <arg:0> - La imagen '<arg:1>' está usando el carácter '<arg:3>(<arg:4>)' que ya ha sido usado por otra imagen '<arg:5>' en la fuente <arg:2>.</yellow>"
warning.config.image.codepoint.conflict: "<yellow>Problema encontrado en el archivo <arg:0> - La imagen '<arg:1>' está usando el carácter '<arg:3>(<arg:4>)' que ya ha sido usado por otra imagen '<arg:5>' en la fuente <arg:2>.</yellow>"
warning.config.image.invalid_codepoint_grid: "<yellow>Problema encontrado en el archivo <arg:0> - La imagen '<arg:1>' tiene una cuadrícula de puntos de código 'chars' inválida.</yellow>"
warning.config.image.file_not_found: "<yellow>Problema encontrado en el archivo <arg:0> - Archivo PNG '<arg:2>' no encontrado para la imagen '<arg:1>'.</yellow>"
warning.config.image.invalid_hex_value: "<yellow>Problema encontrado en el archivo <arg:0> - La imagen '<arg:1>' está usando el carácter unicode '<arg:2>' que no es un valor hexadecimal válido.</yellow>"

View File

@@ -113,7 +113,7 @@ warning.config.image.missing_file: "<yellow>Проблема найдена в
warning.config.image.invalid_file_chars: "<yellow>Проблема найдена в файле <arg:0> - Изображение '<arg:1>' имеет 'file' аргумент '<arg:2>', который содержит недопустимые символы. Пожалуйста, прочтите https://minecraft.wiki/w/Resource_location#Legal_characters.</yellow>"
warning.config.image.invalid_font_chars: "<yellow>Проблема найдена в файле <arg:0> - Изображение'<arg:1>' имеет 'font' аргумент '<arg:2>', который содержит недопустимые символы. Пожалуйста, прочтите https://minecraft.wiki/w/Resource_location#Legal_characters.</yellow>"
warning.config.image.missing_char: "<yellow>Проблема найдена в файле <arg:0> - В изображении '<arg:1>' отсутствует необходимый 'char' аргумент.</yellow>"
warning.config.image.codepoint_conflict: "<yellow>Проблема найдена в файле <arg:0> - Изображение '<arg:1>' использует символ '<arg:3>(<arg:4>)' в шрифте <arg:2> который был использован другим изображением '<arg:5>'.</yellow>"
warning.config.image.codepoint.conflict: "<yellow>Проблема найдена в файле <arg:0> - Изображение '<arg:1>' использует символ '<arg:3>(<arg:4>)' в шрифте <arg:2> который был использован другим изображением '<arg:5>'.</yellow>"
warning.config.image.invalid_codepoint_grid: "<yellow>Проблема найдена в файле <arg:0> - Изображение '<arg:1>' имеет недействительную 'chars' сетку кодовых точек.</yellow>"
warning.config.image.invalid_char: "<yellow>Проблема найдена в файле <arg:0> - Изображение '<arg:1>' имеет параметр char, содержащий комбинированные символы, что может привести к разделению изображения.</yellow>"
warning.config.image.invalid_hex_value: "<yellow>Проблема найдена в файле <arg:0> - Изображение '<arg:1>' использует символ юникода '<arg:2>' это недопустимое шестнадцатеричное (radix 16) значение.</yellow>"
@@ -376,7 +376,7 @@ warning.config.resource_pack.item_model.conflict.vanilla: "<yellow>Не удал
warning.config.resource_pack.item_model.already_exist: "<yellow>Не удалось создать модель элемента для '<arg:0>', потому что файл '<arg:1>' уже существует.</yellow>"
warning.config.resource_pack.model.generation.already_exist: "<yellow>Не удалось создать модель, так как файл модели '<arg:0>' уже существует.</yellow>"
warning.config.resource_pack.generation.missing_font_texture: "<yellow>В шрифте '<arg:0>' отсутствует обязательная текстура: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>Текстура '<arg:0>' не указана в атласе. Вам нужно добавить путь к текстуре в атлас или включить 'obfuscation' опцию в config.yml.</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>Текстура '<arg:0>' не указана в атласе. Вам нужно добавить путь к текстуре в атлас или включить 'obfuscation'/'fix-atlas' опцию в config.yml.</yellow>"
warning.config.resource_pack.generation.missing_model_texture: "<yellow>В модели '<arg:0>' отсутствует текстура '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_item_model: "<yellow>В предмете '<arg:0>' отсутствует файл модели: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_block_model: "<yellow>В блоке '<arg:0>' отсутствует файл модели: '<arg:1>'</yellow>"

View File

@@ -77,7 +77,7 @@ warning.config.image.missing_file: "<yellow><arg:0> dosyasında sorun bulundu -
warning.config.image.invalid_file_chars: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' resmi, yasak karakterler içeren '<arg:2>' 'file' argümanına sahip. Lütfen https://minecraft.wiki/w/Resource_location#Legal_characters sayfasını okuyun.</yellow>"
warning.config.image.invalid_font_chars: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' resmi, yasak karakterler içeren '<arg:2>' 'font' argümanına sahip. Lütfen https://minecraft.wiki/w/Resource_location#Legal_characters sayfasını okuyun.</yellow>"
warning.config.image.missing_char: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' resmi gerekli 'char' argümanı eksik.</yellow>"
warning.config.image.codepoint_conflict: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' resmi, <arg:2> yazı tipinde başka bir resim '<arg:5>' tarafından kullanılmış olan '<arg:3>(<arg:4>)' karakterini kullanıyor.</yellow>"
warning.config.image.codepoint.conflict: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' resmi, <arg:2> yazı tipinde başka bir resim '<arg:5>' tarafından kullanılmış olan '<arg:3>(<arg:4>)' karakterini kullanıyor.</yellow>"
warning.config.image.invalid_codepoint_grid: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' resminin geçersiz bir 'chars' kod noktası ızgarası var.</yellow>"
warning.config.image.invalid_hex_value: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' resmi, geçerli bir onaltılık (16 tabanlı) değer olmayan '<arg:2>' unicode karakterini kullanıyor.</yellow>"
warning.config.recipe.duplicate: "<yellow><arg:0> dosyasında sorun bulundu - Yinelenen tarif '<arg:1>'. Diğer dosyalarda aynı yapılandırmanın olup olmadığını kontrol edin.</yellow>"

View File

@@ -122,8 +122,9 @@ warning.config.image.height_ascent_conflict: "<yellow>在文件 <arg:0> 发现
warning.config.image.missing_file: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 缺少必需的 'file' 参数</yellow>"
warning.config.image.invalid_file_chars: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 的 'file' 参数 '<arg:2>' 包含非法字符 请参考 https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
warning.config.image.invalid_font_chars: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 的 'font' 参数 '<arg:2>' 包含非法字符 请参考 https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
warning.config.image.invalid_grid_size: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 使用了无效的网格尺寸 '<arg:2>'. 正确的格式 '3,5'</yellow>"
warning.config.image.missing_char: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 缺少必需的 'char' 参数</yellow>"
warning.config.image.codepoint_conflict: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 在字体 <arg:2> 中使用的字符 '<arg:3>(<arg:4>)' 已被其他图片 '<arg:5>' 占用</yellow>"
warning.config.image.codepoint.conflict: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 在字体 <arg:2> 中使用的字符 '<arg:3>(<arg:4>)' 已被其他图片 '<arg:5>' 占用</yellow>"
warning.config.image.invalid_codepoint_grid: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 的 'chars' 码位网格无效</yellow>"
warning.config.image.invalid_char: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 的 'char' 参数包含组合字符可能导致图片分裂</yellow>"
warning.config.image.invalid_hex_value: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 使用的 Unicode 字符 '<arg:2>' 不是有效的十六进制值</yellow>"
@@ -443,7 +444,7 @@ warning.config.resource_pack.generation.missing_item_model: "<yellow>物品'<arg
warning.config.resource_pack.generation.missing_block_model: "<yellow>方块状态'<arg:0>'缺少模型文件: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_parent_model: "<yellow>模型'<arg:0>'找不到父级模型文件: '<arg:1>'</yellow>"
warning.config.resource_pack.generation.missing_equipment_texture: "<yellow>装备 '<arg:0>' 缺少纹理 '<arg:1>'</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>纹理'<arg:0>'不在图集内. 你需要将纹理路径或文件夹前缀添加到图集内,或者启用 config.yml 中的 'obfuscation' 选项</yellow>"
warning.config.resource_pack.generation.texture_not_in_atlas: "<yellow>纹理'<arg:0>'不在图集内. 你需要将纹理路径或文件夹前缀添加到图集内,或者启用 config.yml 中的 'obfuscation'/'fix-atlas' 或 'fix-atlas' 选项</yellow>"
warning.config.resource_pack.invalid_overlay_format: "<yellow>在 config.yml 的 'resource-pack.overlay-format' 处发现问题 - 无效的overlay格式 '<arg:0>'. Overlay格式必须包含占位符 '{version}'</yellow>"
warning.config.equipment.duplicate: "<yellow>在文件 <arg:0> 发现问题 - 重复的装备配置 '<arg:1>'。请检查其他文件中是否存在相同配置</yellow>"
warning.config.equipment.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 装备 '<arg:1>' 缺少必需的 'type' 参数</yellow>"

View File

@@ -442,7 +442,7 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
return;
}
} catch (InterruptedException e) {
AbstractBlockManager.this.plugin.logger().warn("Interrupted while parsing allocating internal block state", e);
AbstractBlockManager.this.plugin.logger().warn("Interrupted while allocating internal block state for block " + id.asString(), e);
return;
}
}

View File

@@ -1,6 +1,5 @@
package net.momirealms.craftengine.core.entity.furniture;
import net.momirealms.craftengine.core.block.AbstractBlockManager;
import net.momirealms.craftengine.core.entity.Billboard;
import net.momirealms.craftengine.core.entity.ItemDisplayContext;
import net.momirealms.craftengine.core.loot.LootTable;
@@ -8,7 +7,6 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.pack.PendingConfigSection;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.IdSectionConfigParser;
import net.momirealms.craftengine.core.plugin.context.event.EventFunctions;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
@@ -19,7 +17,6 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.incendo.cloud.suggestion.Suggestion;
import org.joml.Vector3f;
import java.io.IOException;
import java.nio.file.Path;
import java.util.*;

View File

@@ -2,10 +2,13 @@ package net.momirealms.craftengine.core.font;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.AbstractItemManager;
import net.momirealms.craftengine.core.pack.LoadingSequence;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.pack.ResourceLocation;
import net.momirealms.craftengine.core.pack.cache.IdAllocator;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
import net.momirealms.craftengine.core.plugin.config.IdSectionConfigParser;
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
@@ -24,6 +27,8 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -54,6 +59,14 @@ public abstract class AbstractFontManager implements FontManager {
this.emojiParser = new EmojiParser();
}
public ImageParser imageParser() {
return imageParser;
}
public EmojiParser emojiParser() {
return emojiParser;
}
@Override
public void load() {
this.offsetFont = Optional.ofNullable(plugin.config().settings().getSection("image.offset-characters"))
@@ -441,6 +454,7 @@ public abstract class AbstractFontManager implements FontManager {
public class ImageParser implements IdSectionConfigParser {
public static final String[] CONFIG_SECTION_NAME = new String[] {"images", "image"};
private final Map<Key, IdAllocator> idAllocators = new HashMap<>();
@Override
public String[] sectionId() {
@@ -452,9 +466,43 @@ public abstract class AbstractFontManager implements FontManager {
return LoadingSequence.IMAGE;
}
@Override
public void postProcess() {
for (Map.Entry<Key, IdAllocator> entry : this.idAllocators.entrySet()) {
entry.getValue().processPendingAllocations();
try {
entry.getValue().saveToCache();
} catch (IOException e) {
AbstractFontManager.this.plugin.logger().warn("Error while saving codepoint allocation for font " + entry.getKey().asString(), e);
}
}
}
@Override
public void preProcess() {
this.idAllocators.clear();
}
public IdAllocator getOrCreateIdAllocator(Key key) {
return this.idAllocators.computeIfAbsent(key, k -> {
IdAllocator newAllocator = new IdAllocator(plugin.dataFolderPath().resolve("cache").resolve("font").resolve(k.namespace()).resolve(k.value() + ".json"));
newAllocator.reset(Config.codepointStartingValue(k), 1114111); // utf16
try {
newAllocator.loadFromCache();
} catch (IOException e) {
AbstractFontManager.this.plugin.logger().warn("Error while loading chars data from cache for font " + k.asString(), e);
}
return newAllocator;
});
}
public Map<Key, IdAllocator> idAllocators() {
return this.idAllocators;
}
@Override
public void parseSection(Pack pack, Path path, String node, Key id, Map<String, Object> section) {
if (images.containsKey(id)) {
if (AbstractFontManager.this.images.containsKey(id)) {
throw new LocalizedResourceConfigException("warning.config.image.duplicate");
}
@@ -463,119 +511,165 @@ public abstract class AbstractFontManager implements FontManager {
throw new LocalizedResourceConfigException("warning.config.image.missing_file");
}
String resourceLocation = CharacterUtils.replaceBackslashWithSlash(file.toString());
String resourceLocation = MiscUtils.make(CharacterUtils.replaceBackslashWithSlash(file.toString()), s -> s.endsWith(".png") ? s : s + ".png");
if (!ResourceLocation.isValid(resourceLocation)) {
throw new LocalizedResourceConfigException("warning.config.image.invalid_file_chars", resourceLocation);
}
String fontName = section.getOrDefault("font", "minecraft:default").toString();
String fontName = section.getOrDefault("font", pack.namespace()+ ":default").toString();
if (!ResourceLocation.isValid(fontName)) {
throw new LocalizedResourceConfigException("warning.config.image.invalid_font_chars", fontName);
}
Key fontKey = Key.withDefaultNamespace(fontName, id.namespace());
Font font = getOrCreateFont(fontKey);
List<char[]> chars;
Key fontId = Key.withDefaultNamespace(fontName, id.namespace());
Font font = getOrCreateFont(fontId);
IdAllocator allocator = getOrCreateIdAllocator(fontId);
int rows;
int columns;
List<CompletableFuture<Integer>> futureCodepoints = new ArrayList<>();
Object charsObj = ResourceConfigUtils.get(section, "chars", "char");
// 自动分配
if (charsObj == null) {
throw new LocalizedResourceConfigException("warning.config.image.missing_char");
}
if (charsObj instanceof List<?> list) {
chars = MiscUtils.getAsStringList(list).stream().map(it -> {
if (it.startsWith("\\u")) {
return CharacterUtils.decodeUnicodeToChars(it);
} else {
return it.toCharArray();
Object grid = section.get("grid-size");
if (grid != null) {
String gridString = grid.toString();
String[] split = gridString.split(",");
if (split.length != 2) {
throw new LocalizedResourceConfigException("warning.config.image.invalid_grid_size", gridString);
}
}).toList();
if (chars.isEmpty()) {
rows = Integer.parseInt(split[0]);
columns = Integer.parseInt(split[1]);
int chars = rows * columns;
if (chars <= 0) {
throw new LocalizedResourceConfigException("warning.config.image.invalid_grid_size", gridString);
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
futureCodepoints.add(allocator.requestAutoId(id.asString() + ":" + i + ":" + j));
}
}
} else {
rows = 1;
columns = 1;
futureCodepoints.add(allocator.requestAutoId(id.asString()));
}
}
// 使用了list
else if (charsObj instanceof List<?> list) {
List<String> charsList = MiscUtils.getAsStringList(list);
if (charsList.isEmpty() || charsList.getFirst().isEmpty()) {
throw new LocalizedResourceConfigException("warning.config.image.missing_char");
}
} else {
if (charsObj instanceof Integer integer) {
chars = List.of(new char[]{(char) integer.intValue()});
int tempColumns = -1;
rows = charsList.size();
for (int i = 0; i < charsList.size(); i++) {
String charString = charsList.get(i);
int[] codepoints;
if (charString.startsWith("\\u")) {
codepoints = CharacterUtils.charsToCodePoints(CharacterUtils.decodeUnicodeToChars(charString));
} else {
codepoints = CharacterUtils.charsToCodePoints(charString.toCharArray());
}
for (int j = 0; j < codepoints.length; j++) {
futureCodepoints.add(allocator.assignFixedId(id.asString() + ":" + i + ":" + j, codepoints[i]));
}
if (tempColumns == -1) {
tempColumns = codepoints.length;
} else if (tempColumns != codepoints.length) {
throw new LocalizedResourceConfigException("warning.config.image.invalid_codepoint_grid");
}
}
columns = tempColumns;
}
// 使用了具体的值
else {
if (charsObj instanceof Integer codepoint) {
futureCodepoints.add(allocator.assignFixedId(id.asString(), codepoint));
rows = 1;
columns = 1;
} else {
String character = charsObj.toString();
if (character.isEmpty()) {
throw new LocalizedResourceConfigException("warning.config.image.missing_char");
}
if (character.length() == 1) {
chars = List.of(character.toCharArray());
rows = 1;
int[] codepoints;
if (character.startsWith("\\u")) {
codepoints = CharacterUtils.charsToCodePoints(CharacterUtils.decodeUnicodeToChars(character));
} else {
if (character.startsWith("\\u")) {
chars = List.of(CharacterUtils.decodeUnicodeToChars(character));
} else {
// ??? TODO 需要测试特殊字符集
// if (CharacterUtils.containsCombinedCharacter(character)) {
// TranslationManager.instance().log("warning.config.image.invalid_char", path.toString(), id.toString());
// }
chars = List.of(character.toCharArray());
codepoints = CharacterUtils.charsToCodePoints(character.toCharArray());
}
columns = codepoints.length;
for (int i = 0; i < codepoints.length; i++) {
futureCodepoints.add(allocator.assignFixedId(id.asString() + ":0:" + i, codepoints[i]));
}
}
}
CompletableFutures.allOf(futureCodepoints).thenRun(() -> ResourceConfigUtils.runCatching(path, node, () -> {
int[][] codepointGrid = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
try {
int codepoint = futureCodepoints.get(i * columns + j).get();
codepointGrid[i][j] = codepoint;
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof IdAllocator.IdConflictException conflict) {
throw new LocalizedResourceConfigException("warning.config.image.codepoint.conflict",
fontId.toString(),
CharacterUtils.encodeCharsToUnicode(Character.toChars(conflict.id())),
new String(Character.toChars(conflict.id())),
conflict.previousOwner()
);
} else if (cause instanceof IdAllocator.IdExhaustedException) {
throw new LocalizedResourceConfigException("warning.config.image.codepoint.exhausted", fontId.asString());
}
} catch (InterruptedException e) {
AbstractFontManager.this.plugin.logger().warn("Interrupted while allocating codepoint for image " + id.asString(), e);
return;
}
}
}
}
int size = -1;
int[][] codepointGrid = new int[chars.size()][];
for (int i = 0; i < chars.size(); ++i) {
int[] codepoints = CharacterUtils.charsToCodePoints(chars.get(i));
for (int codepoint : codepoints) {
if (font.isCodepointInUse(codepoint)) {
BitmapImage image = font.bitmapImageByCodepoint(codepoint);
throw new LocalizedResourceConfigException("warning.config.image.codepoint_conflict",
fontKey.toString(),
CharacterUtils.encodeCharsToUnicode(Character.toChars(codepoint)),
new String(Character.toChars(codepoint)),
image.id().toString());
Object heightObj = section.get("height");
if (heightObj == null) {
Key namespacedPath = Key.of(resourceLocation);
Path targetImagePath = pack.resourcePackFolder()
.resolve("assets")
.resolve(namespacedPath.namespace())
.resolve("textures")
.resolve(namespacedPath.value());
if (Files.exists(targetImagePath)) {
try (InputStream in = Files.newInputStream(targetImagePath)) {
BufferedImage image = ImageIO.read(in);
heightObj = image.getHeight() / codepointGrid.length;
} catch (IOException e) {
plugin.logger().warn("Failed to load image " + targetImagePath, e);
return;
}
} else {
throw new LocalizedResourceConfigException("warning.config.image.missing_height");
}
}
if (codepoints.length == 0) {
throw new LocalizedResourceConfigException("warning.config.image.missing_char");
}
codepointGrid[i] = codepoints;
if (size == -1) size = codepoints.length;
if (size != codepoints.length) {
throw new LocalizedResourceConfigException("warning.config.image.invalid_codepoint_grid");
}
}
Object heightObj = section.get("height");
if (!resourceLocation.endsWith(".png")) resourceLocation += ".png";
int height = ResourceConfigUtils.getAsInt(heightObj, "height");
int ascent = ResourceConfigUtils.getAsInt(section.getOrDefault("ascent", height - 1), "ascent");
if (height < ascent) {
throw new LocalizedResourceConfigException("warning.config.image.height_ascent_conflict", String.valueOf(height), String.valueOf(ascent));
}
if (heightObj == null) {
Key namespacedPath = Key.of(resourceLocation);
Path targetImagePath = pack.resourcePackFolder()
.resolve("assets")
.resolve(namespacedPath.namespace())
.resolve("textures")
.resolve(namespacedPath.value());
if (Files.exists(targetImagePath)) {
try (InputStream in = Files.newInputStream(targetImagePath)) {
BufferedImage image = ImageIO.read(in);
heightObj = image.getHeight() / codepointGrid.length;
} catch (IOException e) {
plugin.logger().warn("Failed to load image " + targetImagePath, e);
return;
BitmapImage bitmapImage = new BitmapImage(id, fontId, height, ascent, resourceLocation, codepointGrid);
for (int[] y : codepointGrid) {
for (int x : y) {
font.addBitmapImage(x, bitmapImage);
}
} else {
throw new LocalizedResourceConfigException("warning.config.image.missing_height");
}
}
int height = ResourceConfigUtils.getAsInt(heightObj, "height");
int ascent = ResourceConfigUtils.getAsInt(section.getOrDefault("ascent", height - 1), "ascent");
if (height < ascent) {
throw new LocalizedResourceConfigException("warning.config.image.height_ascent_conflict", String.valueOf(height), String.valueOf(ascent));
}
AbstractFontManager.this.images.put(id, bitmapImage);
BitmapImage bitmapImage = new BitmapImage(id, fontKey, height, ascent, resourceLocation, codepointGrid);
for (int[] y : codepointGrid) {
for (int x : y) {
font.addBitmapImage(x, bitmapImage);
}
}
images.put(id, bitmapImage);
}, () -> GsonHelper.get().toJson(section)));
}
}
}

View File

@@ -437,7 +437,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
}
// custom model data 已被用尽,不太可能
else if (throwable instanceof IdAllocator.IdExhaustedException) {
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data.exhausted");
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data.exhausted", clientBoundMaterial.asString());
}
// 未知错误
else {

View File

@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.loot.function.LootFunction;
import net.momirealms.craftengine.core.loot.function.LootFunctions;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.MutableInt;
import net.momirealms.craftengine.core.util.RandomUtils;
@@ -44,7 +44,7 @@ public class LootPool<T> {
}
if (this.compositeCondition.test(context)) {
Consumer<Item<T>> consumer = LootFunction.decorate(this.compositeFunction, lootConsumer, context);
int i = this.rolls.getInt(context) + MCUtils.fastFloor(this.bonusRolls.getFloat(context) * context.luck());
int i = this.rolls.getInt(context) + MiscUtils.fastFloor(this.bonusRolls.getFloat(context) * context.luck());
for (int j = 0; j < i; ++j) {
this.addRandomItem(createFunctionApplier(consumer, context), context);
}

View File

@@ -3,7 +3,7 @@ package net.momirealms.craftengine.core.loot.entry;
import net.momirealms.craftengine.core.loot.LootContext;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.List;
import java.util.function.Predicate;
@@ -14,7 +14,7 @@ public abstract class AbstractLootEntryContainer<T> implements LootEntryContaine
protected AbstractLootEntryContainer(List<Condition<LootContext>> conditions) {
this.conditions = conditions;
this.compositeCondition = MCUtils.allOf(conditions);
this.compositeCondition = MiscUtils.allOf(conditions);
}
@Override

View File

@@ -3,7 +3,7 @@ package net.momirealms.craftengine.core.loot.function;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.loot.LootContext;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.List;
import java.util.function.Predicate;
@@ -14,7 +14,7 @@ public abstract class AbstractLootConditionalFunction<T> implements LootFunction
public AbstractLootConditionalFunction(List<Condition<LootContext>> predicates) {
this.predicates = predicates;
this.compositePredicates = MCUtils.allOf(predicates);
this.compositePredicates = MiscUtils.allOf(predicates);
}
@Override

View File

@@ -320,6 +320,9 @@ public abstract class AbstractPackManager implements PackManager {
if (namespace.charAt(0) == '.') {
continue;
}
if (!ResourceLocation.isValidNamespace(namespace)) {
namespace = "minecraft";
}
Path metaFile = path.resolve("pack.yml");
String description = null;
String version = null;

View File

@@ -137,6 +137,8 @@ public class Config {
protected boolean image$illegal_characters_filter$anvil;
protected boolean image$illegal_characters_filter$sign;
protected boolean image$illegal_characters_filter$book;
protected int image$codepoint_starting_value$default;
protected Map<Key, Integer> image$codepoint_starting_value$overrides;
protected boolean network$intercept_packets$system_chat;
protected boolean network$intercept_packets$tab_list;
@@ -257,6 +259,7 @@ public class Config {
forcedLocale = TranslationManager.parseLocale(config.getString("forced-locale", ""));
}
@SuppressWarnings("DuplicatedCode")
public void loadFullSettings() {
YamlDocument config = settings();
forcedLocale = TranslationManager.parseLocale(config.getString("forced-locale", ""));
@@ -429,7 +432,7 @@ public class Config {
block$extended_interaction_range = Math.max(config.getDouble("block.predict-breaking.extended-interaction-range", 0.5), 0.0);
block$chunk_relighter = config.getBoolean("block.chunk-relighter", true);
if (firstTime) {
block$serverside_blocks = config.getInt("block.serverside-blocks", 2000);
block$serverside_blocks = Math.min(config.getInt("block.serverside-blocks", 2000), 10_0000);
if (block$serverside_blocks < 0) block$serverside_blocks = 0;
}
@@ -445,6 +448,22 @@ public class Config {
image$illegal_characters_filter$chat = config.getBoolean("image.illegal-characters-filter.chat", true);
image$illegal_characters_filter$command = config.getBoolean("image.illegal-characters-filter.command", true);
image$illegal_characters_filter$sign = config.getBoolean("image.illegal-characters-filter.sign", true);
image$codepoint_starting_value$default = config.getInt("image.codepoint-starting-value.default", 0);
Section codepointOverridesSection = config.getSection("image.codepoint-starting-value.overrides");
if (codepointOverridesSection != null) {
Map<Key, Integer> codepointOverrides = new HashMap<>();
for (Map.Entry<String, Object> entry : codepointOverridesSection.getStringRouteMappedValues(false).entrySet()) {
if (entry.getValue() instanceof String s) {
codepointOverrides.put(Key.of(entry.getKey()), Integer.parseInt(s));
} else if (entry.getValue() instanceof Integer i) {
codepointOverrides.put(Key.of(entry.getKey()), i);
}
}
image$codepoint_starting_value$overrides = codepointOverrides;
} else {
image$codepoint_starting_value$overrides = Map.of();
}
network$intercept_packets$system_chat = config.getBoolean("network.intercept-packets.system-chat", true);
network$intercept_packets$tab_list = config.getBoolean("network.intercept-packets.tab-list", true);
@@ -780,6 +799,13 @@ public class Config {
return instance.item$custom_model_data_starting_value$default;
}
public static int codepointStartingValue(Key font) {
if (instance.image$codepoint_starting_value$overrides.containsKey(font)) {
return instance.image$codepoint_starting_value$overrides.get(font);
}
return instance.image$codepoint_starting_value$default;
}
public static int compressionMethod() {
int id = instance.chunk_system$compression_method;
if (id <= 0 || id > CompressionMethod.METHOD_COUNT) {

View File

@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -18,7 +17,7 @@ public class AllOfCondition<CTX extends Context> implements Condition<CTX> {
protected final Predicate<CTX> condition;
public AllOfCondition(List<? extends Condition<CTX>> conditions) {
this.condition = MCUtils.allOf(conditions);
this.condition = MiscUtils.allOf(conditions);
}
@Override

View File

@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -18,7 +17,7 @@ public class AnyOfCondition<CTX extends Context> implements Condition<CTX> {
protected final Predicate<CTX> condition;
public AnyOfCondition(List<? extends Condition<CTX>> conditions) {
this.condition = MCUtils.anyOf(conditions);
this.condition = MiscUtils.anyOf(conditions);
}
@Override

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.plugin.context.function;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.ArrayList;
@@ -16,7 +15,7 @@ public abstract class AbstractConditionalFunction<CTX extends Context> implement
public AbstractConditionalFunction(List<Condition<CTX>> predicates) {
this.predicates = predicates;
this.compositePredicates = MCUtils.allOf(predicates);
this.compositePredicates = MiscUtils.allOf(predicates);
}
@Override

View File

@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.List;
import java.util.Map;
@@ -28,7 +28,7 @@ public class BreakBlockFunction<CTX extends Context> extends AbstractConditional
@Override
public void runInternal(CTX ctx) {
Optional<Player> optionalPlayer = ctx.getOptionalParameter(DirectContextParameters.PLAYER);
optionalPlayer.ifPresent(player -> player.breakBlock(MCUtils.fastFloor(x.getDouble(ctx)), MCUtils.fastFloor(y.getDouble(ctx)), MCUtils.fastFloor(z.getDouble(ctx))));
optionalPlayer.ifPresent(player -> player.breakBlock(MiscUtils.fastFloor(x.getDouble(ctx)), MiscUtils.fastFloor(y.getDouble(ctx)), MiscUtils.fastFloor(z.getDouble(ctx))));
}
@Override

View File

@@ -10,7 +10,7 @@ import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.LazyReference;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.World;
import net.momirealms.craftengine.core.world.WorldPosition;
@@ -40,7 +40,7 @@ public class PlaceBlockFunction<CTX extends Context> extends AbstractConditional
Optional<WorldPosition> optionalWorldPosition = ctx.getOptionalParameter(DirectContextParameters.POSITION);
if (optionalWorldPosition.isPresent()) {
World world = optionalWorldPosition.get().world();
world.setBlockAt(MCUtils.fastFloor(this.x.getDouble(ctx)), MCUtils.fastFloor(this.y.getDouble(ctx)), MCUtils.fastFloor(this.z.getDouble(ctx)), this.lazyBlockState.get(), this.updateFlags.getInt(ctx));
world.setBlockAt(MiscUtils.fastFloor(this.x.getDouble(ctx)), MiscUtils.fastFloor(this.y.getDouble(ctx)), MiscUtils.fastFloor(this.z.getDouble(ctx)), this.lazyBlockState.get(), this.updateFlags.getInt(ctx));
}
}

View File

@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.WorldPosition;
@@ -48,7 +48,7 @@ public class RunFunction<CTX extends Context> extends AbstractConditionalFunctio
for (Function<CTX> function : functions) {
function.run(ctx);
}
}, delay, pos.world().platformWorld(), MCUtils.fastFloor(pos.x()) >> 4, MCUtils.fastFloor(pos.z()) >> 4);
}, delay, pos.world().platformWorld(), MiscUtils.fastFloor(pos.x()) >> 4, MiscUtils.fastFloor(pos.z()) >> 4);
}
}
}

View File

@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.plugin.context.number;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
@@ -54,7 +54,7 @@ public class GaussianNumberProvider implements NumberProvider {
}
attempts++;
}
return MCUtils.clamp(this.mean, this.min, this.max);
return MiscUtils.clamp(this.mean, this.min, this.max);
}
@Override

View File

@@ -3,7 +3,7 @@ package net.momirealms.craftengine.core.plugin.context.parameter;
import net.momirealms.craftengine.core.entity.Entity;
import net.momirealms.craftengine.core.plugin.context.ChainParameterProvider;
import net.momirealms.craftengine.core.plugin.context.ContextKey;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.HashMap;
import java.util.Map;
@@ -19,9 +19,9 @@ public class EntityParameterProvider implements ChainParameterProvider<Entity> {
CONTEXT_FUNCTIONS.put(DirectContextParameters.YAW, Entity::xRot);
CONTEXT_FUNCTIONS.put(DirectContextParameters.PITCH, Entity::yRot);
CONTEXT_FUNCTIONS.put(DirectContextParameters.POSITION, Entity::position);
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MCUtils.fastFloor(p.x()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MCUtils.fastFloor(p.y()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MCUtils.fastFloor(p.z()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MiscUtils.fastFloor(p.x()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MiscUtils.fastFloor(p.y()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MiscUtils.fastFloor(p.z()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.NAME, Entity::name);
CONTEXT_FUNCTIONS.put(DirectContextParameters.UUID, Entity::uuid);
CONTEXT_FUNCTIONS.put(DirectContextParameters.WORLD, Entity::world);

View File

@@ -5,7 +5,7 @@ import net.momirealms.craftengine.core.entity.player.InteractionHand;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.context.ChainParameterProvider;
import net.momirealms.craftengine.core.plugin.context.ContextKey;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.HashMap;
import java.util.Map;
@@ -21,9 +21,9 @@ public class PlayerParameterProvider implements ChainParameterProvider<Player> {
CONTEXT_FUNCTIONS.put(DirectContextParameters.PITCH, Entity::xRot);
CONTEXT_FUNCTIONS.put(DirectContextParameters.YAW, Entity::yRot);
CONTEXT_FUNCTIONS.put(DirectContextParameters.POSITION, Entity::position);
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MCUtils.fastFloor(p.x()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MCUtils.fastFloor(p.y()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MCUtils.fastFloor(p.z()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MiscUtils.fastFloor(p.x()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MiscUtils.fastFloor(p.y()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MiscUtils.fastFloor(p.z()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.FOOD, Player::foodLevel);
CONTEXT_FUNCTIONS.put(DirectContextParameters.SATURATION, Player::saturation);
CONTEXT_FUNCTIONS.put(DirectContextParameters.NAME, Player::name);

View File

@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.plugin.context.parameter;
import net.momirealms.craftengine.core.plugin.context.ChainParameterProvider;
import net.momirealms.craftengine.core.plugin.context.ContextKey;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.world.WorldPosition;
import java.util.HashMap;
@@ -20,9 +20,9 @@ public class PositionParameterProvider implements ChainParameterProvider<WorldPo
CONTEXT_FUNCTIONS.put(DirectContextParameters.Z, WorldPosition::z);
CONTEXT_FUNCTIONS.put(DirectContextParameters.YAW, WorldPosition::xRot);
CONTEXT_FUNCTIONS.put(DirectContextParameters.PITCH, WorldPosition::yRot);
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MCUtils.fastFloor(p.x()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MCUtils.fastFloor(p.y()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MCUtils.fastFloor(p.z()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MiscUtils.fastFloor(p.x()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MiscUtils.fastFloor(p.y()));
CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MiscUtils.fastFloor(p.z()));
}
@SuppressWarnings("unchecked")

View File

@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.plugin.context.ContextHolder;
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.ArrayList;
import java.util.Arrays;
@@ -21,7 +21,7 @@ public class AllPlayerSelector<CTX extends Context> implements PlayerSelector<CT
private final Predicate<CTX> predicate;
public AllPlayerSelector(List<Condition<CTX>> predicates) {
this.predicate = MCUtils.allOf(predicates);
this.predicate = MiscUtils.allOf(predicates);
}
public AllPlayerSelector() {

View File

@@ -6,7 +6,7 @@ import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.ByteBufUtil;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.EncoderException;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.sparrow.nbt.CompoundTag;
import net.momirealms.sparrow.nbt.NBT;
import net.momirealms.sparrow.nbt.Tag;
@@ -47,7 +47,7 @@ public interface NetworkCodecs {
}
};
NetworkCodec<ByteBuf, Float> ROTATION_BYTE = BYTE.map(MCUtils::unpackDegrees, MCUtils::packDegrees);
NetworkCodec<ByteBuf, Float> ROTATION_BYTE = BYTE.map(MiscUtils::unpackDegrees, MiscUtils::packDegrees);
NetworkCodec<ByteBuf, Short> SHORT = new NetworkCodec<>() {
@Override

View File

@@ -3,7 +3,7 @@ package net.momirealms.craftengine.core.registry;
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.IdentityHashMap;
@@ -11,7 +11,7 @@ import java.util.Map;
import java.util.Objects;
public class ConstantBoundRegistry<T> extends AbstractMappedRegistry<T> {
protected final Reference2IntMap<T> toId = MCUtils.make(new Reference2IntOpenHashMap<>(), map -> map.defaultReturnValue(-1));
protected final Reference2IntMap<T> toId = MiscUtils.init(new Reference2IntOpenHashMap<>(), map -> map.defaultReturnValue(-1));
protected final Map<T, Holder.Reference<T>> byValue;
public ConstantBoundRegistry(ResourceKey<? extends Registry<T>> key, int expectedSize) {

View File

@@ -19,8 +19,7 @@ public class CharacterUtils {
for (int i = 0, j = 0; j < count; i += 6, j++) {
String hex = unicodeString.substring(i + 2, i + 6);
try {
int codePoint = Integer.parseInt(hex, 16);
chars[j] = (char) codePoint;
chars[j] = (char) Integer.parseInt(hex, 16);
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("warning.config.image.invalid_hex_value", e, hex);
}

View File

@@ -38,7 +38,7 @@ public class Color {
}
public static Color fromVector3f(Vector3f vec) {
return new Color(0 << 24 /*不可省略*/ | MCUtils.fastFloor(vec.x) << 16 | MCUtils.fastFloor(vec.y) << 8 | MCUtils.fastFloor(vec.z));
return new Color(0 << 24 /*不可省略*/ | MiscUtils.fastFloor(vec.x) << 16 | MiscUtils.fastFloor(vec.y) << 8 | MiscUtils.fastFloor(vec.z));
}
public static int opaque(int color) {

View File

@@ -131,10 +131,10 @@ public enum Direction {
public static Direction[] orderedByNearest(AbstractEntity entity) {
float f = entity.xRot() * ((float)Math.PI / 180F);
float f1 = -entity.yRot() * ((float)Math.PI / 180F);
float sin = MCUtils.sin(f);
float cos = MCUtils.cos(f);
float sin1 = MCUtils.sin(f1);
float cos1 = MCUtils.cos(f1);
float sin = MiscUtils.sin(f);
float cos = MiscUtils.cos(f);
float sin1 = MiscUtils.sin(f1);
float cos1 = MiscUtils.cos(f1);
boolean flag = sin1 > 0.0F;
boolean flag1 = sin < 0.0F;
boolean flag2 = cos1 > 0.0F;

View File

@@ -585,7 +585,7 @@ public class FriendlyByteBuf extends ByteBuf {
}
public BitSet readFixedBitSet(int size) {
byte[] byteArray = new byte[MCUtils.positiveCeilDiv(size, 8)];
byte[] byteArray = new byte[MiscUtils.positiveCeilDiv(size, 8)];
this.readBytes(byteArray);
return BitSet.valueOf(byteArray);
}
@@ -595,7 +595,7 @@ public class FriendlyByteBuf extends ByteBuf {
throw new EncoderException("BitSet length exceeds expected size (" + bitSet.length() + " > " + size + ")");
}
byte[] byteArray = bitSet.toByteArray();
this.writeBytes(Arrays.copyOf(byteArray, MCUtils.positiveCeilDiv(size, 8)));
this.writeBytes(Arrays.copyOf(byteArray, MiscUtils.positiveCeilDiv(size, 8)));
}
@SuppressWarnings("unchecked")
@@ -631,11 +631,11 @@ public class FriendlyByteBuf extends ByteBuf {
double d = Double.isNaN(vec3.x) ? (double) 0.0F : Math.clamp(vec3.x, -1.7179869183E10, 1.7179869183E10);
double d1 = Double.isNaN(vec3.y) ? (double) 0.0F : Math.clamp(vec3.y, -1.7179869183E10, 1.7179869183E10);
double d2 = Double.isNaN(vec3.z) ? (double) 0.0F : Math.clamp(vec3.z, -1.7179869183E10, 1.7179869183E10);
double max = MCUtils.absMax(d, MCUtils.absMax(d1, d2));
double max = MiscUtils.absMax(d, MiscUtils.absMax(d1, d2));
if (max < 3.051944088384301E-5) {
this.writeByte(0);
} else {
long l = MCUtils.ceilLong(max);
long l = MiscUtils.ceilLong(max);
boolean flag = (l & 3L) != l;
long l1 = flag ? l & 3L | 4L : l;
long l2 = (Math.round(((d / (double) l) * (double) 0.5F + (double) 0.5F) * (double) 32766.0F)) << 3;

View File

@@ -121,7 +121,7 @@ public class Int2ObjectBiMap<K> implements IndexedIterable<K> {
}
private int getIdealIndex(@Nullable K value) {
return (MCUtils.idealHash(System.identityHashCode(value)) & Integer.MAX_VALUE) % this.values.length;
return (MiscUtils.idealHash(System.identityHashCode(value)) & Integer.MAX_VALUE) % this.values.length;
}
private int findIndex(@Nullable K value, int id) {

View File

@@ -1,294 +0,0 @@
package net.momirealms.craftengine.core.util;
import com.google.common.collect.Iterators;
import org.jetbrains.annotations.Nullable;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
public class MCUtils {
private MCUtils() {}
public static final float DEG_TO_RAD = ((float)Math.PI / 180F);
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
private static final float[] SIN = make(new float[65536], (sineTable) -> {
for(int i = 0; i < sineTable.length; ++i) {
sineTable[i] = (float) Math.sin((double) i * Math.PI * 2.0 / 65536.0);
}
});
public static int fastFloor(double value) {
int truncated = (int) value;
return value < (double) truncated ? truncated - 1 : truncated;
}
public static int fastFloor(float value) {
int truncated = (int) value;
return value < (double) truncated ? truncated - 1 : truncated;
}
public static int lerpDiscrete(float delta, int start, int end) {
int i = end - start;
return start + fastFloor(delta * (float) (i - 1)) + (delta > 0.0F ? 1 : 0);
}
public static int murmurHash3Mixer(int value) {
value ^= value >>> 16;
value *= -2048144789;
value ^= value >>> 13;
value *= -1028477387;
return value ^ value >>> 16;
}
public static int ceil(double value) {
int i = (int)value;
return value > (double)i ? i + 1 : i;
}
public static boolean isPowerOfTwo(int value) {
return value != 0 && (value & value - 1) == 0;
}
public static int smallestEncompassingPowerOfTwo(int value) {
int i = value - 1;
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
i |= i >> 16;
return i + 1;
}
public static int ceilLog2(int value) {
value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)((long)value * 125613361L >> 27) & 31];
}
public static int positiveCeilDiv(int a, int b) {
return -Math.floorDiv(-a, b);
}
public static int idealHash(int value) {
value ^= value >>> 16;
value *= -2048144789;
value ^= value >>> 13;
value *= -1028477387;
value ^= value >>> 16;
return value;
}
public static long getUnsignedDivisorMagic(final long divisor, final int bits) {
return ((1L << bits) - 1L) / divisor + 1L;
}
public static <T> T make(T object, Consumer<? super T> initializer) {
initializer.accept(object);
return object;
}
public static <T> Predicate<T> allOf() {
return o -> true;
}
@SuppressWarnings("unchecked")
public static <T> Predicate<T> allOf(Predicate<? super T> a) {
return (Predicate<T>) a;
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b) {
return o -> a.test(o) && b.test(o);
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c) {
return o -> a.test(o) && b.test(o) && c.test(o);
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d) {
return o -> a.test(o) && b.test(o) && c.test(o) && d.test(o);
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d, Predicate<? super T> e) {
return o -> a.test(o) && b.test(o) && c.test(o) && d.test(o) && e.test(o);
}
@SafeVarargs
public static <T> Predicate<T> allOf(Predicate<? super T>... predicates) {
return o -> {
for (Predicate<? super T> predicate : predicates) {
if (!predicate.test(o)) {
return false;
}
}
return true;
};
}
public static <T> Predicate<T> allOf(List<? extends Predicate<? super T>> predicates) {
return switch (predicates.size()) {
case 0 -> allOf();
case 1 -> allOf((Predicate<? super T>) predicates.get(0));
case 2 -> allOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1));
case 3 -> allOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1), (Predicate<? super T>) predicates.get(2));
case 4 -> allOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3)
);
case 5 -> allOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3),
(Predicate<? super T>) predicates.get(4)
);
default -> {
@SuppressWarnings("unchecked")
Predicate<? super T>[] predicates2 = predicates.toArray(Predicate[]::new);
yield allOf(predicates2);
}
};
}
public static <T> Predicate<T> anyOf() {
return o -> false;
}
@SuppressWarnings("unchecked")
public static <T> Predicate<T> anyOf(Predicate<? super T> a) {
return (Predicate<T>) a;
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b) {
return o -> a.test(o) || b.test(o);
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c) {
return o -> a.test(o) || b.test(o) || c.test(o);
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d) {
return o -> a.test(o) || b.test(o) || c.test(o) || d.test(o);
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d, Predicate<? super T> e) {
return o -> a.test(o) || b.test(o) || c.test(o) || d.test(o) || e.test(o);
}
@SafeVarargs
public static <T> Predicate<T> anyOf(Predicate<? super T>... predicates) {
return o -> {
for (Predicate<? super T> predicate : predicates) {
if (predicate.test(o)) {
return true;
}
}
return false;
};
}
public static <T> Predicate<T> anyOf(List<? extends Predicate<? super T>> predicates) {
return switch (predicates.size()) {
case 0 -> anyOf();
case 1 -> anyOf((Predicate<? super T>) predicates.get(0));
case 2 -> anyOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1));
case 3 -> anyOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1), (Predicate<? super T>) predicates.get(2));
case 4 -> anyOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3)
);
case 5 -> anyOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3),
(Predicate<? super T>) predicates.get(4)
);
default -> {
@SuppressWarnings("unchecked")
Predicate<? super T>[] predicates2 = predicates.toArray(Predicate[]::new);
yield anyOf(predicates2);
}
};
}
public static <T> T findPreviousInIterable(Iterable<T> iterable, @Nullable T object) {
Iterator<T> iterator = iterable.iterator();
T previous = null;
while (iterator.hasNext()) {
T current = iterator.next();
if (current == object) {
if (previous == null) {
previous = iterator.hasNext() ? Iterators.getLast(iterator) : object;
}
break;
}
previous = current;
}
return previous;
}
public static float sin(float value) {
return SIN[(int) (value * 10430.378F) & '\uffff'];
}
public static float cos(float value) {
return SIN[(int)(value * 10430.378F + 16384.0F) & '\uffff'];
}
public static float sqrt(float value) {
return (float)Math.sqrt(value);
}
public static <T> T findNextInIterable(Iterable<T> iterable, @Nullable T object) {
Iterator<T> iterator = iterable.iterator();
T next = iterator.next();
if (object != null) {
T current = next;
while (current != object) {
if (iterator.hasNext()) {
current = iterator.next();
}
}
if (iterator.hasNext()) {
return iterator.next();
}
}
return next;
}
public static byte packDegrees(float degrees) {
return (byte) fastFloor(degrees * 256.0F / 360.0F);
}
public static float unpackDegrees(byte degrees) {
return (float) (degrees * 360) / 256.0F;
}
public static int clamp(int value, int min, int max) {
return Math.min(Math.max(value, min), max);
}
public static float clamp(float value, float min, float max) {
return value < min ? min : Math.min(value, max);
}
public static double clamp(double value, double min, double max) {
return value < min ? min : Math.min(value, max);
}
public static double absMax(double x, double y) {
return Math.max(Math.abs(x), Math.abs(y));
}
public static long ceilLong(double value) {
long l = (long)value;
return value > (double)l ? l + 1L : l;
}
}

View File

@@ -1,10 +1,302 @@
package net.momirealms.craftengine.core.util;
import com.google.common.collect.Iterators;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public class MiscUtils {
private MiscUtils() {
}
private MiscUtils() {}
public static final float DEG_TO_RAD = ((float) Math.PI / 180F);
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
private static final float[] SIN = init(new float[65536], (sineTable) -> {
for (int i = 0; i < sineTable.length; ++i) {
sineTable[i] = (float) Math.sin((double) i * Math.PI * 2.0 / 65536.0);
}
});
public static int fastFloor(double value) {
int truncated = (int) value;
return value < (double) truncated ? truncated - 1 : truncated;
}
public static int fastFloor(float value) {
int truncated = (int) value;
return value < (double) truncated ? truncated - 1 : truncated;
}
public static int lerpDiscrete(float delta, int start, int end) {
int i = end - start;
return start + fastFloor(delta * (float) (i - 1)) + (delta > 0.0F ? 1 : 0);
}
public static int murmurHash3Mixer(int value) {
value ^= value >>> 16;
value *= -2048144789;
value ^= value >>> 13;
value *= -1028477387;
return value ^ value >>> 16;
}
public static int ceil(double value) {
int i = (int) value;
return value > (double) i ? i + 1 : i;
}
public static boolean isPowerOfTwo(int value) {
return value != 0 && (value & value - 1) == 0;
}
public static int smallestEncompassingPowerOfTwo(int value) {
int i = value - 1;
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
i |= i >> 16;
return i + 1;
}
public static int ceilLog2(int value) {
value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) ((long) value * 125613361L >> 27) & 31];
}
public static int positiveCeilDiv(int a, int b) {
return -Math.floorDiv(-a, b);
}
public static int idealHash(int value) {
value ^= value >>> 16;
value *= -2048144789;
value ^= value >>> 13;
value *= -1028477387;
value ^= value >>> 16;
return value;
}
public static long getUnsignedDivisorMagic(final long divisor, final int bits) {
return ((1L << bits) - 1L) / divisor + 1L;
}
public static <T> T init(T object, Consumer<? super T> initializer) {
initializer.accept(object);
return object;
}
public static <T> T make(final T object, Function<T, T> initializer) {
return initializer.apply(object);
}
public static <T> Predicate<T> allOf() {
return o -> true;
}
@SuppressWarnings("unchecked")
public static <T> Predicate<T> allOf(Predicate<? super T> a) {
return (Predicate<T>) a;
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b) {
return o -> a.test(o) && b.test(o);
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c) {
return o -> a.test(o) && b.test(o) && c.test(o);
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d) {
return o -> a.test(o) && b.test(o) && c.test(o) && d.test(o);
}
public static <T> Predicate<T> allOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d, Predicate<? super T> e) {
return o -> a.test(o) && b.test(o) && c.test(o) && d.test(o) && e.test(o);
}
@SafeVarargs
public static <T> Predicate<T> allOf(Predicate<? super T>... predicates) {
return o -> {
for (Predicate<? super T> predicate : predicates) {
if (!predicate.test(o)) {
return false;
}
}
return true;
};
}
public static <T> Predicate<T> allOf(List<? extends Predicate<? super T>> predicates) {
return switch (predicates.size()) {
case 0 -> allOf();
case 1 -> allOf((Predicate<? super T>) predicates.get(0));
case 2 -> allOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1));
case 3 ->
allOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1), (Predicate<? super T>) predicates.get(2));
case 4 -> allOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3)
);
case 5 -> allOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3),
(Predicate<? super T>) predicates.get(4)
);
default -> {
@SuppressWarnings("unchecked")
Predicate<? super T>[] predicates2 = predicates.toArray(Predicate[]::new);
yield allOf(predicates2);
}
};
}
public static <T> Predicate<T> anyOf() {
return o -> false;
}
@SuppressWarnings("unchecked")
public static <T> Predicate<T> anyOf(Predicate<? super T> a) {
return (Predicate<T>) a;
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b) {
return o -> a.test(o) || b.test(o);
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c) {
return o -> a.test(o) || b.test(o) || c.test(o);
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d) {
return o -> a.test(o) || b.test(o) || c.test(o) || d.test(o);
}
public static <T> Predicate<T> anyOf(Predicate<? super T> a, Predicate<? super T> b, Predicate<? super T> c, Predicate<? super T> d, Predicate<? super T> e) {
return o -> a.test(o) || b.test(o) || c.test(o) || d.test(o) || e.test(o);
}
@SafeVarargs
public static <T> Predicate<T> anyOf(Predicate<? super T>... predicates) {
return o -> {
for (Predicate<? super T> predicate : predicates) {
if (predicate.test(o)) {
return true;
}
}
return false;
};
}
public static <T> Predicate<T> anyOf(List<? extends Predicate<? super T>> predicates) {
return switch (predicates.size()) {
case 0 -> anyOf();
case 1 -> anyOf((Predicate<? super T>) predicates.get(0));
case 2 -> anyOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1));
case 3 ->
anyOf((Predicate<? super T>) predicates.get(0), (Predicate<? super T>) predicates.get(1), (Predicate<? super T>) predicates.get(2));
case 4 -> anyOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3)
);
case 5 -> anyOf(
(Predicate<? super T>) predicates.get(0),
(Predicate<? super T>) predicates.get(1),
(Predicate<? super T>) predicates.get(2),
(Predicate<? super T>) predicates.get(3),
(Predicate<? super T>) predicates.get(4)
);
default -> {
@SuppressWarnings("unchecked")
Predicate<? super T>[] predicates2 = predicates.toArray(Predicate[]::new);
yield anyOf(predicates2);
}
};
}
public static <T> T findPreviousInIterable(Iterable<T> iterable, @Nullable T object) {
Iterator<T> iterator = iterable.iterator();
T previous = null;
while (iterator.hasNext()) {
T current = iterator.next();
if (current == object) {
if (previous == null) {
previous = iterator.hasNext() ? Iterators.getLast(iterator) : object;
}
break;
}
previous = current;
}
return previous;
}
public static float sin(float value) {
return SIN[(int) (value * 10430.378F) & '\uffff'];
}
public static float cos(float value) {
return SIN[(int) (value * 10430.378F + 16384.0F) & '\uffff'];
}
public static float sqrt(float value) {
return (float) Math.sqrt(value);
}
public static <T> T findNextInIterable(Iterable<T> iterable, @Nullable T object) {
Iterator<T> iterator = iterable.iterator();
T next = iterator.next();
if (object != null) {
T current = next;
while (current != object) {
if (iterator.hasNext()) {
current = iterator.next();
}
}
if (iterator.hasNext()) {
return iterator.next();
}
}
return next;
}
public static byte packDegrees(float degrees) {
return (byte) fastFloor(degrees * 256.0F / 360.0F);
}
public static float unpackDegrees(byte degrees) {
return (float) (degrees * 360) / 256.0F;
}
public static int clamp(int value, int min, int max) {
return Math.min(Math.max(value, min), max);
}
public static float clamp(float value, float min, float max) {
return value < min ? min : Math.min(value, max);
}
public static double clamp(double value, double min, double max) {
return value < min ? min : Math.min(value, max);
}
public static double absMax(double x, double y) {
return Math.max(Math.abs(x), Math.abs(y));
}
public static long ceilLong(double value) {
long l = (long) value;
return value > (double) l ? l + 1L : l;
}
@SuppressWarnings("unchecked")
public static Map<String, Object> castToMap(Object obj, boolean allowNull) {

View File

@@ -21,12 +21,12 @@ public class QuaternionUtils {
}
public static Quaternionf toQuaternionf(float yaw, float pitch, float roll) {
float cy = MCUtils.cos(yaw * 0.5f);
float sy = MCUtils.sin(yaw * 0.5f);
float cp = MCUtils.cos(pitch * 0.5f);
float sp = MCUtils.sin(pitch * 0.5f);
float cr = MCUtils.cos(roll * 0.5f);
float sr = MCUtils.sin(roll * 0.5f);
float cy = MiscUtils.cos(yaw * 0.5f);
float sy = MiscUtils.sin(yaw * 0.5f);
float cp = MiscUtils.cos(pitch * 0.5f);
float sp = MiscUtils.sin(pitch * 0.5f);
float cr = MiscUtils.cos(roll * 0.5f);
float sr = MiscUtils.sin(roll * 0.5f);
float w = cr * cp * cy + sr * sp * sy;
float x = sr * cp * cy - cr * sp * sy;
float y = cr * sp * cy + sr * cp * sy;

View File

@@ -1,7 +1,7 @@
package net.momirealms.craftengine.core.world;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
public class BlockPos extends Vec3i {
public static final BlockPos ZERO = new BlockPos(0, 0, 0);
@@ -23,7 +23,7 @@ public class BlockPos extends Vec3i {
}
public static BlockPos fromVec3d(Vec3d vec) {
return new BlockPos(MCUtils.fastFloor(vec.x), MCUtils.fastFloor(vec.y), MCUtils.fastFloor(vec.z));
return new BlockPos(MiscUtils.fastFloor(vec.x), MiscUtils.fastFloor(vec.y), MiscUtils.fastFloor(vec.z));
}
public static BlockPos of(long packedPos) {

View File

@@ -1,7 +1,7 @@
package net.momirealms.craftengine.core.world;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
public class EntityHitResult {
private final Direction direction;
@@ -23,9 +23,9 @@ public class EntityHitResult {
}
private BlockPos getBlockPos() {
int x = MCUtils.fastFloor(this.position.x);
int y = MCUtils.fastFloor(this.position.y);
int z = MCUtils.fastFloor(this.position.z);
int x = MiscUtils.fastFloor(this.position.x);
int y = MiscUtils.fastFloor(this.position.y);
int z = MiscUtils.fastFloor(this.position.z);
if (this.direction == Direction.UP) {
if (this.position.y % 1 == 0) {
y--;

View File

@@ -1,6 +1,6 @@
package net.momirealms.craftengine.core.world;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
public class Vec3d implements Position {
public static final Vec3d ZERO = new Vec3d(0, 0, 0);
@@ -15,7 +15,7 @@ public class Vec3d implements Position {
}
public Vec3d toCenter() {
return new Vec3d(MCUtils.fastFloor(x) + 0.5, MCUtils.fastFloor(y) + 0.5, MCUtils.fastFloor(z) + 0.5);
return new Vec3d(MiscUtils.fastFloor(x) + 0.5, MiscUtils.fastFloor(y) + 0.5, MiscUtils.fastFloor(z) + 0.5);
}
public Vec3d add(Vec3d vec) {

View File

@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.block.EmptyBlock;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
import net.momirealms.craftengine.core.util.IndexedIterable;
import net.momirealms.craftengine.core.util.MCUtils;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import org.jetbrains.annotations.Nullable;
@@ -269,7 +269,7 @@ public class PalettedContainer<T> implements PaletteResizeListener<T>, ReadableC
case 0 -> new DataProvider<>(SINGULAR, bits);
case 1, 2, 3, 4 -> new DataProvider<>(ARRAY, 4);
case 5, 6, 7, 8 -> new DataProvider<>(BI_MAP, bits);
default -> new DataProvider<>(PaletteProvider.ID_LIST, MCUtils.ceilLog2(idList.size()));
default -> new DataProvider<>(PaletteProvider.ID_LIST, MiscUtils.ceilLog2(idList.size()));
};
}
};
@@ -278,7 +278,7 @@ public class PalettedContainer<T> implements PaletteResizeListener<T>, ReadableC
return switch (bits) {
case 0 -> new DataProvider<>(SINGULAR, bits);
case 1, 2, 3 -> new DataProvider<>(ARRAY, bits);
default -> new DataProvider<>(PaletteProvider.ID_LIST, MCUtils.ceilLog2(idList.size()));
default -> new DataProvider<>(PaletteProvider.ID_LIST, MiscUtils.ceilLog2(idList.size()));
};
}
};
@@ -300,7 +300,7 @@ public class PalettedContainer<T> implements PaletteResizeListener<T>, ReadableC
public abstract <A> DataProvider<A> createDataProvider(IndexedIterable<A> idList, int bits);
<A> int getBits(IndexedIterable<A> idList, int size) {
int i = MCUtils.ceilLog2(size);
int i = MiscUtils.ceilLog2(size);
DataProvider<A> dataProvider = this.createDataProvider(idList, i);
return dataProvider.factory() == ID_LIST ? i : dataProvider.bits();
}

View File

@@ -2,9 +2,9 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.63.7
project_version=0.0.63.8
config_version=47
lang_version=31
lang_version=32
project_group=net.momirealms
latest_supported_version=1.21.8
@@ -15,8 +15,8 @@ supported_languages=en,zh_cn,zh_tw,es,tr,de,ru_ru
paper_version=1.21.8
jetbrains_annotations_version=26.0.2
slf4j_version=2.0.17
log4j_version=2.24.3
gson_version=2.11.0
log4j_version=2.25.2
gson_version=2.13.2
asm_version=9.8
asm_commons_version=9.8
jar_relocator_version=1.7
@@ -29,20 +29,20 @@ cloud_paper_version=2.0.0-beta.11
cloud_minecraft_extras_version=2.0.0-beta.11
boosted_yaml_version=1.3.7
bstats_version=3.1.0
caffeine_version=3.2.0
caffeine_version=3.2.2
placeholder_api_version=2.11.6
vault_version=1.7
guava_version=33.4.6-jre
guava_version=33.5.0-jre
lz4_version=1.8.0
geantyref_version=1.3.16
zstd_version=1.5.7-2
commons_io_version=2.18.0
zstd_version=1.5.7-4
commons_io_version=2.20.0
commons_imaging_version=1.0.0-alpha6
commons_lang3_version=3.17.0
commons_lang3_version=3.19.0
sparrow_nbt_version=0.9.4
sparrow_util_version=0.51
fastutil_version=8.5.15
netty_version=4.1.124.Final
fastutil_version=8.5.16
netty_version=4.1.127.Final
joml_version=1.10.8
datafixerupper_version=8.0.16
mojang_brigadier_version=1.0.18
@@ -53,9 +53,9 @@ anti_grief_version=0.20
nms_helper_version=1.0.97
evalex_version=3.5.0
reactive_streams_version=1.0.4
amazon_awssdk_version=2.33.1
amazon_awssdk_version=2.34.5
amazon_awssdk_eventstream_version=1.0.1
jimfs_version=1.3.0
jimfs_version=1.3.1
authlib_version=7.0.60
concurrent_util_version=0.0.3