mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 15:22:57 +00:00
Add model caching (#1449)
This commit is contained in:
1 parent
5e3c23e4eb
commit
9dcc818a17
7 files changed
+302
-164
No files matched your search
@@ -2,7 +2,10 @@ package forestry.farming.models;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.arboriculture.models.ModelLeaves;
|
||||
import forestry.core.models.ModelBlockCached;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -17,46 +20,71 @@ import forestry.farming.blocks.BlockFarm;
|
||||
import forestry.farming.blocks.EnumFarmBlockType;
|
||||
import forestry.farming.tiles.TileFarm;
|
||||
|
||||
public class ModelFarmBlock extends ModelBlockDefault<BlockFarm> {
|
||||
import java.util.Objects;
|
||||
|
||||
public class ModelFarmBlock extends ModelBlockCached<BlockFarm, ModelFarmBlock.Key> {
|
||||
public static class Key {
|
||||
public final EnumFarmBlockTexture texture;
|
||||
public final EnumFarmBlockType type;
|
||||
private final int hashCode;
|
||||
|
||||
public Key(EnumFarmBlockTexture texture, EnumFarmBlockType type) {
|
||||
this.texture = texture;
|
||||
this.type = type;
|
||||
this.hashCode = Objects.hash(texture, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof Key)) {
|
||||
return false;
|
||||
} else {
|
||||
Key otherKey = (Key) other;
|
||||
return otherKey.texture == texture && otherKey.type == type;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public ModelFarmBlock() {
|
||||
super(BlockFarm.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bakeInventoryBlock(@Nonnull BlockFarm blockFarm, @Nonnull ItemStack item, @Nonnull IModelBaker baker) {
|
||||
if (blockFarm == null) {
|
||||
return;
|
||||
}
|
||||
protected Key getInventoryKey(@Nonnull ItemStack stack) {
|
||||
EnumFarmBlockTexture texture = EnumFarmBlockTexture.getFromCompound(stack.getTagCompound());
|
||||
EnumFarmBlockType type = EnumFarmBlockType.VALUES[stack.getItemDamage()];
|
||||
|
||||
EnumFarmBlockTexture type = EnumFarmBlockTexture.getFromCompound(item.getTagCompound());
|
||||
|
||||
// Add the plain block.
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, getSprites(type), 0);
|
||||
// Add the overlay block.
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, getOverlaySprites(EnumFarmBlockType.VALUES[item.getItemDamage()]), 0);
|
||||
return new Key(texture, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bakeWorldBlock(@Nonnull BlockFarm blockFarm, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IExtendedBlockState stateExtended, @Nonnull IModelBaker baker) {
|
||||
|
||||
protected Key getWorldKey(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos) {
|
||||
TileFarm farm = TileUtil.getTile(world, pos, TileFarm.class);
|
||||
|
||||
EnumFarmBlockTexture texture = EnumFarmBlockTexture.BRICK;
|
||||
TextureAtlasSprite[] overlayTextures = getOverlaySprites(EnumFarmBlockType.PLAIN);
|
||||
|
||||
if(farm != null){
|
||||
EnumFarmBlockType type = EnumFarmBlockType.PLAIN;
|
||||
|
||||
if (farm != null) {
|
||||
texture = farm.getFarmBlockTexture();
|
||||
overlayTextures = getOverlaySprites(farm.getFarmBlockType());
|
||||
type = farm.getFarmBlockType();
|
||||
}
|
||||
|
||||
TextureAtlasSprite[] textures = getSprites(texture);
|
||||
|
||||
return new Key(texture, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bakeBlock(@Nonnull BlockFarm blockFarm, @Nonnull Key key, @Nonnull IModelBaker baker, boolean inventory) {
|
||||
TextureAtlasSprite[] textures = getSprites(key.texture);
|
||||
|
||||
// Add the plain block.
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, pos, textures, 0);
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, textures, 0);
|
||||
// Add the overlay block.
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, pos, overlayTextures, 0);
|
||||
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, getOverlaySprites(key.type), 0);
|
||||
|
||||
// Set the particle sprite
|
||||
baker.setParticleSprite(textures[0]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user