当前位置: 首页>>代码示例>>Java>>正文


Java MinecraftReflection类代码示例

本文整理汇总了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;
}
 
开发者ID:elsiff,项目名称:MoreFish,代码行数:23,代码来源:SkullUtils.java

示例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)));
}
 
开发者ID:andylizi,项目名称:LaserLib,代码行数:24,代码来源:NMSUtil.java

示例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();
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:15,代码来源:Attributes.java

示例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();
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:29,代码来源:EntityUtils.java

示例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;
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:13,代码来源:ItemStackGenerator.java

示例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);
}
 
开发者ID:Limeth,项目名称:Breakpoint,代码行数:10,代码来源:Attributes.java

示例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);
}
 
开发者ID:andylizi,项目名称:LaserLib,代码行数:8,代码来源:DummyEntityImpl.java

示例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)));
}
 
开发者ID:andylizi,项目名称:LaserLib,代码行数:19,代码来源:NMSUtil.java

示例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);
}
 
开发者ID:andylizi,项目名称:LaserLib,代码行数:40,代码来源:NMSUtil.java

示例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);
}
 
开发者ID:andylizi,项目名称:LaserLib,代码行数:21,代码来源:NMSUtil.java

示例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);
}
 
开发者ID:FastFelix771,项目名称:TownyWands,代码行数:9,代码来源:ItemWrapper.java

示例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;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:9,代码来源:RPProtocolLib.java

示例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);
	}
}
 
开发者ID:yushijinhun,项目名称:AdvancedCommands,代码行数:11,代码来源:ReflectionHelper.java

示例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);
	}
}
 
开发者ID:yushijinhun,项目名称:AdvancedCommands,代码行数:11,代码来源:ReflectionHelper.java

示例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);
	}
}
 
开发者ID:yushijinhun,项目名称:AdvancedCommands,代码行数:9,代码来源:ReflectionHelper.java


注:本文中的com.comphenix.protocol.utility.MinecraftReflection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。