mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-31 12:56:28 +00:00
feat(entity): 添加快乐恶魂及其相关实体数据
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package net.momirealms.craftengine.bukkit.entity.data;
|
||||
|
||||
public class AgeableMobData<T> extends PathfinderMobData<T> {
|
||||
public static final MobData<Boolean> Baby = new AgeableMobData<>(16, EntityDataValue.Serializers$BOOLEAN, false);
|
||||
|
||||
public AgeableMobData(int id, Object serializer, T defaultValue) {
|
||||
super(id, serializer, defaultValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.bukkit.entity.data;
|
||||
|
||||
public class AnimalData<T> extends AgeableMobData<T> {
|
||||
|
||||
public AnimalData(int id, Object serializer, T defaultValue) {
|
||||
super(id, serializer, defaultValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.craftengine.bukkit.entity.data;
|
||||
|
||||
public class HappyGhastData<T> extends AnimalData<T> {
|
||||
public static final HappyGhastData<Boolean> IsLeashHolder = new HappyGhastData<>(17, EntityDataValue.Serializers$BOOLEAN, false);
|
||||
public static final BaseEntityData<Boolean> StaysStill = new HappyGhastData<>(18, EntityDataValue.Serializers$BOOLEAN, false);
|
||||
|
||||
public HappyGhastData(int id, Object serializer, T defaultValue) {
|
||||
super(id, serializer, defaultValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.bukkit.entity.data;
|
||||
|
||||
public class PathfinderMobData<T> extends MobData<T> {
|
||||
|
||||
public PathfinderMobData(int id, Object serializer, T defaultValue) {
|
||||
super(id, serializer, defaultValue);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.command.feature;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.data.HappyGhastData;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
@@ -12,7 +13,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bukkit.parser.location.LocationParser;
|
||||
import org.incendo.cloud.parser.standard.StringArrayParser;
|
||||
import org.incendo.cloud.parser.standard.IntegerParser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,37 +30,34 @@ public class TestCommand extends BukkitCommandFeature<CommandSender> {
|
||||
return builder
|
||||
.senderType(Player.class)
|
||||
.required("location", LocationParser.locationParser())
|
||||
// .required("remove", StringArrayParser.stringArrayParser())
|
||||
.required("remove", IntegerParser.integerParser())
|
||||
.handler(context -> {
|
||||
Player player = context.sender();
|
||||
// String[] removeEntityIds = context.get("remove");
|
||||
// int removeHitboxId = Integer.parseInt(removeEntityIds[0]);
|
||||
// int removePlayerId = Integer.parseInt(removeEntityIds[1]);
|
||||
// if (removeHitboxId >= 0 && removePlayerId >= 0) {
|
||||
// try {
|
||||
// Object packet = NetworkReflections.constructor$ClientboundRemoveEntitiesPacket.newInstance((Object) new int[]{removeHitboxId, removePlayerId});
|
||||
// plugin().adapt(player).sendPacket(packet, true);
|
||||
// player.sendMessage("发送成功");
|
||||
// } catch (ReflectiveOperationException e) {
|
||||
// player.sendMessage("发送失败");
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
int removeEntityId = context.get("remove");
|
||||
if (removeEntityId >= 0) {
|
||||
try {
|
||||
Object packet = NetworkReflections.constructor$ClientboundRemoveEntitiesPacket.newInstance((Object) new int[]{removeEntityId});
|
||||
plugin().adapt(player).sendPacket(packet, true);
|
||||
player.sendMessage("发送成功");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
player.sendMessage("发送失败");
|
||||
}
|
||||
return;
|
||||
}
|
||||
Location location = context.get("location");
|
||||
// int hitboxId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
int playerId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
int entityId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
List<Object> packets = new ArrayList<>();
|
||||
// packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
|
||||
// hitboxId, UUID.randomUUID(), location.x(), location.y(), location.z(), 0, location.getYaw(),
|
||||
// MEntityTypes.HAPPY_GHAST, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||
// ));
|
||||
List<Object> cachedShulkerValues = new ArrayList<>();
|
||||
HappyGhastData.MobFlags.addEntityDataIfNotDefaultValue((byte) 0x01, cachedShulkerValues); // NO AI
|
||||
// HappyGhastData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, cachedShulkerValues); // Invisible
|
||||
HappyGhastData.StaysStill.addEntityDataIfNotDefaultValue(true, cachedShulkerValues);
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
|
||||
playerId, UUID.randomUUID(), location.x(), location.y()/* + 4*/, location.z(), 0, location.getYaw(),
|
||||
MEntityTypes.PLAYER, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||
entityId, UUID.randomUUID(), location.x(), location.y(), location.z(), 0, location.getYaw(),
|
||||
MEntityTypes.HAPPY_GHAST, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||
));
|
||||
player.sendMessage("player: " + MEntityTypes.PLAYER);
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityId, List.copyOf(cachedShulkerValues)));
|
||||
plugin().adapt(player).sendPackets(packets, true);
|
||||
player.sendMessage("发送成功 id: [" + /*hitboxId + ", " +*/ playerId + "]");
|
||||
player.sendMessage("发送成功 id: " + entityId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user