2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2019-02-10 22:57:03 +00:00
|
|
|
* Copyright (c) 2016-2019.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2014-12-12 19:47:27 +00:00
|
|
|
package net.minecraftforge.client;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
2018-09-08 20:34:59 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
2014-12-12 19:47:27 +00:00
|
|
|
|
2018-09-08 20:34:59 +00:00
|
|
|
import com.google.common.collect.Maps;
|
2018-06-27 18:29:09 +00:00
|
|
|
|
2014-12-12 19:47:27 +00:00
|
|
|
import net.minecraft.client.renderer.ItemModelMesher;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
2018-07-29 01:55:33 +00:00
|
|
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.client.renderer.block.model.ModelManager;
|
|
|
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
2014-12-12 19:47:27 +00:00
|
|
|
import net.minecraft.item.Item;
|
2018-07-29 01:55:33 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2017-07-05 21:52:29 +00:00
|
|
|
import net.minecraftforge.registries.IRegistryDelegate;
|
2014-12-12 19:47:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper around ItemModeMesher that cleans up the internal maps to respect ID remapping.
|
|
|
|
*/
|
|
|
|
public class ItemModelMesherForge extends ItemModelMesher
|
|
|
|
{
|
2018-09-08 20:34:59 +00:00
|
|
|
final Map<IRegistryDelegate<Item>, ModelResourceLocation> locations = Maps.newHashMap();
|
|
|
|
final Map<IRegistryDelegate<Item>, IBakedModel> models = Maps.newHashMap();
|
2014-12-12 19:47:27 +00:00
|
|
|
|
|
|
|
public ItemModelMesherForge(ModelManager manager)
|
|
|
|
{
|
|
|
|
super(manager);
|
|
|
|
}
|
|
|
|
|
2017-06-18 01:24:17 +00:00
|
|
|
@Override
|
2018-07-29 01:55:33 +00:00
|
|
|
@Nullable
|
2018-09-22 10:40:22 +00:00
|
|
|
public IBakedModel getItemModel(Item item)
|
2014-12-12 19:47:27 +00:00
|
|
|
{
|
2018-09-08 20:34:59 +00:00
|
|
|
return models.get(item.delegate);
|
2014-12-12 19:47:27 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 01:24:17 +00:00
|
|
|
@Override
|
2018-09-22 10:40:22 +00:00
|
|
|
public void register(Item item, ModelResourceLocation location)
|
2014-12-12 19:47:27 +00:00
|
|
|
{
|
2017-07-05 21:52:29 +00:00
|
|
|
IRegistryDelegate<Item> key = item.delegate;
|
2018-09-08 20:34:59 +00:00
|
|
|
locations.put(key, location);
|
|
|
|
models.put(key, getModelManager().getModel(location));
|
2014-12-12 19:47:27 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 01:24:17 +00:00
|
|
|
@Override
|
2014-12-12 19:47:27 +00:00
|
|
|
public void rebuildCache()
|
|
|
|
{
|
|
|
|
final ModelManager manager = this.getModelManager();
|
2018-09-08 20:34:59 +00:00
|
|
|
for (Map.Entry<IRegistryDelegate<Item>, ModelResourceLocation> e : locations.entrySet())
|
2014-12-12 19:47:27 +00:00
|
|
|
{
|
2018-09-08 20:34:59 +00:00
|
|
|
models.put(e.getKey(), manager.getModel(e.getValue()));
|
2014-12-12 19:47:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 01:55:33 +00:00
|
|
|
|
|
|
|
public ModelResourceLocation getLocation(@Nonnull ItemStack stack)
|
|
|
|
{
|
2018-09-08 20:34:59 +00:00
|
|
|
ModelResourceLocation location = locations.get(stack.getItem().delegate);
|
2018-07-29 01:55:33 +00:00
|
|
|
|
|
|
|
if (location == null)
|
|
|
|
{
|
|
|
|
location = ModelBakery.MODEL_MISSING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return location;
|
|
|
|
}
|
2014-12-12 19:47:27 +00:00
|
|
|
}
|