Пример #1
0
 @SideOnly(Side.CLIENT)
 @SubscribeEvent
 public void textureStitch(TextureStitchEvent.Pre event) {
   blockIconInfoList.clear();
   blockIconList.clear();
   fluidIcons.clear();
   itemIcons.clear();
   TextureMap textureMap = event.map;
   for (Object object : jsonDestroyer.objectsToDestroy) {
     if (object instanceof Block && object instanceof ITexturedBlock) {
       ITexturedBlock blockTextureProvider = (ITexturedBlock) object;
       Block block = (Block) object;
       for (int i = 0; i < blockTextureProvider.amountOfStates(); i++) {
         for (EnumFacing side : EnumFacing.values()) {
           String name;
           name = blockTextureProvider.getTextureNameFromState(block.getStateFromMeta(i), side);
           TextureAtlasSprite texture = textureMap.getTextureExtry(name);
           if (texture == null) {
             texture = new CustomTexture(name);
             textureMap.setTextureEntry(name, texture);
           }
           BlockIconInfo iconInfo = new BlockIconInfo(block, i, side);
           blockIconList.put(iconInfo, texture);
           blockIconInfoList.add(iconInfo);
         }
       }
     } else if (object instanceof BlockFluidBase && object instanceof ITexturedFluid) {
       ITexturedFluid fluidTextureProvider = (ITexturedFluid) object;
       String name = fluidTextureProvider.getTextureName();
       TextureAtlasSprite texture = textureMap.getTextureExtry(name);
       if (texture == null) {
         texture = new CustomTexture(name);
         textureMap.setTextureEntry(name, texture);
       }
       fluidIcons.put((BlockFluidBase) object, texture);
     } else if (object instanceof Item && object instanceof ITexturedItem) {
       ITexturedItem itemTexture = (ITexturedItem) object;
       Item item = (Item) object;
       for (int i = 0; i < itemTexture.getMaxMeta(); i++) {
         String name = itemTexture.getTextureName(i);
         TextureAtlasSprite texture = textureMap.getTextureExtry(name);
         if (texture == null) {
           texture = new CustomTexture(name);
           textureMap.setTextureEntry(name, texture);
         }
         ItemIconInfo info = new ItemIconInfo((Item) object, i, texture, name);
         itemIcons.add(info);
       }
     } else if (object instanceof Item && object instanceof ITexturedBucket) {
       ITexturedBucket itemTexture = (ITexturedBucket) object;
       for (int i = 0; i < itemTexture.getMaxMeta(); i++) {
         String name = itemTexture.getFluid(i).getStill().toString();
         TextureAtlasSprite texture = textureMap.getTextureExtry(name);
         if (texture == null) {
           texture = new CustomTexture(name);
           textureMap.setTextureEntry(name, texture);
         }
         ItemIconInfo info = new ItemIconInfo((Item) object, i, texture, name);
         info.isBucket = true;
         itemIcons.add(info);
       }
     }
   }
 }
Пример #2
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);
        }
      }
    }
  }