Skip to content

Commit

Permalink
Add new Wood Model Loader (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedelosk authored and mezz committed Aug 12, 2016
1 parent b5faab5 commit eb63e75
Show file tree
Hide file tree
Showing 1,039 changed files with 1,010 additions and 10,034 deletions.
25 changes: 25 additions & 0 deletions src/main/java/forestry/api/arboriculture/EnumForestryWoodType.java
Expand Up @@ -101,4 +101,29 @@ public int getCarbonization() {
public int getCombustability() {
return combustability;
}

@Override
public String getPlankTexture() {
return "forestry:blocks/wood/planks." + getName();
}

@Override
public String getDoorLowerTexture() {
return "forestry:blocks/doors/" + getName() + "_lower";
}

@Override
public String getDoorUpperTexture() {
return "forestry:blocks/doors/" + getName() + "_upper";
}

@Override
public String getBarkTexture() {
return "forestry:blocks/wood/bark." + getName();
}

@Override
public String getHeartTexture() {
return "forestry:blocks/wood/heart." + getName();
}
}
40 changes: 40 additions & 0 deletions src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java
Expand Up @@ -71,4 +71,44 @@ public int getCarbonization() {
public int getCombustability() {
return combustability;
}

@Override
public String getPlankTexture() {
if(this == DARK_OAK){
return "blocks/planks_big_oak";
}
return "blocks/planks_" + getName();
}

@Override
public String getDoorLowerTexture() {
if(this == OAK){
return "blocks/door_wood_lower";
}
return "blocks/door_wood_lower";
}

@Override
public String getDoorUpperTexture() {
if(this == OAK){
return "blocks/door_wood_upper";
}
return "blocks/door_" + getName() + "_upper";
}

@Override
public String getBarkTexture() {
if(this == DARK_OAK){
return "blocks/log_big_oak";
}
return "blocks/log_" + getName();
}

@Override
public String getHeartTexture() {
if(this == DARK_OAK){
return "blocks/log_big_oak_top";
}
return "blocks/log_" + getName() + "_top";
}
}
4 changes: 4 additions & 0 deletions src/main/java/forestry/api/arboriculture/IWoodAccess.java
Expand Up @@ -5,6 +5,8 @@
******************************************************************************/
package forestry.api.arboriculture;

import java.util.List;

import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;

Expand All @@ -22,5 +24,7 @@ public interface IWoodAccess {
ItemStack getStack(IWoodType woodType, WoodBlockKind kind, boolean fireproof);

IBlockState getBlock(IWoodType woodType, WoodBlockKind kind, boolean fireproof);

List<IWoodType> getRegisteredWoodTypes();

}
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.arboriculture;

import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public interface IWoodItemMeshDefinition extends ItemMeshDefinition {

ResourceLocation getDefaultModelLocation(ItemStack stack);

}
21 changes: 21 additions & 0 deletions src/main/java/forestry/api/arboriculture/IWoodStateMapper.java
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.arboriculture;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public interface IWoodStateMapper extends IStateMapper {

ModelResourceLocation getModelResourceLocation(IBlockState state);

ModelResourceLocation getDefaultModelResourceLocation(IBlockState state);

}
10 changes: 10 additions & 0 deletions src/main/java/forestry/api/arboriculture/IWoodType.java
Expand Up @@ -14,4 +14,14 @@ public interface IWoodType extends IStringSerializable {
int getCarbonization();

int getCombustability();

String getPlankTexture();

String getDoorLowerTexture();

String getDoorUpperTexture();

String getBarkTexture();

String getHeartTexture();
}
56 changes: 55 additions & 1 deletion src/main/java/forestry/api/arboriculture/WoodBlockKind.java
Expand Up @@ -2,11 +2,65 @@

import java.util.Locale;

import com.google.common.collect.ImmutableMap;

import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelProcessingHelper;

public enum WoodBlockKind {
LOG, PLANKS, SLAB, FENCE, FENCE_GATE, STAIRS, DOOR;
LOG, PLANKS, SLAB, FENCE, FENCE_GATE, STAIRS, DOOR(false);

public final boolean retextureItem;

private WoodBlockKind() {
this(true);
}

private WoodBlockKind(boolean retextureItem) {
this.retextureItem = retextureItem;
}

@Override
public String toString() {
return super.toString().toLowerCase(Locale.ENGLISH);
}

public IModel retextureModel(IModel model, IWoodType type){
ImmutableMap.Builder<String, String> textures = new ImmutableMap.Builder();
switch (this) {
case SLAB:
case STAIRS:
String textureLocation = type.getPlankTexture();
textures.put("particle", textureLocation);
textures.put("side", textureLocation);
textures.put("top", textureLocation);
textures.put("bottom", textureLocation);
textures.put("all", textureLocation);
break;
case PLANKS:
textures.put("particle", type.getPlankTexture());
textures.put("all", type.getPlankTexture());
break;
case FENCE_GATE:
case FENCE:
textures.put("particle", type.getPlankTexture());
textures.put("side", type.getPlankTexture());
textures.put("texture", type.getPlankTexture());
break;
case DOOR:
textures.put("particle", type.getDoorLowerTexture());
textures.put("bottom", type.getDoorLowerTexture());
textures.put("top", type.getDoorUpperTexture());
break;
case LOG:
textures.put("particle", type.getBarkTexture());
textures.put("side", type.getBarkTexture());
textures.put("all", type.getBarkTexture());
textures.put("end", type.getHeartTexture());
break;
default:
break;
}
return ModelProcessingHelper.retexture(model, textures.build());
}
}
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;

public class CamouflageHandlerArbDoor implements ICamouflageItemHandler {

Expand All @@ -51,7 +52,7 @@ public float getLightTransmittance(ItemStack stack, ICamouflageHandler camouflag

@SideOnly(Side.CLIENT)
@Override
public IBakedModel getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile) {
public Pair<IBlockState, IBakedModel> getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile) {
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0 || !(stack.getItem() instanceof ItemBlockWoodDoor)){
return null;
}
Expand All @@ -71,7 +72,7 @@ public IBakedModel getModel(ItemStack stack, ICamouflageHandler camouflageHandle

BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();

return modelShapes.getModelForState(doorState);
return Pair.of(doorState, modelShapes.getModelForState(doorState));
}

}
2 changes: 1 addition & 1 deletion src/main/java/forestry/arboriculture/IWoodTyped.java
Expand Up @@ -11,8 +11,8 @@
package forestry.arboriculture;

import javax.annotation.Nonnull;
import java.util.Collection;

import java.util.Collection;
import forestry.api.arboriculture.IWoodType;
import forestry.api.arboriculture.WoodBlockKind;

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/forestry/arboriculture/PluginArboriculture.java
Expand Up @@ -56,6 +56,7 @@
import forestry.arboriculture.models.TextureLeaves;
import forestry.arboriculture.network.PacketRegistryArboriculture;
import forestry.arboriculture.proxy.ProxyArboriculture;
import forestry.arboriculture.proxy.ProxyArboricultureClient;
import forestry.arboriculture.tiles.TileFruitPod;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.arboriculture.tiles.TilePile;
Expand All @@ -68,6 +69,7 @@
import forestry.core.items.ItemFruit.EnumFruit;
import forestry.core.network.IPacketRegistry;
import forestry.core.recipes.RecipeUtil;
import forestry.core.render.TextureManager;
import forestry.core.utils.IMCUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.OreDictUtil;
Expand All @@ -88,7 +90,9 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
Expand Down Expand Up @@ -554,6 +558,24 @@ public void registerSprites(TextureStitchEvent.Pre event) {
for (IAlleleFruit alleleFruit : AlleleFruit.getFruitAlleles()) {
alleleFruit.getProvider().registerSprites();
}
List<ResourceLocation> textures = new ArrayList<>();
for(IWoodType type : TreeManager.woodAccess.getRegisteredWoodTypes()){
textures.add(new ResourceLocation(type.getHeartTexture()));
textures.add(new ResourceLocation(type.getBarkTexture()));
textures.add(new ResourceLocation(type.getDoorLowerTexture()));
textures.add(new ResourceLocation(type.getDoorUpperTexture()));
textures.add(new ResourceLocation(type.getPlankTexture()));
}
for(ResourceLocation loc : textures){
TextureManager.getInstance();
TextureManager.registerSprite(loc);
}
}

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onModelBake(ModelBakeEvent event) {
((ProxyArboricultureClient)proxy).onModelBake(event);
}

@SubscribeEvent
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/forestry/arboriculture/WoodAccess.java
Expand Up @@ -11,6 +11,8 @@
package forestry.arboriculture;

import javax.annotation.Nonnull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.HashMap;
Expand Down Expand Up @@ -43,6 +45,7 @@

public class WoodAccess implements IWoodAccess {
private static final Map<WoodBlockKind, WoodMap> woodMaps = new EnumMap<>(WoodBlockKind.class);
private static final List<IWoodType> registeredWoodTypes = new ArrayList<>();

static {
for (WoodBlockKind woodBlockKind : WoodBlockKind.values()) {
Expand Down Expand Up @@ -195,6 +198,9 @@ private static <T extends Block & IWoodTyped, V extends Enum<V> & IWoodType> voi
int meta = woodTyped.getMetaFromState(blockState);
IWoodType woodType = woodTyped.getWoodType(meta);
ItemStack itemStack = new ItemStack(woodTyped, 1, meta);
if(!(woodType instanceof EnumVanillaWoodType)){
PluginArboriculture.proxy.registerWoodModel(woodTyped, true);
}
register(woodType, woodBlockKind, fireproof, blockState, itemStack);
}
}
Expand All @@ -207,6 +213,9 @@ private static <T extends Block & IWoodTyped> void registerWithoutVariants(T woo
IBlockState blockState = woodTyped.getDefaultState();
IWoodType woodType = woodTyped.getWoodType(0);
ItemStack itemStack = new ItemStack(woodTyped);
if(!(woodType instanceof EnumVanillaWoodType)){
PluginArboriculture.proxy.registerWoodModel(woodTyped, false);
}
register(woodType, woodBlockKind, fireproof, blockState, itemStack);
}

Expand All @@ -218,6 +227,9 @@ private static void register(IWoodType woodType, WoodBlockKind woodBlockKind, bo
throw new NullPointerException("Invalid itemStack: " + itemStack);
}
WoodMap woodMap = woodMaps.get(woodBlockKind);
if(!registeredWoodTypes.contains(woodType)){
registeredWoodTypes.add(woodType);
}
woodMap.getItem(fireproof).put(woodType, itemStack);
woodMap.getBlock(fireproof).put(woodType, blockState);
}
Expand Down Expand Up @@ -249,4 +261,9 @@ public IBlockState getBlock(IWoodType woodType, WoodBlockKind woodBlockKind, boo
}
return blockState;
}

@Override
public List<IWoodType> getRegisteredWoodTypes() {
return registeredWoodTypes;
}
}

1 comment on commit eb63e75

@HanPrower
Copy link

@HanPrower HanPrower commented on eb63e75 Aug 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nedelosk: So how does one do custom models for fences and gates now?

PureBDcraft fences look crap when they just use the planks straight up so they really need custom models or I'll go mad o.o

Maybe you can do a fallback that if the individual blockstates exist in a resourcepack then those can be used instead?

Please sign in to comment.