本文整理匯總了Java中net.minecraft.util.IStringSerializable類的典型用法代碼示例。如果您正苦於以下問題:Java IStringSerializable類的具體用法?Java IStringSerializable怎麽用?Java IStringSerializable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IStringSerializable類屬於net.minecraft.util包,在下文中一共展示了IStringSerializable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toVanilla
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
public static String toVanilla(IBlockState state) {
StringBuilder result = new StringBuilder();
Set<Entry<IProperty<?>, Comparable<?>>> entries = state.getProperties().entrySet();
Iterator<Entry<IProperty<?>, Comparable<?>>> iter = entries.iterator();
while(iter.hasNext()) {
Entry<IProperty<?>, Comparable<?>> entry = iter.next();
result.append(entry.getKey().getName());
result.append('=');
Comparable<?> value = entry.getValue();
if (value instanceof IStringSerializable) {
result.append(((IStringSerializable)value).getName());
} else {
result.append(entry.getValue().toString());
}
if (iter.hasNext()) result.append(',');
}
return result.toString();
}
示例2: PropertyEnum
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
protected PropertyEnum(String name, Class<T> valueClass, Collection<T> allowedValues)
{
super(name, valueClass);
this.allowedValues = ImmutableSet.copyOf(allowedValues);
for (T t : allowedValues)
{
String s = ((IStringSerializable)t).getName();
if (this.nameToValue.containsKey(s))
{
throw new IllegalArgumentException("Multiple values have the same name \'" + s + "\'");
}
this.nameToValue.put(s, t);
}
}
示例3: registerVariantBlocks
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
private void registerVariantBlocks(ProxyModBase proxy) {
for (InfoBlock block : proxy.blocks) {
if (!(block instanceof InfoBlockVariant))
continue;
InfoBlockVariant blockVar = (InfoBlockVariant) block;
List<String> variants = Lists.newArrayList();
for (Object metalObj : blockVar.getVariantProp().getAllowedValues()) {
IStringSerializable value = (IStringSerializable) metalObj;
String name = proxy.getModId() + ":" + value.getName() + blockVar.getVariantSuffix();
variants.add(name);
}
ModelBakery.registerItemVariants(Item.getItemFromBlock(block.getBlock()),
variants.stream().map(ResourceLocation::new).toArray(ResourceLocation[]::new));
ModelLoader.setCustomStateMapper(block.getBlock(),
(new StateMap.Builder()).withName(blockVar.getVariantProp())
.withSuffix(blockVar.getVariantSuffix())
.build());
}
}
示例4: PropertyClass
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
protected PropertyClass(String name, Class valueClass, Collection allowedValues)
{
super(name, valueClass);
this.allowedValues = ImmutableSet.copyOf(allowedValues);
Iterator iterator = allowedValues.iterator();
while (iterator.hasNext())
{
IStringSerializable oenum = (IStringSerializable)iterator.next();
String s1 = oenum.getName();
if (this.nameToValue.containsKey(s1))
{
throw new IllegalArgumentException("Multiple values have the same name \'" + s1 + "\'");
}
this.nameToValue.put(s1, oenum);
}
}
示例5: valueName
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
protected String valueName(Object value) {
if (value == null) {
return "null";
} else if (value instanceof IStringSerializable) {
return ((IStringSerializable) value).getName();
} else if (value instanceof Enum) {
return ((Enum<?>) value).name().toLowerCase(Locale.ROOT);
} else {
return value.toString().toLowerCase(Locale.ROOT);
}
}
示例6: registerModel
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
public static <T extends Enum<T> & IStringSerializable> void registerModel(Item item, Class<T> clazz) {
for (T t : clazz.getEnumConstants()) {
ResourceLocation location = new ResourceLocation(item.getRegistryName() + "_" + t.getName());
ModelResourceLocation modelResourceLocation = new ModelResourceLocation(location, "inventory");
ModelLoader.setCustomModelResourceLocation(item, t.ordinal(), modelResourceLocation);
}
}
示例7: registerModel
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
public static <T extends Enum<T> & IStringSerializable> void registerModel(Item item, Class<T> clazz) {
for(T t : clazz.getEnumConstants()) {
ResourceLocation location = new ResourceLocation(item.getRegistryName() + "_" + t.getName());
ModelResourceLocation modelResourceLocation = new ModelResourceLocation(location, "inventory");
ModelLoader.setCustomModelResourceLocation(item, t.ordinal(), modelResourceLocation);
}
}
示例8: from
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
public static <T extends Enum<T> & IStringSerializable> ImmutableMap<T, ResourceLocation> from(Class<T> clazz, String name, Function<String, ResourceLocation> function) {
ImmutableMap.Builder<T, ResourceLocation> builder = ImmutableMap.builder();
T[] enums = clazz.getEnumConstants();
for(T enu : enums) {
builder.put(enu, function.apply(name + enu.getName()));
}
return builder.build();
}
示例9: getModelLocations
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
@Override
public String[] getModelLocations() {
ArrayList<String> variants = new ArrayList<String>();
for(Enum<T> t : enumValues) {
if (t instanceof IStringSerializable) {
variants.add(id + "." + ((IStringSerializable)t).getName() );
} else {
variants.add(id + "." + t.name().toLowerCase());
}
}
return variants.toArray(new String[variants.size()]);
}
示例10: getValueName
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
private static Object getValueName(Comparable p_getValueName_0_)
{
if (p_getValueName_0_ instanceof IStringSerializable)
{
IStringSerializable istringserializable = (IStringSerializable)p_getValueName_0_;
return istringserializable.getName();
}
else
{
return p_getValueName_0_.toString();
}
}
示例11: create
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz)
{
/**
* Create a new PropertyEnum with all Enum constants of the given class that match the given Predicate.
*/
return create(name, clazz, Predicates.<T>alwaysTrue());
}
示例12: toLua
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
@Override
public <T> Object toLua(T value) throws ConversionException {
checkNotNull(value, "value==null!");
if (value instanceof TableData) {
TableData data = (TableData) value;
return tableDataConverter.toLua(data);
}
@SuppressWarnings("unchecked")
Class<T> javaClass = (Class<T>) value.getClass();
LuaClass<T, ?> cls = getByJavaClass(javaClass);
if (cls != null) {
return cls.getLuaInstance(value);
}
if (value instanceof Enum) {
Enum<?> vEnum = (Enum<?>) value;
if (vEnum instanceof IStringSerializable) {
return ByteString.of(((IStringSerializable) vEnum).getName());
}
return ByteString.of(vEnum.name());
}
if (value instanceof IStringSerializable) {
return ByteString.of(((IStringSerializable) value).getName());
}
return super.toLua(value);
}
示例13: toLua
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
public static Object toLua(Comparable<?> obj) {
if (obj instanceof IStringSerializable) {
IStringSerializable s = (IStringSerializable) obj;
return s.getName();
}
if (obj instanceof Enum) {
Enum<?> e = (Enum<?>) obj;
return e.name();
}
if (obj instanceof String) {
String str = (String) obj;
if ("true".equals(obj)) {
return true;
}
if ("false".equals(obj)) {
return false;
}
Object result = Ints.tryParse(str);
if (result != null) {
return result;
}
result = Doubles.tryParse(str);
if (result != null) {
return result;
}
}
return Conversions.canonicalRepresentationOf(obj);
}
示例14: registerSlabGroup
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
/**
* Register a group of slab blocks
*
* @param slabGroup The slab group
*/
@SuppressWarnings("unchecked")
private static <
VARIANT extends Enum<VARIANT> & IStringSerializable,
VARIANTS extends Iterable<VARIANT> & IStringSerializable,
SLAB extends BlockSlabAquaRegia<VARIANT, VARIANTS, SLAB>
> void registerSlabGroup(BlockSlabAquaRegia.SlabGroup<VARIANT, VARIANTS, SLAB> slabGroup) {
registerBlock(slabGroup.singleSlab, slab -> new ItemSlab(slab, slabGroup.singleSlab, slabGroup.doubleSlab));
registerBlock(slabGroup.doubleSlab, null); // No item form for the double slab
slabGroup.setItem((ItemSlab) Item.getItemFromBlock(slabGroup.singleSlab));
}
示例15: registerBlocksItemModels
import net.minecraft.util.IStringSerializable; //導入依賴的package包/類
private void registerBlocksItemModels(ProxyModBase proxy) {
for (InfoBlock block : proxy.blocks) {
if (block instanceof InfoBlockVariant) {
InfoBlockVariant blockVar = (InfoBlockVariant) block;
for (Object valueObj : blockVar.getVariantProp().getAllowedValues()) {
IStringSerializable value = (IStringSerializable) valueObj;
String name = proxy.getModId() + ":" + value.getName() + blockVar.getVariantSuffix();
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block.getBlock()),
blockVar.getMeta(value), new ModelResourceLocation(name, "inventory"));
}
} else {
ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(block.getBlock()),
new SimpleItemMeshDefinition(proxy.getModId() + ":" + block.getName()));
}
}
for (InfoItem item : proxy.items) {
if (item.getVariants() == null) {
ModelLoader.setCustomMeshDefinition(item.getItem(),
new SimpleItemMeshDefinition(item.getDomain() + ":" + item.getName()));
} else {
int i = 0;
for (String variant : item.getVariants()) {
ModelLoader.setCustomModelResourceLocation(item.getItem(), i++,
new ModelResourceLocation(item.getDomain() + ":" + variant, "inventory"));
}
}
}
}