mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
Adding a way to add costum wood models
This commit is contained in:
1 parent
9a05322d45
commit
fb8ddf54b7
4 files changed
+169
-7
No files matched your search
@@ -1,7 +1,8 @@
|
||||
package forestry.api.arboriculture;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
@@ -25,8 +26,8 @@ public enum WoodBlockKind {
|
||||
return super.toString().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public IModel retextureModel(IModel model, IWoodType type){
|
||||
ImmutableMap.Builder<String, String> textures = new ImmutableMap.Builder();
|
||||
public IModel retextureModel(IModel model, IWoodType type, ImmutableMap<String, String> customTextures){
|
||||
Map<String, String> textures = new HashMap<>();
|
||||
switch (this) {
|
||||
case SLAB:
|
||||
case STAIRS:
|
||||
@@ -61,6 +62,7 @@ public enum WoodBlockKind {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ModelProcessingHelper.retexture(model, textures.build());
|
||||
textures.putAll(customTextures);
|
||||
return ModelProcessingHelper.retexture(model, new ImmutableMap.Builder<String, String>().putAll(textures).build());
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forestry.api.arboriculture.EnumForestryWoodType;
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
@@ -54,6 +55,7 @@ import forestry.arboriculture.items.ItemCharcoal;
|
||||
import forestry.arboriculture.items.ItemGrafter;
|
||||
import forestry.arboriculture.items.ItemRegistryArboriculture;
|
||||
import forestry.arboriculture.models.TextureLeaves;
|
||||
import forestry.arboriculture.models.WoodTextures;
|
||||
import forestry.arboriculture.network.PacketRegistryArboriculture;
|
||||
import forestry.arboriculture.proxy.ProxyArboriculture;
|
||||
import forestry.arboriculture.proxy.ProxyArboricultureClient;
|
||||
@@ -555,6 +557,7 @@ public class PluginArboriculture extends BlankForestryPlugin {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerSprites(TextureStitchEvent.Pre event) {
|
||||
TextureLeaves.registerAllSprites();
|
||||
WoodTextures.deserializeFile();
|
||||
for (IAlleleFruit alleleFruit : AlleleFruit.getFruitAlleles()) {
|
||||
alleleFruit.getProvider().registerSprites();
|
||||
}
|
||||
@@ -565,6 +568,11 @@ public class PluginArboriculture extends BlankForestryPlugin {
|
||||
textures.add(new ResourceLocation(type.getDoorLowerTexture()));
|
||||
textures.add(new ResourceLocation(type.getDoorUpperTexture()));
|
||||
textures.add(new ResourceLocation(type.getPlankTexture()));
|
||||
for(WoodBlockKind kind : WoodBlockKind.values()){
|
||||
for(Entry<String, String> loc : WoodTextures.getLocations(type, kind).entrySet()){
|
||||
textures.add(new ResourceLocation(loc.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
for(ResourceLocation loc : textures){
|
||||
TextureManager.getInstance();
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package forestry.arboriculture.models;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.core.render.FontColour;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class WoodTextures {
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().create();
|
||||
protected static final Map<String, Texture> textures = new HashMap<>();
|
||||
protected static KindTexture kindTextures;
|
||||
|
||||
public static void deserializeFile(){
|
||||
try {
|
||||
InputStream stream = FontColour.class.getResourceAsStream("/assets/forestry/textures/woodTextures.json");
|
||||
if(stream != null){
|
||||
JsonReader reader = null;
|
||||
try {
|
||||
reader = new JsonReader(new BufferedReader(new InputStreamReader(stream)));
|
||||
JsonElement json = Streams.parse(reader);
|
||||
if(json.isJsonObject()){
|
||||
for(Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()){
|
||||
JsonElement ele = entry.getValue();
|
||||
if(ele.isJsonObject()){
|
||||
textures.put(entry.getKey(), loadTexture(ele.getAsJsonObject()));
|
||||
}else if(ele.isJsonArray()){
|
||||
ImmutableMap.Builder<String, SimpleTexture> locations = new ImmutableMap.Builder<>();
|
||||
for(JsonElement eleEntry : ele.getAsJsonArray()){
|
||||
if(eleEntry.isJsonObject()){
|
||||
JsonObject obj = eleEntry.getAsJsonObject();
|
||||
if(!obj.has("kind") || !obj.get("kind").isJsonPrimitive() || !obj.get("kind").getAsJsonPrimitive().isString()){
|
||||
continue;
|
||||
}
|
||||
String kind = obj.get("kind").getAsString();
|
||||
locations.put(kind, loadTexture(obj));
|
||||
}
|
||||
}
|
||||
textures.put(entry.getKey(), new KindTexture(locations.build()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}finally{
|
||||
if(reader != null){
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static SimpleTexture loadTexture(JsonObject obj){
|
||||
ImmutableMap.Builder<String, String> locations = new ImmutableMap.Builder<>();
|
||||
for(Entry<String, JsonElement> eleEntry : obj.entrySet()){
|
||||
JsonElement e = eleEntry.getValue();
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString()){
|
||||
locations.put(eleEntry.getKey(), e.getAsString());
|
||||
}
|
||||
}
|
||||
return new SimpleTexture(locations.build());
|
||||
}
|
||||
|
||||
public static ImmutableMap<String, String> getLocations(IWoodType woodType, WoodBlockKind blockKind){
|
||||
if(woodType != null && blockKind != null && woodType.getName() != null){
|
||||
String kindName = blockKind.toString();
|
||||
SimpleTexture kindTex = null;
|
||||
Texture tex = textures.get(woodType.getName().toLowerCase(Locale.ENGLISH));
|
||||
if(kindTextures != null){
|
||||
kindTex = kindTextures.kindLocations.get(kindName);
|
||||
}
|
||||
Map<String, String> locations = new HashMap<>();
|
||||
if(kindTex != null){
|
||||
locations.putAll(kindTex.locations);
|
||||
}
|
||||
if(tex != null){
|
||||
if(tex instanceof SimpleTexture){
|
||||
locations.putAll(((SimpleTexture) tex).locations);
|
||||
}else{
|
||||
SimpleTexture kind = ((KindTexture)tex).kindLocations.get(kindName);
|
||||
locations.putAll(kind.locations);
|
||||
}
|
||||
}
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
|
||||
for(Entry<String, String> location : locations.entrySet()){
|
||||
String texture = location.getValue();
|
||||
if(texture.equals("plank")){
|
||||
texture = woodType.getPlankTexture();
|
||||
}else if(texture.equals("bark")){
|
||||
texture = woodType.getBarkTexture();
|
||||
}else if(texture.equals("heart")){
|
||||
texture = woodType.getHeartTexture();
|
||||
}else if(texture.equals("doorUp")){
|
||||
texture = woodType.getDoorUpperTexture();
|
||||
}else if(texture.equals("doorLow")){
|
||||
texture = woodType.getDoorLowerTexture();
|
||||
}else{
|
||||
builder.put(location.getKey(), texture.replace("%woodType", woodType.getName().toLowerCase(Locale.ENGLISH)));
|
||||
continue;
|
||||
}
|
||||
builder.put(location.getKey(), texture);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
return ImmutableMap.of();
|
||||
}
|
||||
|
||||
private static class Texture{
|
||||
|
||||
}
|
||||
|
||||
private static class SimpleTexture extends Texture{
|
||||
public final ImmutableMap<String, String> locations;
|
||||
|
||||
public SimpleTexture(ImmutableMap<String, String> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
}
|
||||
|
||||
private static class KindTexture extends Texture{
|
||||
public final ImmutableMap<String, SimpleTexture> kindLocations;
|
||||
|
||||
public KindTexture(ImmutableMap<String, SimpleTexture> kindLocations) {
|
||||
this.kindLocations = kindLocations;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,8 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import forestry.api.arboriculture.EnumPileType;
|
||||
import forestry.api.arboriculture.IWoodItemMeshDefinition;
|
||||
import forestry.api.arboriculture.IWoodStateMapper;
|
||||
@@ -49,6 +51,7 @@ import forestry.arboriculture.models.ModelDecorativeLeaves;
|
||||
import forestry.arboriculture.models.ModelLeaves;
|
||||
import forestry.arboriculture.models.ModelWoodPile;
|
||||
import forestry.arboriculture.models.WoodModelLoader;
|
||||
import forestry.arboriculture.models.WoodTextures;
|
||||
import forestry.arboriculture.render.CharcoalPileRenderer;
|
||||
import forestry.arboriculture.tiles.TilePile;
|
||||
import forestry.core.models.BlockModelEntry;
|
||||
@@ -124,14 +127,15 @@ public class ProxyArboricultureClient extends ProxyArboriculture {
|
||||
woodType = woodTyped.getWoodType(0);
|
||||
itemStack = new ItemStack(woodTyped);
|
||||
}
|
||||
ImmutableMap<String, String> customTextures = WoodTextures.getLocations(woodType, woodKind);
|
||||
if(woodKind.retextureItem){
|
||||
ItemMeshDefinition definition = definitions.get(itemStack.getItem());
|
||||
if(definition instanceof IWoodItemMeshDefinition){
|
||||
IWoodItemMeshDefinition woodDefinition = (IWoodItemMeshDefinition) definition;
|
||||
IModel basicItemModel = ModelLoaderRegistry.getModel(woodDefinition.getDefaultModelLocation(itemStack));
|
||||
ModelResourceLocation basicItemLocation = definition.getModelLocation(itemStack);
|
||||
|
||||
registry.putObject(basicItemLocation, new SimpleRetexturedModel(woodKind.retextureModel(basicItemModel, woodType)));
|
||||
|
||||
registry.putObject(basicItemLocation, new SimpleRetexturedModel(woodKind.retextureModel(basicItemModel, woodType, customTextures)));
|
||||
}
|
||||
}
|
||||
IModel basicModel = ModelLoaderRegistry.getModel(woodMapper.getDefaultModelResourceLocation(state));
|
||||
@@ -139,7 +143,7 @@ public class ProxyArboricultureClient extends ProxyArboriculture {
|
||||
if(loadingExceptions.containsKey(basicLocation)){
|
||||
loadingExceptions.remove(basicLocation);
|
||||
}
|
||||
registry.putObject(basicLocation, new SimpleRetexturedModel(woodKind.retextureModel(basicModel, woodType)));
|
||||
registry.putObject(basicLocation, new SimpleRetexturedModel(woodKind.retextureModel(basicModel, woodType, customTextures)));
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in new issue
Block a user