use of com.comphenix.protocol.wrappers.nbt.NbtWrapper in project WheelCore by Plugindustry.
the class NBTBasedProvider method getOreDictionary.
@Nonnull
@Override
@SuppressWarnings("unchecked")
public Set<String> getOreDictionary(@Nullable ItemStack itemStack) {
if (itemStack == null)
return Collections.emptySet();
Set<String> defaultOreDict = getInstance(itemStack) == null ? ItemMapping.getVanillaOreDict(itemStack.getType()) : Collections.emptySet();
Optional<NbtWrapper<?>> nbtWrapperOptional = NbtFactory.fromItemOptional((ItemStack) ShadowManager.shadowUnpack(CraftItemStack.asCraftCopy(itemStack)));
if (nbtWrapperOptional.isEmpty())
return defaultOreDict;
NbtWrapper<?> nbtWrapper = nbtWrapperOptional.get();
if (nbtWrapper.getType() != NbtType.TAG_COMPOUND)
return defaultOreDict;
NbtCompound compound = NbtFactory.asCompound(nbtWrapper);
if (!compound.containsKey("wheel_core_item_ore_dictionary"))
return defaultOreDict;
Object data = compound.getObject("wheel_core_item_ore_dictionary");
if ((!(data instanceof NbtList)) || ((NbtList<?>) data).getElementType() != NbtType.TAG_STRING)
return defaultOreDict;
return ((NbtList<String>) data).asCollection().stream().map(NbtBase::getValue).collect(Collectors.toSet());
}
use of com.comphenix.protocol.wrappers.nbt.NbtWrapper in project LibsDisguises by libraryaddict.
the class ReflectionManager method convertInvalidMeta.
public static Object convertInvalidMeta(Object value) {
if (value instanceof Optional) {
Optional opt = (Optional) value;
if (!opt.isPresent()) {
return NmsVersion.v1_13.isSupported() ? value : com.google.common.base.Optional.absent();
}
if (nmsReflection != null) {
return nmsReflection.convertOptional(opt.get());
}
Object val = opt.get();
if (val instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) val;
try {
Object obj = blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (val instanceof WrappedBlockData) {
try {
Object obj = ((WrappedBlockData) val).getHandle();
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (val instanceof ItemStack) {
val = getNmsItem((ItemStack) val);
if (val == null) {
return NmsVersion.v1_13.isSupported() ? Optional.empty() : com.google.common.base.Optional.absent();
} else {
return Optional.of(val);
}
} else if (val instanceof WrappedChatComponent) {
Object obj = ((WrappedChatComponent) val).getHandle();
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
} else if (!NmsVersion.v1_13.isSupported()) {
return com.google.common.base.Optional.of(val);
} else {
return Optional.of(val);
}
} else if (value instanceof Vector3F) {
Vector3F angle = (Vector3F) value;
if (nmsReflection != null) {
return nmsReflection.convertVec3(angle);
}
try {
return vector3FConstructor.newInstance(angle.getX(), angle.getY(), angle.getZ());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof EulerAngle) {
EulerAngle angle = (EulerAngle) value;
if (nmsReflection != null) {
return nmsReflection.convertVec3(angle);
}
try {
return vector3FConstructor.newInstance((float) angle.getX(), (float) angle.getY(), (float) angle.getZ());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof Direction) {
if (nmsReflection != null) {
return nmsReflection.convertDirection((Direction) value);
}
try {
return enumDirectionFrom.invoke(null, ((Direction) value).ordinal());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) value;
if (nmsReflection != null) {
return nmsReflection.getBlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
try {
return blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof ItemStack) {
return getNmsItem((ItemStack) value);
} else if (value instanceof Double) {
return ((Double) value).floatValue();
} else if (value instanceof NbtWrapper) {
return ((NbtWrapper) value).getHandle();
} else if (value instanceof WrappedParticle) {
return ((WrappedParticle) value).getHandle();
} else if (value instanceof EntityPose) {
return getNmsEntityPose((EntityPose) value);
} else if (value instanceof VillagerData) {
return getNmsVillagerData((VillagerData) value);
} else if (value instanceof WrappedChatComponent) {
return ((WrappedChatComponent) value).getHandle();
}
return value;
}
use of com.comphenix.protocol.wrappers.nbt.NbtWrapper in project WheelCore by Plugindustry.
the class NBTBasedProvider method getInstance.
@Nullable
@Override
public ItemBase getInstance(@Nullable ItemStack itemStack) {
if (itemStack == null)
return null;
Optional<NbtWrapper<?>> nbtWrapperOptional = NbtFactory.fromItemOptional((ItemStack) ShadowManager.shadowUnpack(CraftItemStack.asCraftCopy(itemStack)));
if (nbtWrapperOptional.isEmpty())
return null;
NbtWrapper<?> nbtWrapper = nbtWrapperOptional.get();
if (nbtWrapper.getType() != NbtType.TAG_COMPOUND)
return null;
NbtCompound compound = NbtFactory.asCompound(nbtWrapper);
if (!compound.containsKey("wheel_core_item_type"))
return null;
Object type = compound.getObject("wheel_core_item_type");
return type instanceof String ? MainManager.getItemInstanceFromId((String) type) : null;
}
use of com.comphenix.protocol.wrappers.nbt.NbtWrapper in project WheelCore by Plugindustry.
the class NBTBasedProvider method getData.
@Nullable
@Override
public ItemData getData(@Nullable ItemStack itemStack) {
if (itemStack == null)
return null;
Optional<NbtWrapper<?>> nbtWrapperOptional = NbtFactory.fromItemOptional((ItemStack) ShadowManager.shadowUnpack(CraftItemStack.asCraftCopy(itemStack)));
if (nbtWrapperOptional.isEmpty())
return null;
NbtWrapper<?> nbtWrapper = nbtWrapperOptional.get();
if (nbtWrapper.getType() != NbtType.TAG_COMPOUND)
return null;
NbtCompound compound = NbtFactory.asCompound(nbtWrapper);
if (!compound.containsKey("wheel_core_item_data"))
return null;
Object data = compound.getObject("wheel_core_item_data");
return data instanceof String ? gson.fromJson((String) data, ItemData.class) : null;
}
Aggregations