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(); }
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); } }
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()); } }
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); } }
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); } }
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); } }
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); } }
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(); }
@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()]); }
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(); } }
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()); }
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, Predicate<T> filter) { /** * Create a new PropertyEnum with the specified values */ return create(name, clazz, Collections2.<T>filter(Lists.newArrayList(clazz.getEnumConstants()), filter)); }
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, T... values) { /** * Create a new PropertyEnum with the specified values */ return create(name, clazz, Lists.newArrayList(values)); }
@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); }
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); }
/** * 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)); }
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")); } } } }
private static <T extends Enum<T> & IStringSerializable> void registerVariantsDefaulted( Block b, Class<T> enumclazz, String variantHeader) { Item item = Item.getItemFromBlock(b); for (T e : enumclazz.getEnumConstants()) { String variantName = variantHeader + "=" + e.getName().toLowerCase(); ModelLoader.setCustomModelResourceLocation(item, e.ordinal(), new ModelResourceLocation(b.getRegistryName(), variantName)); } }
public static <T extends Enum<T> & IStringSerializable> void registerModel(Block block, Class<T> clazz) { Item item = Item.getItemFromBlock(block); if (item == Items.AIR) throw new UnsupportedOperationException("This block has no Item!"); registerModel(item, clazz); }
/** * Get the name for the given value. */ public String getName(T value) { return ((IStringSerializable)value).getName(); }
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz) { return create(name, clazz, Predicates.<T>alwaysTrue()); }
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, Predicate<T> filter) { return create(name, clazz, Collections2.<T>filter(Lists.newArrayList(clazz.getEnumConstants()), filter)); }
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, T... values) { return create(name, clazz, Lists.newArrayList(values)); }
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, Collection<T> values) { return new PropertyEnum(name, clazz, values); }