mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 18:09:27 +00:00
feat(entity): 补充翻译末影人手上的方块
This commit is contained in:
@@ -4,7 +4,7 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBlocks;
|
|||||||
|
|
||||||
public class BlockDisplayEntityData<T> extends DisplayEntityData<T> {
|
public class BlockDisplayEntityData<T> extends DisplayEntityData<T> {
|
||||||
// Block display only
|
// Block display only
|
||||||
public static final DisplayEntityData<Object> DisplayedBlock = new BlockDisplayEntityData<>(BlockDisplayEntityData.class, EntityDataValue.Serializers$BLOCK_STATE, MBlocks.AIR$defaultState);
|
public static final BlockDisplayEntityData<Object> DisplayedBlock = new BlockDisplayEntityData<>(BlockDisplayEntityData.class, EntityDataValue.Serializers$BLOCK_STATE, MBlocks.AIR$defaultState);
|
||||||
|
|
||||||
public BlockDisplayEntityData(Class<?> clazz, Object serializer, T defaultValue) {
|
public BlockDisplayEntityData(Class<?> clazz, Object serializer, T defaultValue) {
|
||||||
super(clazz, serializer, defaultValue);
|
super(clazz, serializer, defaultValue);
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.momirealms.craftengine.bukkit.entity.data;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class EnderManData<T> extends MonsterData<T> {
|
||||||
|
public static final EnderManData<Optional<Object>> CarryState = new EnderManData<>(EnderManData.class, EntityDataValue.Serializers$OPTIONAL_BLOCK_STATE, Optional.empty());
|
||||||
|
public static final EnderManData<Boolean> Creepy = new EnderManData<>(EnderManData.class, EntityDataValue.Serializers$BOOLEAN, false);
|
||||||
|
public static final EnderManData<Boolean> StaredAt = new EnderManData<>(EnderManData.class, EntityDataValue.Serializers$BOOLEAN, false);
|
||||||
|
|
||||||
|
public EnderManData(Class<?> clazz, Object serializer, T defaultValue) {
|
||||||
|
super(clazz, serializer, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflect
|
|||||||
|
|
||||||
public class ItemDisplayEntityData<T> extends DisplayEntityData<T> {
|
public class ItemDisplayEntityData<T> extends DisplayEntityData<T> {
|
||||||
// Item display only
|
// Item display only
|
||||||
public static final DisplayEntityData<Object> DisplayedItem = new ItemDisplayEntityData<>(ItemDisplayEntityData.class, EntityDataValue.Serializers$ITEM_STACK, CoreReflections.instance$ItemStack$EMPTY);
|
public static final ItemDisplayEntityData<Object> DisplayedItem = new ItemDisplayEntityData<>(ItemDisplayEntityData.class, EntityDataValue.Serializers$ITEM_STACK, CoreReflections.instance$ItemStack$EMPTY);
|
||||||
/**
|
/**
|
||||||
* Display type:
|
* Display type:
|
||||||
* 0 = NONE
|
* 0 = NONE
|
||||||
@@ -17,7 +17,7 @@ public class ItemDisplayEntityData<T> extends DisplayEntityData<T> {
|
|||||||
* 7 = GROUND
|
* 7 = GROUND
|
||||||
* 8 = FIXED
|
* 8 = FIXED
|
||||||
*/
|
*/
|
||||||
public static final DisplayEntityData<Byte> DisplayType = new ItemDisplayEntityData<>(ItemDisplayEntityData.class, EntityDataValue.Serializers$BYTE, (byte) 0);
|
public static final ItemDisplayEntityData<Byte> DisplayType = new ItemDisplayEntityData<>(ItemDisplayEntityData.class, EntityDataValue.Serializers$BYTE, (byte) 0);
|
||||||
|
|
||||||
public ItemDisplayEntityData(Class<?> clazz, Object serializer, T defaultValue) {
|
public ItemDisplayEntityData(Class<?> clazz, Object serializer, T defaultValue) {
|
||||||
super(clazz, serializer, defaultValue);
|
super(clazz, serializer, defaultValue);
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.momirealms.craftengine.bukkit.entity.data;
|
||||||
|
|
||||||
|
public class MonsterData<T> extends PathfinderMobData<T> {
|
||||||
|
|
||||||
|
public MonsterData(Class<?> clazz, Object serializer, T defaultValue) {
|
||||||
|
super(clazz, serializer, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,11 @@ package net.momirealms.craftengine.bukkit.entity.data;
|
|||||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||||
|
|
||||||
public class TextDisplayEntityData<T> extends DisplayEntityData<T> {
|
public class TextDisplayEntityData<T> extends DisplayEntityData<T> {
|
||||||
public static final DisplayEntityData<Object> Text = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$COMPONENT, CoreReflections.instance$Component$empty);
|
public static final TextDisplayEntityData<Object> Text = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$COMPONENT, CoreReflections.instance$Component$empty);
|
||||||
public static final DisplayEntityData<Integer> LineWidth = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$INT, 200);
|
public static final TextDisplayEntityData<Integer> LineWidth = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$INT, 200);
|
||||||
public static final DisplayEntityData<Integer> BackgroundColor = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$INT, 0x40000000);
|
public static final TextDisplayEntityData<Integer> BackgroundColor = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$INT, 0x40000000);
|
||||||
public static final DisplayEntityData<Byte> TextOpacity = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$BYTE, (byte) -1);
|
public static final TextDisplayEntityData<Byte> TextOpacity = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$BYTE, (byte) -1);
|
||||||
public static final DisplayEntityData<Byte> TextDisplayMasks = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$BYTE, (byte) 0);
|
public static final TextDisplayEntityData<Byte> TextDisplayMasks = new TextDisplayEntityData<>(TextDisplayEntityData.class, EntityDataValue.Serializers$BYTE, (byte) 0);
|
||||||
|
|
||||||
public TextDisplayEntityData(Class<?> clazz, Object serializer, T defaultValue) {
|
public TextDisplayEntityData(Class<?> clazz, Object serializer, T defaultValue) {
|
||||||
super(clazz, serializer, defaultValue);
|
super(clazz, serializer, defaultValue);
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ public class PacketConsumers {
|
|||||||
ADD_ENTITY_HANDLERS[MEntityTypes.ITEM$registryId] = simpleAddEntityHandler(CommonItemPacketHandler.INSTANCE);
|
ADD_ENTITY_HANDLERS[MEntityTypes.ITEM$registryId] = simpleAddEntityHandler(CommonItemPacketHandler.INSTANCE);
|
||||||
ADD_ENTITY_HANDLERS[MEntityTypes.ITEM_FRAME$registryId] = simpleAddEntityHandler(ItemFramePacketHandler.INSTANCE);
|
ADD_ENTITY_HANDLERS[MEntityTypes.ITEM_FRAME$registryId] = simpleAddEntityHandler(ItemFramePacketHandler.INSTANCE);
|
||||||
ADD_ENTITY_HANDLERS[MEntityTypes.GLOW_ITEM_FRAME$registryId] = simpleAddEntityHandler(ItemFramePacketHandler.INSTANCE);
|
ADD_ENTITY_HANDLERS[MEntityTypes.GLOW_ITEM_FRAME$registryId] = simpleAddEntityHandler(ItemFramePacketHandler.INSTANCE);
|
||||||
|
ADD_ENTITY_HANDLERS[MEntityTypes.ENDERMAN$registryId] = simpleAddEntityHandler(EndermanPacketHandler.INSTANCE);
|
||||||
ADD_ENTITY_HANDLERS[MEntityTypes.FIREBALL$registryId] = createOptionalCustomProjectileEntityHandler(true);
|
ADD_ENTITY_HANDLERS[MEntityTypes.FIREBALL$registryId] = createOptionalCustomProjectileEntityHandler(true);
|
||||||
ADD_ENTITY_HANDLERS[MEntityTypes.EYE_OF_ENDER$registryId] = createOptionalCustomProjectileEntityHandler(true);
|
ADD_ENTITY_HANDLERS[MEntityTypes.EYE_OF_ENDER$registryId] = createOptionalCustomProjectileEntityHandler(true);
|
||||||
ADD_ENTITY_HANDLERS[MEntityTypes.FIREWORK_ROCKET$registryId] = createOptionalCustomProjectileEntityHandler(true);
|
ADD_ENTITY_HANDLERS[MEntityTypes.FIREWORK_ROCKET$registryId] = createOptionalCustomProjectileEntityHandler(true);
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package net.momirealms.craftengine.bukkit.plugin.network.handler;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||||
|
import net.momirealms.craftengine.bukkit.plugin.network.PacketConsumers;
|
||||||
|
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||||
|
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||||
|
import net.momirealms.craftengine.bukkit.util.EntityDataUtils;
|
||||||
|
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||||
|
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||||
|
import net.momirealms.craftengine.core.plugin.network.ByteBufPacketEvent;
|
||||||
|
import net.momirealms.craftengine.core.plugin.network.EntityPacketHandler;
|
||||||
|
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||||
|
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||||
|
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class EndermanPacketHandler implements EntityPacketHandler {
|
||||||
|
public static final EndermanPacketHandler INSTANCE = new EndermanPacketHandler();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleSetEntityData(NetWorkUser user, ByteBufPacketEvent event) {
|
||||||
|
FriendlyByteBuf buf = event.getBuffer();
|
||||||
|
int id = buf.readVarInt();
|
||||||
|
boolean isChanged = false;
|
||||||
|
List<Object> packedItems = FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$unpack(buf);
|
||||||
|
for (int i = 0; i < packedItems.size(); i++) {
|
||||||
|
Object packedItem = packedItems.get(i);
|
||||||
|
int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
|
||||||
|
if (entityDataId == EntityDataUtils.ENDERMAN_OPTIONAL_BLOCK_STATE) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Optional<Object> blockState = (Optional<Object>) FastNMS.INSTANCE.field$SynchedEntityData$DataValue$value(packedItem);
|
||||||
|
if (blockState.isEmpty()) continue;
|
||||||
|
int stateId = BlockStateUtils.blockStateToId(blockState.get());
|
||||||
|
int newStateId;
|
||||||
|
if (!user.clientModEnabled()) {
|
||||||
|
newStateId = PacketConsumers.remap(stateId);
|
||||||
|
} else {
|
||||||
|
newStateId = PacketConsumers.remapMOD(stateId);
|
||||||
|
}
|
||||||
|
Object serializer = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$serializer(packedItem);
|
||||||
|
packedItems.set(i, FastNMS.INSTANCE.constructor$SynchedEntityData$DataValue(
|
||||||
|
entityDataId, serializer, Optional.of(BlockStateUtils.idToBlockState(newStateId))
|
||||||
|
));
|
||||||
|
isChanged = true;
|
||||||
|
} else if (Config.interceptEntityName() && entityDataId == EntityDataUtils.CUSTOM_NAME_DATA_ID) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Optional<Object> optionalTextComponent = (Optional<Object>) FastNMS.INSTANCE.field$SynchedEntityData$DataValue$value(packedItem);
|
||||||
|
if (optionalTextComponent.isEmpty()) continue;
|
||||||
|
Object textComponent = optionalTextComponent.get();
|
||||||
|
String json = ComponentUtils.minecraftToJson(textComponent);
|
||||||
|
Map<String, Component> tokens = CraftEngine.instance().fontManager().matchTags(json);
|
||||||
|
if (tokens.isEmpty()) continue;
|
||||||
|
Component component = AdventureHelper.jsonToComponent(json);
|
||||||
|
for (Map.Entry<String, Component> token : tokens.entrySet()) {
|
||||||
|
component = component.replaceText(b -> b.matchLiteral(token.getKey()).replacement(token.getValue()));
|
||||||
|
}
|
||||||
|
Object serializer = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$serializer(packedItem);
|
||||||
|
packedItems.set(i, FastNMS.INSTANCE.constructor$SynchedEntityData$DataValue(
|
||||||
|
entityDataId, serializer, Optional.of(ComponentUtils.adventureToMinecraft(component))
|
||||||
|
));
|
||||||
|
isChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isChanged) {
|
||||||
|
event.setChanged(true);
|
||||||
|
buf.clear();
|
||||||
|
buf.writeVarInt(event.packetID());
|
||||||
|
buf.writeVarInt(id);
|
||||||
|
FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$pack(packedItems, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -58,6 +58,8 @@ public final class MEntityTypes {
|
|||||||
public static final int HAPPY_GHAST$registryId;
|
public static final int HAPPY_GHAST$registryId;
|
||||||
public static final Object PLAYER;
|
public static final Object PLAYER;
|
||||||
public static final int PLAYER$registryId;
|
public static final int PLAYER$registryId;
|
||||||
|
public static final Object ENDERMAN;
|
||||||
|
public static final int ENDERMAN$registryId;
|
||||||
|
|
||||||
private static Object getById(String id) {
|
private static Object getById(String id) {
|
||||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||||
@@ -122,5 +124,7 @@ public final class MEntityTypes {
|
|||||||
ARROW$registryId = getRegistryId(ARROW);
|
ARROW$registryId = getRegistryId(ARROW);
|
||||||
SPECTRAL_ARROW = getById("spectral_arrow");
|
SPECTRAL_ARROW = getById("spectral_arrow");
|
||||||
SPECTRAL_ARROW$registryId = getRegistryId(SPECTRAL_ARROW);
|
SPECTRAL_ARROW$registryId = getRegistryId(SPECTRAL_ARROW);
|
||||||
|
ENDERMAN = getById("enderman");
|
||||||
|
ENDERMAN$registryId = getRegistryId(ENDERMAN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public final class EntityDataUtils {
|
|||||||
public static final int CUSTOM_NAME_DATA_ID = 2;
|
public static final int CUSTOM_NAME_DATA_ID = 2;
|
||||||
public static final int ITEM_DATA_ID = 8;
|
public static final int ITEM_DATA_ID = 8;
|
||||||
public static final int ITEM_FRAME_DATA_ID = VersionHelper.isOrAbove1_21_6() ? 9 : 8;
|
public static final int ITEM_FRAME_DATA_ID = VersionHelper.isOrAbove1_21_6() ? 9 : 8;
|
||||||
|
public static final int ENDERMAN_OPTIONAL_BLOCK_STATE = 16;
|
||||||
|
|
||||||
public static byte encodeTextDisplayMask(boolean hasShadow, boolean isSeeThrough, boolean useDefaultBackground, int alignment) {
|
public static byte encodeTextDisplayMask(boolean hasShadow, boolean isSeeThrough, boolean useDefaultBackground, int alignment) {
|
||||||
int bitMask = 0;
|
int bitMask = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user