本文整理汇总了Java中com.comphenix.protocol.utility.MinecraftReflection类的典型用法代码示例。如果您正苦于以下问题:Java MinecraftReflection类的具体用法?Java MinecraftReflection怎么用?Java MinecraftReflection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MinecraftReflection类属于com.comphenix.protocol.utility包,在下文中一共展示了MinecraftReflection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSkullTexture
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
public static ItemStack setSkullTexture(ItemStack itemStack, String value) {
ItemStack newStack = itemStack;
if (!MinecraftReflection.isCraftItemStack(itemStack)) {
newStack = MinecraftReflection.getBukkitItemStack(itemStack);
}
NbtCompound tag = (NbtCompound) NbtFactory.fromItemTag(newStack);
NbtCompound skullOwner = NbtFactory.ofCompound("SkullOwner");
NbtCompound properties = NbtFactory.ofCompound("Properties");
NbtCompound compound = NbtFactory.ofCompound("");
compound.put("Value", value);
NbtList<NbtCompound> textures = NbtFactory.ofList("textures", compound);
properties.put(textures);
skullOwner.put("Id", UUID.randomUUID().toString());
skullOwner.put(properties);
tag.put(skullOwner);
NbtFactory.setItemTag(newStack, tag);
return newStack;
}
示例2: createLivingEntitySpawnPacket
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
/**
* 创建用于生成生物实体的数据包.
* @param entity NMS EntityLiving.
* @return 包含所用数据包的集合.
* @throws ReflectiveOperationException 如果创建失败.
*/
public static Collection<PacketContainer> createLivingEntitySpawnPacket(Object entity) throws ReflectiveOperationException{
if(CONST_PACKET_SPAWN_ENTITY_LIVING == null){
CONST_PACKET_SPAWN_ENTITY_LIVING = PacketType.Play.Server.SPAWN_ENTITY_LIVING.getPacketClass()
.getConstructor(MinecraftReflection.getMinecraftClass("EntityLiving"));
CONST_PACKET_SPAWN_ENTITY_LIVING.setAccessible(true);
}
if(CONST_PACKET_ENTITY_METADATA == null){
CONST_PACKET_ENTITY_METADATA = PacketType.Play.Server.ENTITY_METADATA.getPacketClass()
.getConstructor(int.class, MinecraftReflection.getDataWatcherClass(), boolean.class);
CONST_PACKET_ENTITY_METADATA.setAccessible(true);
}
return Arrays.asList(
new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING,
CONST_PACKET_SPAWN_ENTITY_LIVING.newInstance(entity)),
new PacketContainer(PacketType.Play.Server.ENTITY_METADATA,
CONST_PACKET_ENTITY_METADATA.newInstance(readEntityId(entity), readDataWatcher(entity), true)));
}
示例3: setAttribute
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
private void setAttribute(String type, double speed) {
try {
Method getAttributeMethod = MinecraftReflection.getMinecraftClass("EntityLiving")
.getMethod("getAttributeInstance", MinecraftReflection.getMinecraftClass("IAttribute"));
Field iAttributeField = MinecraftReflection.getMinecraftClass("GenericAttributes").getField(type);
Object attribute = getAttributeMethod.invoke(this.entity, iAttributeField.get(null));
Method aMethod = MinecraftReflection.getMinecraftClass("AttributeInstance").getMethod("setValue", double.class);
aMethod.invoke(attribute, speed);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
e.printStackTrace();
}
}
示例4: goPetToPlayer
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
public static void goPetToPlayer(final Player player, final LivingEntity entity) {
if (!InventoryManager.playerIsLoaded(player) || !player.isOnline() || entity.isDead()) {
return;
}
Location target = player.getLocation();
if (target.distance(entity.getLocation()) > 20) {
PetManager.respawnPet(player);
} else if (target.distance(entity.getLocation()) < 4) {
return;
}
PetType petType = PetManager.getPetFromEntity(entity, player);
double speedModifier = petType == null ? 1.0 : 0.4 / petType.getSpeed();
Class<?> entityInsentientClass = MinecraftReflection.getMinecraftClass("EntityInsentient");
Class<?> navigationAbstractClass = MinecraftReflection.getMinecraftClass("NavigationAbstract");
try {
Method getHandle = MinecraftReflection.getCraftEntityClass().getDeclaredMethod("getHandle");
Object insentient = entityInsentientClass.cast(getHandle.invoke(entity));
Object navigation = entityInsentientClass.getDeclaredMethod("getNavigation").invoke(insentient);
navigationAbstractClass.getDeclaredMethod("a", double.class, double.class, double.class, double.class)
.invoke(navigation, target.getX(), target.getY(), target.getZ(), speedModifier);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
示例5: removeAttributes
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
private static ItemStack removeAttributes(ItemStack item) {
if (!MinecraftReflection.isCraftItemStack(item)) {
item = MinecraftReflection.getBukkitItemStack(item);
}
try {
NbtCompound compound = (NbtCompound) NbtFactory.fromItemTag(item);
compound.put(NbtFactory.ofList("AttributeModifiers"));
} catch (IllegalArgumentException e) {
return item;
}
return item;
}
示例6: Attributes
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
public Attributes(ItemStack stack)
{
// Create a CraftItemStack (under the hood)
this.stack = MinecraftReflection.getBukkitItemStack(stack);
// Load NBT
NbtCompound nbt = (NbtCompound) NbtFactory.fromItemTag(this.stack);
attributes = nbt.getListOrDefault("AttributeModifiers");
attributes.setElementType(NbtType.TAG_COMPOUND);
}
示例7: DummyEntityImpl
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
public DummyEntityImpl(Object entity) throws IllegalArgumentException, ReflectiveOperationException{
this.entity = Objects.requireNonNull(entity);
if(!MinecraftReflection.isMinecraftEntity(entity))
throw new IllegalArgumentException();
this.entityId = NMSUtil.readEntityId(entity);
this.living = MinecraftReflection.getMinecraftClass("EntityLiving").isInstance(entity);
}
示例8: createEntitySpawnPacket
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
/**
* 创建用于生成实体对象的数据包.
* @param entity NMS Entity.
* @param objectType 对象类型.
* @param objectData 对象附加数据.
* @return 包含所用数据包的集合.
* @throws ReflectiveOperationException 如果创建失败.
*/
public static Collection<PacketContainer> createEntitySpawnPacket(Object entity, int objectType, int objectData) throws ReflectiveOperationException{
if(CONST_PACKET_SPAWN_ENTITY == null){
CONST_PACKET_SPAWN_ENTITY = PacketType.Play.Server.SPAWN_ENTITY.getPacketClass()
.getConstructor(MinecraftReflection.getMinecraftClass("Entity"), int.class, int.class);
CONST_PACKET_SPAWN_ENTITY.setAccessible(true);
}
return Arrays.asList(new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY,
CONST_PACKET_SPAWN_ENTITY.newInstance(entity, objectType, objectData)));
}
示例9: createDummyGuardian
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
/**
* 构造一个虚拟守卫者的实例.
* @param pos 生成位置.
* @param isElder 是否为远古守卫者.
* @param target 守卫者的目标的实体ID.
* @return 虚拟守卫者的表示对象.
* @throws ReflectiveOperationException 如果创建失败.
*/
public static DummyEntity createDummyGuardian(Location pos, boolean isElder, int target)
throws ReflectiveOperationException{
boolean useIndependentElderGuardian = isElder && ABOVE_EXPLORATION_UPDATE;
if(CONST_ENTITY_GURADIAN == null){
CONST_ENTITY_GURADIAN = MinecraftReflection.getMinecraftClass("EntityGuardian")
.getConstructor(MinecraftReflection.getNmsWorldClass());
CONST_ENTITY_GURADIAN.setAccessible(true);
}
if(useIndependentElderGuardian && CONST_ENTITY_ELDER_GUARDIAN == null){
CONST_ENTITY_ELDER_GUARDIAN = MinecraftReflection.getMinecraftClass("EntityGuardianElder")
.getConstructor(MinecraftReflection.getNmsWorldClass());
CONST_ENTITY_ELDER_GUARDIAN.setAccessible(true);
}
Object entity = (useIndependentElderGuardian ? CONST_ENTITY_ELDER_GUARDIAN : CONST_ENTITY_GURADIAN)
.newInstance(bukkitUnwrapper.unwrapItem(pos.getWorld()));
WrappedDataWatcher dataWatcher = new WrappedDataWatcher(readDataWatcher(entity));
WOBJ_ENTITY_FLAGS.set(dataWatcher, (byte) 0x20); // 0x20 Invisible
WOBJ_GUARDIAN_TARGET.set(dataWatcher, target); // Target EID
if(isElder)
if(ABOVE_BOUNTIFUL_UPDATE){ // 1.9+
if(ABOVE_EXPLORATION_UPDATE){ // 1.11+
WOBJ_GUARDIAN_FLAGS.set(dataWatcher, true); // true RetractingSpikes
}else{ // 1.9 - 1.10
WOBJ_GUARDIAN_FLAGS.set(dataWatcher, (byte) (0x2 | 0x4)); // 0x2 RetractingSpikes | 0x4 Elder
}
}else{ // 1.8
WOBJ_GUARDIAN_FLAGS.set(dataWatcher, 0x2 | 0x4); // 0x2 RetractingSpikes | 0x4 Elder
}
writeEntityData(entity, pos, dataWatcher.getHandle());
return new DummyEntityImpl(entity);
}
示例10: createDummyArmorStand
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
/**
* 构造一个虚拟隐形盔甲架的实例.
* @param pos 生成位置.
* @return 虚拟盔甲架的表示对象.
* @throws ReflectiveOperationException 如果创建失败.
*/
public static DummyEntity createDummyArmorStand(Location pos)
throws ReflectiveOperationException{
if(CONST_ENTITY_ARMORSTAND == null){
CONST_ENTITY_ARMORSTAND = MinecraftReflection.getMinecraftClass("EntityArmorStand")
.getConstructor(MinecraftReflection.getNmsWorldClass());
CONST_ENTITY_ARMORSTAND.setAccessible(true);
}
Object entity = CONST_ENTITY_ARMORSTAND.newInstance(bukkitUnwrapper.unwrapItem(pos.getWorld()));
WrappedDataWatcher dataWatcher = new WrappedDataWatcher(FieldUtils.readField(entity, "datawatcher", true));
WOBJ_ENTITY_FLAGS.set(dataWatcher, (byte) 0x20); // 0 - 0x20 Invisible
WOBJ_ARMORSTAND_FLAGS.set(dataWatcher, (byte) (0x1 | 0x8 | 0x10)); // 11 - (0x1 Small | 0x8 NoBasePlate | 0x10 Marker)
writeEntityData(entity, pos, dataWatcher.getHandle());
return new DummyEntityImpl(entity);
}
示例11: wrap
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
@SneakyThrows( {InvocationTargetException.class, IllegalAccessException.class} )
public static ItemWrapper wrap(@NonNull ItemStack source) {
if(!MinecraftReflection.isCraftItemStack(source)) {
return new ItemWrapper((ItemStack) Reflect.getMethod(MinecraftReflection.getCraftItemStackClass(), "asCraftCopy", ItemStack.class).invoke(Reflect.STATIC, source));
}
return new ItemWrapper(source);
}
示例12: removeAttributes
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
public static ItemStack removeAttributes(ItemStack item) {
if (!MinecraftReflection.isCraftItemStack(item)) {
item = MinecraftReflection.getBukkitItemStack(item);
}
NbtCompound compound = (NbtCompound) NbtFactory.fromItemTag(item);
compound.put(NbtFactory.ofList("AttributeModifiers"));
return item;
}
示例13: getEntityIOMethods
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
private static void getEntityIOMethods() {
try {
IOMethodsFinder finder = new IOMethodsFinder(MinecraftReflection.getEntityClass());
finder.find();
entityReadMethod = finder.readMethod;
entityWriteMethod = finder.writeMethod;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例14: getTileEntityIOMethods
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
private static void getTileEntityIOMethods() {
try {
IOMethodsFinder finder = new IOMethodsFinder(MinecraftReflection.getTileEntityClass());
finder.find();
tileEntityReadMethod = finder.readMethod;
tileEntityWriteMethod = finder.writeMethod;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例15: getTileEntityUpdateMethod
import com.comphenix.protocol.utility.MinecraftReflection; //导入依赖的package包/类
private static void getTileEntityUpdateMethod() {
try {
// TODO: Use ASM to find method if you can
tileEntityUpdateMethod = MinecraftReflection.getTileEntityClass().getMethod("update");
} catch (Exception e) {
throw new RuntimeException(e);
}
}