/** * Safe way of getting the material from an itemstack. */ public static Material getMaterialFromStack(ItemStack stack) { if(!(stack.getItem() instanceof IMaterialItem)) { return Material.UNKNOWN; } return ((IMaterialItem) stack.getItem()).getMaterial(stack); }
@Nonnull @Override public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) { String id = ((IMaterialItem) stack.getItem()).getMaterialID(stack); return ((BakedMaterialModel) originalModel).getModelByIdentifier(id); } }
public <T extends Item & IToolPart> void addCombination(ToolCore toolCore, T toolPart) { toolCores.add(toolCore); ItemStack toolPartItem = toolPart.getItemstackWithMaterial(material); List<ItemStack> stacks = new ArrayList<>(); stacks.add(toolPartItem); stacks.addAll(EMBOSSMENT_ITEMS); addRecipeMatch(new RecipeMatch.ItemCombination(1, stacks.toArray(new ItemStack[stacks.size()]))); }
protected Material getMaterial(ItemStack... stacks) { for(ItemStack stack : stacks) { if(stack.isEmpty()) { continue; } // material-item? if(stack.getItem() instanceof IMaterialItem) { return ((IMaterialItem) stack.getItem()).getMaterial(stack); } } // regular item, check if it belongs to a material for(Material material : TinkerRegistry.getAllMaterials()) { if(material.matches(stacks).isPresent()) { return material; } } // no material found return null; }
Map<Object, Object> out = Maps.newHashMap(); Material material = materialItem.getMaterial(stack); out.put("id", material.getIdentifier()); out.put("name", material.getLocalizedName());