예제 #1
0
 public static void onRegisterItems(ItemModelMesher mesher) {
   for (Map.Entry<RegistryDelegate<Item>, ItemMeshDefinition> e :
       customMeshDefinitions.entrySet()) {
     mesher.register(e.getKey().get(), e.getValue());
   }
   for (Entry<Pair<RegistryDelegate<Item>, Integer>, ModelResourceLocation> e :
       customModels.entrySet()) {
     mesher.register(e.getKey().getLeft().get(), e.getKey().getRight(), e.getValue());
   }
 }
예제 #2
0
  @EventHandler
  public void init(FMLInitializationEvent event) {
    FMLCommonHandler.instance().bus().register(this);

    ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
    for (Entry<Item, String> entry : itemModels.entrySet())
      mesher.register(entry.getKey(), 0, new ModelResourceLocation(entry.getValue(), "inventory"));
    for (Entry<Block, String> entry : blockModels.entrySet())
      mesher.register(
          Item.getItemFromBlock(entry.getKey()),
          0,
          new ModelResourceLocation(entry.getValue(), "inventory"));
  }
예제 #3
0
  @SideOnly(Side.CLIENT)
  @SubscribeEvent(priority = EventPriority.LOWEST)
  public void bakeModels(ModelBakeEvent event) {
    ItemModelMesher itemModelMesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
    for (Object object : jsonDestroyer.objectsToDestroy) {
      if (object instanceof Block && object instanceof ITexturedBlock) {
        ITexturedBlock textureProvdier = (ITexturedBlock) object;
        Block block = (Block) object;
        for (int i = 0; i < textureProvdier.amountOfStates(); i++) {
          HashMap<EnumFacing, TextureAtlasSprite> textureMap =
              new HashMap<EnumFacing, TextureAtlasSprite>();
          for (EnumFacing side : EnumFacing.VALUES) {
            for (BlockIconInfo iconInfo : blockIconInfoList) {
              if (iconInfo.getBlock() == block
                  && iconInfo.getMeta() == i
                  && iconInfo.getSide() == side) {
                if (blockIconList.containsKey(iconInfo))
                  textureMap.put(side, blockIconList.get(iconInfo));
              }
            }
          }
          if (textureMap.isEmpty()) {
            return;
          }

          BlockModel model =
              new BlockModel(
                  textureMap, block.getStateFromMeta(i).getBlock() instanceof IOpaqueBlock);
          ModelResourceLocation modelResourceLocation =
              getModelResourceLocation(block.getStateFromMeta(i));
          //                    if(event.modelManager.getModel(modelResourceLocation) !=
          // event.modelManager.getMissingModel()){
          //                        FMLLog.info("Model found @ " + modelResourceLocation.toString()
          // + ", this means a resource pack is overriding it or a modder is doing something bad.
          // JSON-Destoyer will not attempt to create a model for it.");
          //                        continue;
          //                    }
          event.modelRegistry.putObject(modelResourceLocation, model);
          ModelResourceLocation inventory = getBlockinventoryResourceLocation(block);
          //                    if(event.modelManager.getModel(inventory) !=
          // event.modelManager.getMissingModel()){
          //                        FMLLog.info("Model found @ " + inventory.toString() + ", this
          // means a resource pack is overriding it or a modder is doing something bad.
          // JSON-Destoyer will not attempt to create a model for it.");
          //                        continue;
          //                    }
          event.modelRegistry.putObject(inventory, model);
          itemModelMesher.register(Item.getItemFromBlock(block), i, inventory);
          event.modelRegistry.putObject(modelResourceLocation, model);
          itemModelMesher.register(Item.getItemFromBlock(block), i, modelResourceLocation);
        }
      } else if (object instanceof ITexturedFluid && object instanceof BlockFluidBase) {
        final BlockFluidBase fluid = (BlockFluidBase) object;
        final ModelResourceLocation fluidLocation =
            new ModelResourceLocation(fluid.getFluid().getFlowing(), "fluid");
        //                if(event.modelManager.getModel(fluidLocation) !=
        // event.modelManager.getMissingModel()){
        //                    FMLLog.info("Model found @ " + fluidLocation.toString() + ", this
        // means a resource pack is overriding it or a modder is doing something bad. JSON-Destoyer
        // will not attempt to create a model for it.");
        //                    continue;
        //                }
        Item fluidItem = Item.getItemFromBlock(fluid);
        ModelBakery.addVariantName(fluidItem);
        ModelLoader.setCustomMeshDefinition(
            fluidItem,
            new ItemMeshDefinition() {
              public ModelResourceLocation getModelLocation(ItemStack stack) {
                return fluidLocation;
              }
            });
        ModelLoader.setCustomStateMapper(
            fluid,
            new StateMapperBase() {
              protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
                return fluidLocation;
              }
            });

        for (int i = 0; i < 16; i++) {
          ModelResourceLocation location =
              new ModelResourceLocation(getBlockResourceLocation(fluid), "level=" + i);
          if (event.modelManager.getModel(location) != event.modelManager.getMissingModel()) {
            FMLLog.info(
                "Model found @ "
                    + location.toString()
                    + ", this means a resource pack is overriding it or a modder is doing something bad. JSON-Destoyer will not attempt to create a model for it.");
            continue;
          }
          ModelFluid modelFluid = new ModelFluid(fluid.getFluid());
          Function<ResourceLocation, TextureAtlasSprite> textureGetter =
              new Function<ResourceLocation, TextureAtlasSprite>() {
                public TextureAtlasSprite apply(ResourceLocation location) {
                  return fluidIcons.get(fluid);
                }
              };
          IFlexibleBakedModel bakedModel =
              modelFluid.bake(
                  modelFluid.getDefaultState(), DefaultVertexFormats.BLOCK, textureGetter);

          event.modelRegistry.putObject(location, bakedModel);
        }
        ModelResourceLocation inventoryLocation =
            new ModelResourceLocation(getBlockResourceLocation(fluid), "inventory");
        //                if(event.modelManager.getModel(inventoryLocation) !=
        // event.modelManager.getMissingModel()){
        //                    FMLLog.info("Model found @ " + inventoryLocation.toString() + ", this
        // means a resource pack is overriding it or a modder is doing something bad. JSON-Destoyer
        // will not attempt to create a model for it.");
        //                    continue;
        //                }
        ModelFluid modelFluid = new ModelFluid(fluid.getFluid());
        Function<ResourceLocation, TextureAtlasSprite> textureGetter =
            new Function<ResourceLocation, TextureAtlasSprite>() {
              public TextureAtlasSprite apply(ResourceLocation location) {
                return fluidIcons.get(fluid);
              }
            };
        IFlexibleBakedModel bakedModel =
            modelFluid.bake(modelFluid.getDefaultState(), DefaultVertexFormats.ITEM, textureGetter);

        event.modelRegistry.putObject(inventoryLocation, bakedModel);
      } else if (object instanceof Item && object instanceof ITexturedItem) {
        ITexturedItem iTexturedItem = (ITexturedItem) object;
        Item item = (Item) object;
        for (int i = 0; i < iTexturedItem.getMaxMeta(); i++) {
          TextureAtlasSprite texture = null;
          ItemIconInfo itemIconInfo = null;
          for (ItemIconInfo info : itemIcons) {
            if (info.damage == i && info.getItem() == item && info.isBucket == false) {
              texture = info.getSprite();
              itemIconInfo = info;
              break;
            }
          }
          if (texture == null) {
            break;
          }

          ModelResourceLocation inventory;
          inventory = getItemInventoryResourceLocation(item);

          if (iTexturedItem.getMaxMeta() != 1) {
            if (item.getModel(new ItemStack(item, 1, i), Minecraft.getMinecraft().thePlayer, 0)
                != null) {
              inventory =
                  item.getModel(new ItemStack(item, 1, i), Minecraft.getMinecraft().thePlayer, 0);
            }
          }
          //                    if(event.modelManager.getModel(inventory) !=
          // event.modelManager.getMissingModel()){
          //                        FMLLog.info("Model found @ " + inventory.toString() + ", this
          // means a resource pack is overriding it or a modder is doing something bad.
          // JSON-Destoyer will not attempt to create a model for it.");
          //                        continue;
          //                    }

          final TextureAtlasSprite finalTexture = texture;
          Function<ResourceLocation, TextureAtlasSprite> textureGetter =
              new Function<ResourceLocation, TextureAtlasSprite>() {
                public TextureAtlasSprite apply(ResourceLocation location) {
                  return finalTexture;
                }
              };
          ImmutableList.Builder<ResourceLocation> builder = ImmutableList.builder();
          builder.add(new ResourceLocation(itemIconInfo.textureName));
          CustomModel itemLayerModel = new CustomModel(builder.build());
          IBakedModel model =
              itemLayerModel.bake(
                  ItemLayerModel.instance.getDefaultState(),
                  DefaultVertexFormats.ITEM,
                  textureGetter);
          itemModelMesher.register(item, i, inventory);
          event.modelRegistry.putObject(inventory, model);
        }
      } else if (object instanceof Item && object instanceof ITexturedBucket) {
        ITexturedBucket iTexturedBucket = (ITexturedBucket) object;
        Item item = (Item) object;
        for (int i = 0; i < iTexturedBucket.getMaxMeta(); i++) {
          ModelResourceLocation inventory;
          inventory = getItemInventoryResourceLocation(item);
          if (iTexturedBucket.getMaxMeta() != 1) {
            if (item.getModel(new ItemStack(item, 1, i), Minecraft.getMinecraft().thePlayer, 0)
                != null) {
              inventory =
                  item.getModel(new ItemStack(item, 1, i), Minecraft.getMinecraft().thePlayer, 0);
            }
          }
          //                    if(event.modelManager.getModel(inventory) !=
          // event.modelManager.getMissingModel()){
          //                        FMLLog.info("Model found @ " + inventory.toString() + ", this
          // means a resource pack is overriding it or a modder is doing something bad.
          // JSON-Destoyer will not attempt to create a model for it.");
          //                        continue;
          //                    }
          Function<ResourceLocation, TextureAtlasSprite> textureGetter;
          textureGetter =
              new Function<ResourceLocation, TextureAtlasSprite>() {
                public TextureAtlasSprite apply(ResourceLocation location) {
                  return Minecraft.getMinecraft()
                      .getTextureMapBlocks()
                      .getAtlasSprite(location.toString());
                }
              };
          ModelDynBucket modelDynBucket =
              new ModelDynBucket(
                  new ResourceLocation("forge:items/bucket_base"),
                  new ResourceLocation("forge:items/bucket_fluid"),
                  new ResourceLocation("forge:items/bucket_cover"),
                  iTexturedBucket.getFluid(i),
                  iTexturedBucket.isGas(i));

          IBakedModel model =
              modelDynBucket.bake(
                  ItemLayerModel.instance.getDefaultState(),
                  DefaultVertexFormats.ITEM,
                  textureGetter);
          itemModelMesher.register(item, i, inventory);
          event.modelRegistry.putObject(inventory, model);
        }
      }
    }
  }