本文整理汇总了Java中org.inventivetalent.reflection.minecraft.Minecraft类的典型用法代码示例。如果您正苦于以下问题:Java Minecraft类的具体用法?Java Minecraft怎么用?Java Minecraft使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Minecraft类属于org.inventivetalent.reflection.minecraft包,在下文中一共展示了Minecraft类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onMove
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
@EventHandler
public void onMove(final PlayerMoveEvent e) {
if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) {
final BossBar bar = BossBarAPI.getBossBar(e.getPlayer());
if (bar != null) {
new BukkitRunnable() {
@Override
public void run() {
if (!e.getPlayer().isOnline()) {
return;
}
bar.updateMovement();
}
}.runTaskLater(PACore.getInstance(), 0);
}
}
}
开发者ID:cadox8,项目名称:PA,代码行数:19,代码来源:BossBarAPI.java
示例2: buildPacketPlayOutBed
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static Object buildPacketPlayOutBed(int id, int x, int y, int z) {
try {
Class<?> packetClass = Reflection.nmsClassResolver.resolve("PacketPlayOutBed");
Object bedPacket = packetClass.newInstance();
AccessUtil.setAccessible(packetClass.getDeclaredField("a")).set(bedPacket, id);
if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) {
AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(bedPacket, x);
AccessUtil.setAccessible(packetClass.getDeclaredField("c")).set(bedPacket, y);
AccessUtil.setAccessible(packetClass.getDeclaredField("d")).set(bedPacket, z);
} else {
AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(bedPacket, Reflection.nmsClassResolver.resolve("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(x, y, z));
}
return bedPacket;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:18,代码来源:ClassBuilder.java
示例3: buildPacketPlayOutEntityTeleport
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static Object buildPacketPlayOutEntityTeleport(int id, double x, double y, double z, float yaw, float pitch, boolean onGround, boolean heightCorrection) {
try {
Class<?> packetClass = Reflection.nmsClassResolver.resolve("PacketPlayOutEntityTeleport");
Object teleportPacket;
if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) {
teleportPacket = packetClass.getConstructor(int.class, int.class, int.class, int.class, byte.class, byte.class, boolean.class, boolean.class)
.newInstance(id, floor(x * 32.0D), floor(y * 32.0D), floor(z * 32.0D), (byte) (int) (yaw * 256F / 360F), (byte) (int) (pitch * 256F / 360F), onGround, heightCorrection);
} else if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) {
teleportPacket = packetClass.getConstructor(int.class, int.class, int.class, int.class, byte.class, byte.class, boolean.class)
.newInstance(id, floor(x * 32.0D), floor(y * 32.0D), floor(z * 32.0D), (byte) (int) (yaw * 256F / 360F), (byte) (int) (pitch * 256F / 360F), onGround);
} else {
teleportPacket = packetClass.newInstance();
AccessUtil.setAccessible(packetClass.getDeclaredField("a")).set(teleportPacket, id);
AccessUtil.setAccessible(packetClass.getDeclaredField("b")).set(teleportPacket, x);
AccessUtil.setAccessible(packetClass.getDeclaredField("c")).set(teleportPacket, y);
AccessUtil.setAccessible(packetClass.getDeclaredField("d")).set(teleportPacket, z);
AccessUtil.setAccessible(packetClass.getDeclaredField("e")).set(teleportPacket, (byte) (int) (yaw * 256F / 360F));
AccessUtil.setAccessible(packetClass.getDeclaredField("f")).set(teleportPacket, (byte) (int) (pitch * 256F / 360F));
AccessUtil.setAccessible(packetClass.getDeclaredField("g")).set(teleportPacket, onGround);
}
return teleportPacket;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:27,代码来源:ClassBuilder.java
示例4: checkExtraVersionConditions
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
static boolean checkExtraVersionConditions(ExtraMethod annotation) {
Minecraft.Version currentVersion = Minecraft.VERSION;
if (annotation.forVersion().length == 0 && annotation.fromVersion() == Minecraft.Version.UNKNOWN && annotation.untilVersion() == Minecraft.Version.UNKNOWN) {
// No version condition specified, just generate it
return true;
}
if (annotation.fromVersion() != Minecraft.Version.UNKNOWN && currentVersion.newerThan(annotation.fromVersion())) {
return true;
}
if (annotation.untilVersion() != Minecraft.Version.UNKNOWN && currentVersion.olderThan(annotation.untilVersion())) {
return true;
}
if (annotation.forVersion().length > 0) {
for (Minecraft.Version version : annotation.forVersion()) {
if (version == currentVersion) {
return true;
}
}
}
return false;
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:25,代码来源:ClassGenerator.java
示例5: injectEntity
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
static void injectEntity(Class<?> clazz, int id, String name) {
Class<?> EntityTypes = Reflection.nmsClassResolver.resolveSilent("EntityTypes");
if(Minecraft.VERSION.newerThan(Minecraft.Version.v1_11_R1)) {
MethodResolver methodResolver = new MethodResolver(EntityTypes);
MethodWrapper method = methodResolver.resolveWrapper(new ResolverQuery("a", int.class,
String.class, Class.class, String.class));
if(method.exists()) {
method.getMethod().setAccessible(true);
method.invoke(null, id, name, clazz, name);
} else {
NPCLib.logger.warning("Could not inject " + clazz.getSimpleName() + " as " + name +
" with id " + id + " due to incompatible Minecraft verson!");
}
} else {
FieldResolver fieldResolver = new FieldResolver(EntityTypes);
((Map) fieldResolver.resolveWrapper("c").get(null)).put(name, clazz);
((Map) fieldResolver.resolveWrapper("d").get(null)).put(clazz, name);
((Map) fieldResolver.resolveWrapper("f").get(null)).put(clazz, Integer.valueOf(id));
}
NPCLib.logger.info("Injected " + clazz.getSimpleName() + " as " + name + " with id " + id);
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:23,代码来源:NPCRegistry.java
示例6: createEntity
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
protected <T extends NPCEntity> T createEntity(Location location, NPCInfo npcInfo) {
if ("EntityPlayer".equals(npcInfo.getNms())) {
throw new IllegalArgumentException("cannot construct EntityPlayer using #createEntity");
}
Class<?> clazz = getOrGenerateClass(npcInfo);
try {
// noinspection unchecked
Constructor<?> constructor = clazz.getConstructor(Reflection.nmsClassResolver.resolve("World"));
// noinspection unchecked
return (T) constructor.newInstance(Minecraft.getHandle(location.getWorld()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:17,代码来源:NPCRegistry.java
示例7: createPlayerEntity
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
protected EntityPlayer createPlayerEntity(Location location, NPCInfo npcInfo, GameProfileWrapper gameProfile) {
Class<?> clazz = getOrGenerateClass(npcInfo);
try {
Object minecraftServer = new MethodResolver(Bukkit.getServer().getClass()).resolveWrapper("getServer")
.invoke(Bukkit.getServer());
Object worldServer = Minecraft.getHandle(location.getWorld());
Object interactManager = new ConstructorResolver(
Reflection.nmsClassResolver.resolve("PlayerInteractManager"))
.resolve(new Class[] { Reflection.nmsClassResolver.resolve("World") })
.newInstance(worldServer);
// noinspection unchecked
Constructor<?> constructor = clazz.getConstructor(Reflection.nmsClassResolver.resolve("MinecraftServer"),
Reflection.nmsClassResolver.resolve("WorldServer"), gameProfile.getHandle().getClass(),
Reflection.nmsClassResolver.resolve("PlayerInteractManager"));
return (EntityPlayer) constructor.newInstance(minecraftServer, worldServer, gameProfile.getHandle(),
interactManager);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:22,代码来源:NPCRegistry.java
示例8: sendPacket
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
protected void sendPacket(Player player, Object packet) {
if (player == null || packet == null) { return; }
if (player == this.getNpcEntity() || player == this.getBukkitEntity()) { return; }
if (NPCLib.isNPC(player)) { return; }
try {
Object handle = Minecraft.getHandle(player);
if (handle != null) {
Object connection = AccessUtil.setAccessible(handle.getClass().getDeclaredField("playerConnection")).get(handle);
if (connection != null) {
new MethodResolver(connection.getClass()).resolve("sendPacket").invoke(connection, packet);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:17,代码来源:NPCAbstract.java
示例9: setProfile
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
protected void setProfile(GameProfileWrapper profile) {
try {
UUID uuid = profile.getId();
if (uuid == null) {
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + profile.getName()).getBytes(Charsets.UTF_8));
}
if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1)) {
Method method = new MethodResolver(Reflection.nmsClassResolver.resolve("Entity")).resolve(new ResolverQuery("a", UUID.class));
method.invoke(getNpcEntity(), uuid);
}
Field field = new FieldResolver(Reflection.nmsClassResolver.resolve("EntityHuman")).resolveByFirstType(GameProfile.class);
field.set(getNpcEntity(), profile.getHandle());
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
refreshScoreboard();
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:19,代码来源:NPCPlayer.java
示例10: removeOnDeath
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
protected void removeOnDeath(SuperSwitch superSwitch) {
if (!superSwitch.isCancelled()) {
if (getBukkitEntity().isDead()) { return; }
if (getPlugin() == null || !getPlugin().isEnabled()) { return; }
// Remove players from the world manually
Bukkit.getScheduler().runTaskLater(getPlugin(), new Runnable() {
@Override
public void run() {
try {
Reflection.nmsClassResolver.resolve("World").getDeclaredMethod("removeEntity", Reflection.nmsClassResolver.resolve("Entity")).invoke(Minecraft.getHandle(getBukkitEntity().getWorld()), getNpcEntity());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, 40);// <-- death animation delay
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:18,代码来源:NPCPlayer.java
示例11: applyTextureToSkull
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static void applyTextureToSkull(Skull skull, Object profile) throws Exception {
Location location = skull.getLocation();
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
Object world = Minecraft.getHandle(location.getWorld());
Object tileEntity = WorldServerMethodResolver.resolve("getTileEntity").invoke(world, x, y, z);
TileEntitySkullFieldResolver.resolveByFirstType(GameProfile).set(tileEntity, profile);
WorldMethodResolver.resolve(new ResolverQuery("notify", int.class, int.class, int.class)).invoke(world, x, y, z);
}
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:11,代码来源:HeadTextureChanger.java
示例12: send
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
void send(Collection<? extends Player> receivers, double x, double y, double z, double offsetX, double offsetY, double offsetZ, double speed, int count, int... extra) {
if (!this.effect.isCompatible()) {
throw new ParticleException("Particle " + this.effect + " is not compatible with the server version (" + Minecraft.VERSION + " < " + this.effect.getMinVersion() + ")");
}
try {
if (Minecraft.VERSION.newerThan(v1_8_R1)) {
send_1_8(receivers, x, y, z, offsetX, offsetY, offsetZ, speed, count, extra);
} else {//1.7
send_1_7(effect.name, receivers, x, y, z, offsetX, offsetY, offsetZ, speed, count);
}
} catch (Exception e) {
throw new ParticleException("Failed to send particle " + this.effect + " to " + receivers.toString(), e);
}
}
开发者ID:cadox8,项目名称:PA,代码行数:15,代码来源:ParticleEffect.java
示例13: parseAnnotationVersions
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
/**
* Parses an annotation to the current server version. Removes all entries
* that don't match the version, but keeps the original order for matching
* names.
*
* @param clazz Class of the annotation
* @param annotation annotation
* @param <A> annotation type
* @return a list of matching names
*/
<A extends Annotation> List<String> parseAnnotationVersions(java.lang.Class<A> clazz, A annotation) {
List<String> list = new ArrayList<>();
try {
String[] names = (String[]) clazz.getMethod("value").invoke(annotation);
Minecraft.Version[] versions = (Minecraft.Version[]) clazz.getMethod("versions").invoke(annotation);
if (versions.length == 0) {// No versions specified -> directly use the names
for (String name : names) {
list.add(name);
}
} else {
if (versions.length > names.length) {
throw new RuntimeException("versions array cannot have more elements than the names (" + clazz + ")");
}
for (int i = 0; i < versions.length; i++) {
if (Minecraft.VERSION == versions[i]) {// Wohoo, perfect match!
list.add(names[i]);
} else {
if (names[i].startsWith(">") && Minecraft.VERSION.newerThan(versions[i])) {// Match if the current version is newer
list.add(names[i].substring(1));
} else if (names[i].startsWith("<") && Minecraft.VERSION.olderThan(versions[i])) {// Match if the current version is older
list.add(names[i].substring(1));
}
}
}
}
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
return list;
}
开发者ID:cadox8,项目名称:PA,代码行数:44,代码来源:ReflectionAnnotations.java
示例14: resolve
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
@Override
public Class resolve(String... names) throws ClassNotFoundException {
for (int i = 0; i < names.length; i++) {
if (!names[i].startsWith("org.bukkit.craftbukkit")) {
names[i] = "org.bukkit.craftbukkit." + Minecraft.getVersion() + names[i];
}
}
return super.resolve(names);
}
开发者ID:cadox8,项目名称:PA,代码行数:10,代码来源:OBCClassResolver.java
示例15: resolve
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
@Override
public Class resolve(String... names) throws ClassNotFoundException {
for (int i = 0; i < names.length; i++) {
if (!names[i].startsWith("net.minecraft.server")) {
names[i] = "net.minecraft.server." + Minecraft.getVersion() + names[i];
}
}
return super.resolve(names);
}
开发者ID:cadox8,项目名称:PA,代码行数:10,代码来源:NMSClassResolver.java
示例16: buildWitherSpawnPacket
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static Object buildWitherSpawnPacket(int id, UUID uuid/*UUID*/, Location loc, Object dataWatcher) throws Exception {
Object packet = NMSClass.PacketPlayOutSpawnEntityLiving.newInstance();
if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) {
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("a")).set(packet, id);
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("b")).set(packet, 64);// TODO: Find correct entity type id
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("c")).set(packet, (int) loc.getX());
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("d")).set(packet, MathUtil.floor(loc.getY() * 32D));
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("e")).set(packet, (int) loc.getZ());
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("i")).set(packet, (byte) MathUtil.d(loc.getYaw() * 256F / 360F));
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("j")).set(packet, (byte) MathUtil.d(loc.getPitch() * 256F / 360F));
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("k")).set(packet, (byte) MathUtil.d(loc.getPitch() * 256F / 360F));
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("l")).set(packet, dataWatcher);
} else {
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("a")).set(packet, id);
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("b")).set(packet, uuid);
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("c")).set(packet, 64);
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("d")).set(packet, loc.getX());
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("e")).set(packet, loc.getY());
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("f")).set(packet, loc.getZ());
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("j")).set(packet, (byte) MathUtil.d(loc.getYaw() * 256F / 360F));
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("k")).set(packet, (byte) MathUtil.d(loc.getPitch() * 256F / 360F));
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("l")).set(packet, (byte) MathUtil.d(loc.getPitch() * 256F / 360F));
AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("m")).set(packet, dataWatcher);
}
return packet;
}
开发者ID:cadox8,项目名称:PA,代码行数:30,代码来源:ClassBuilder.java
示例17: buildNameMetadataPacket
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static Object buildNameMetadataPacket(int id, Object dataWatcher, int nameIndex, int visibilityIndex, String name) throws Exception {
// dataWatcher = setDataWatcherValue(dataWatcher, nameIndex, name != null ? name : "");// Pass an empty string to avoid exceptions
// dataWatcher = setDataWatcherValue(dataWatcher, visibilityIndex, (byte) (name != null && !name.isEmpty() ? 1 : 0));
DataWatcher.setValue(dataWatcher, nameIndex, ENTITY_NAME, name != null ? name : "");// Pass an empty string to avoid exceptions
DataWatcher.setValue(dataWatcher, visibilityIndex, ENTITY_NAME_VISIBLE, Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1) ? (byte) (name != null && !name.isEmpty() ? 1 : 0) : (name != null && !name.isEmpty()));//Byte < 1.9, Boolean >= 1.9
Object metaPacket = NMSClass.PacketPlayOutEntityMetadata.getConstructor(int.class, NMSClass.DataWatcher, boolean.class).newInstance(id, dataWatcher, true);
return metaPacket;
}
开发者ID:cadox8,项目名称:PA,代码行数:10,代码来源:ClassBuilder.java
示例18: getEntityFromDamageSource
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static Entity getEntityFromDamageSource(Object damageSource) {
if (damageSource == null) { return null; }
try {
Class<?> classDamageSource = nmsClassResolver.resolve("DamageSource");
Object nmsEntity = classDamageSource.getDeclaredMethod("getEntity").invoke(damageSource);
if (nmsEntity == null) { return null; }
return Minecraft.getBukkitEntity(nmsEntity);
} catch (ReflectiveOperationException e) {
throw new RuntimeException();
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:12,代码来源:Reflection.java
示例19: getEntityById
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static Entity getEntityById(World world, int id) {
try {
Field mapField = AccessUtil.setAccessible(nmsClassResolver.resolve("World").getDeclaredField("entitiesById"));
Object nmsEntity = nmsClassResolver.resolve("IntHashMap").getDeclaredMethod("get", int.class).invoke(mapField.get(Minecraft.getHandle(world)), id);
return nmsEntity == null ? null : Minecraft.getBukkitEntity(nmsEntity);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:10,代码来源:Reflection.java
示例20: getDataWatcher
import org.inventivetalent.reflection.minecraft.Minecraft; //导入依赖的package包/类
public static Object getDataWatcher(org.bukkit.entity.Entity ent) {
try {
return nmsClassResolver.resolve("Entity").getDeclaredMethod("getDataWatcher").invoke(Minecraft.getHandle(ent));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:9,代码来源:Reflection.java
注:本文中的org.inventivetalent.reflection.minecraft.Minecraft类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论