Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.minetronic.masterchef.model.baked;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.concurrent.ExecutionException;
- import java.util.concurrent.TimeUnit;
- import javax.vecmath.Matrix4f;
- import org.apache.commons.lang3.tuple.Pair;
- import com.google.common.base.Optional;
- import com.google.common.cache.CacheBuilder;
- import com.google.common.cache.CacheLoader;
- import com.google.common.cache.LoadingCache;
- import com.google.common.collect.ImmutableMap;
- import com.minetronic.masterchef.blocks.BlockRipeningRack;
- import com.minetronic.masterchef.utils.Reference;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.renderer.block.model.BakedQuad;
- import net.minecraft.client.renderer.block.model.IBakedModel;
- import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
- import net.minecraft.client.renderer.block.model.ItemOverrideList;
- import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
- import net.minecraft.client.renderer.block.model.ModelResourceLocation;
- import net.minecraft.client.renderer.texture.TextureAtlasSprite;
- import net.minecraft.util.EnumFacing;
- import net.minecraftforge.client.model.IPerspectiveAwareModel;
- import net.minecraftforge.common.model.TRSRTransformation;
- import net.minecraftforge.common.property.IExtendedBlockState;
- import net.minecraftforge.common.property.IUnlistedProperty;
- public class RipeningRackBakedModel implements IPerspectiveAwareModel {
- public static final ModelResourceLocation VARIANT_TAG = new ModelResourceLocation(
- Reference.MOD_ID + ":" + "ripening_rack", "normal");
- /**
- * This is the full ripening rack without cheese and without directions Used
- * for taking over the properties of the previous IBakedModel. Eg:
- * getParticleTexture
- */
- private final IBakedModel BASE;
- /**
- * Contains all quads of the baked models: all sorts of cheeses, cheeses in
- * bowls and cheeses in buckets
- */
- private final ImmutableMap<String, List<BakedQuad>> MODELS_QUADS_NORTH;
- private final ImmutableMap<String, List<BakedQuad>> MODELS_QUADS_EAST;
- private final ImmutableMap<String, List<BakedQuad>> MODELS_QUADS_SOUTH;
- private final ImmutableMap<String, List<BakedQuad>> MODELS_QUADS_WEST;
- private LoadingCache<Pair<ImmutableMap<IProperty<?>, Comparable<?>>, ImmutableMap<IUnlistedProperty<?>, Optional<?>>>, List<BakedQuad>> quadsCache;
- public RipeningRackBakedModel(IBakedModel base, ImmutableMap<String, List<BakedQuad>> modelsQuadsNorth,
- ImmutableMap<String, List<BakedQuad>> modelsQuadsEast,
- ImmutableMap<String, List<BakedQuad>> modelsQuadsSouth,
- ImmutableMap<String, List<BakedQuad>> modelsQuadsWest) {
- this.BASE = base;
- this.MODELS_QUADS_NORTH = modelsQuadsNorth;
- this.MODELS_QUADS_EAST = modelsQuadsEast;
- this.MODELS_QUADS_SOUTH = modelsQuadsSouth;
- this.MODELS_QUADS_WEST = modelsQuadsWest;
- this.quadsCache = CacheBuilder.newBuilder().maximumSize(50).expireAfterAccess(30, TimeUnit.MINUTES).build(
- new CacheLoader<Pair<ImmutableMap<IProperty<?>, Comparable<?>>, ImmutableMap<IUnlistedProperty<?>, Optional<?>>>, List<BakedQuad>>() {
- @Override
- public List<BakedQuad> load(
- Pair<ImmutableMap<IProperty<?>, Comparable<?>>, ImmutableMap<IUnlistedProperty<?>, Optional<?>>> properties)
- throws Exception {
- return getQuadsForCache(properties);
- }
- });
- }
- private List<BakedQuad> getQuadsForCache(
- Pair<ImmutableMap<IProperty<?>, Comparable<?>>, ImmutableMap<IUnlistedProperty<?>, Optional<?>>> properties) {
- System.out.println("Creating new entry...");
- List<BakedQuad> allQuads = new ArrayList();
- allQuads.addAll(MODELS_QUADS_NORTH.get("ripening_rack"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_bottom_1"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_bottom_2"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_bottom_3"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_bottom_4"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_top_1"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_top_2"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_top_3"));
- allQuads.addAll(MODELS_QUADS_NORTH.get("old_cheese_wedge_top_4"));
- return allQuads;
- }
- @Override
- public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
- if (side == null) {
- if (state instanceof IExtendedBlockState) {
- IExtendedBlockState extendedState = (IExtendedBlockState) state;
- try {
- return quadsCache
- .get(Pair.of(extendedState.getProperties(), extendedState.getUnlistedProperties()));
- } catch (ExecutionException e) {
- e.printStackTrace();
- }
- }
- }
- return Collections.EMPTY_LIST;
- }
- @Override
- public TextureAtlasSprite getParticleTexture() {
- return BASE.getParticleTexture();
- }
- @Override
- public boolean isAmbientOcclusion() {
- return BASE.isAmbientOcclusion();
- }
- @Override
- public boolean isGui3d() {
- return BASE.isGui3d();
- }
- @Override
- public boolean isBuiltInRenderer() {
- return BASE.isBuiltInRenderer();
- }
- @Override
- public ItemOverrideList getOverrides() {
- return BASE.getOverrides();
- }
- @Override
- public ItemCameraTransforms getItemCameraTransforms() {
- return BASE.getItemCameraTransforms();
- }
- @Override
- public Pair<? extends IBakedModel, Matrix4f> handlePerspective(
- ItemCameraTransforms.TransformType cameraTransformType) {
- if (BASE instanceof IPerspectiveAwareModel) {
- Matrix4f matrix4f = ((IPerspectiveAwareModel) BASE).handlePerspective(cameraTransformType).getRight();
- return Pair.of(this, matrix4f);
- } else {
- ItemCameraTransforms itemCameraTransforms = BASE.getItemCameraTransforms();
- ItemTransformVec3f itemTransformVec3f = itemCameraTransforms.getTransform(cameraTransformType);
- TRSRTransformation tr = new TRSRTransformation(itemTransformVec3f);
- Matrix4f mat = null;
- if (tr != null) {
- mat = tr.getMatrix();
- }
- return Pair.of(this, mat);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement