ForgePatch/src/main/java/net/minecraftforge/client/model/BakedItemModel.java

135 lines
5.0 KiB
Java
Raw Normal View History

2017-10-31 18:03:44 +00:00
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
2017-10-31 18:03:44 +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
*/
2017-10-31 18:03:44 +00:00
package net.minecraftforge.client.model;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import java.util.List;
import java.util.Random;
2017-10-31 18:03:44 +00:00
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
2019-05-23 23:02:15 +00:00
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.model.ItemOverrideList;
2017-10-31 18:03:44 +00:00
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
2019-05-23 23:02:15 +00:00
import net.minecraft.util.Direction;
2017-10-31 18:03:44 +00:00
import net.minecraftforge.common.model.TRSRTransformation;
import org.apache.commons.lang3.tuple.Pair;
public class BakedItemModel implements IBakedModel
{
protected final ImmutableList<BakedQuad> quads;
protected final TextureAtlasSprite particle;
protected final ImmutableMap<TransformType, TRSRTransformation> transforms;
protected final ItemOverrideList overrides;
protected final IBakedModel guiModel;
/** @deprecated use {@link #BakedItemModel(ImmutableList, TextureAtlasSprite, ImmutableMap, ItemOverrideList, boolean)} */
@Deprecated // TODO: remove
2017-10-31 18:03:44 +00:00
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides)
{
this(quads, particle, transforms, overrides, true);
}
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides, boolean untransformed)
2017-10-31 18:03:44 +00:00
{
this.quads = quads;
this.particle = particle;
this.transforms = transforms;
this.overrides = overrides;
this.guiModel = untransformed && hasGuiIdentity(transforms) ? new BakedGuiItemModel<>(this) : null;
}
private static boolean hasGuiIdentity(ImmutableMap<TransformType, TRSRTransformation> transforms)
{
TRSRTransformation guiTransform = transforms.get(TransformType.GUI);
return guiTransform == null || guiTransform.isIdentity();
2017-10-31 18:03:44 +00:00
}
@Override public boolean isAmbientOcclusion() { return true; }
@Override public boolean isGui3d() { return false; }
@Override public boolean isBuiltInRenderer() { return false; }
@Override public TextureAtlasSprite getParticleTexture() { return particle; }
@Override public ItemOverrideList getOverrides() { return overrides; }
@Override
2019-05-23 23:02:15 +00:00
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
2017-10-31 18:03:44 +00:00
{
if (side == null)
{
return quads;
}
return ImmutableList.of();
}
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
{
if (type == TransformType.GUI && this.guiModel != null)
2017-10-31 18:03:44 +00:00
{
return this.guiModel.handlePerspective(type);
}
return PerspectiveMapWrapper.handlePerspective(this, transforms, type);
}
public static class BakedGuiItemModel<T extends BakedItemModel> extends BakedModelWrapper<T>
{
private final ImmutableList<BakedQuad> quads;
public BakedGuiItemModel(T originalModel)
{
super(originalModel);
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
for (BakedQuad quad : originalModel.quads)
{
2019-05-23 23:02:15 +00:00
if (quad.getFace() == Direction.SOUTH)
2017-10-31 18:03:44 +00:00
{
builder.add(quad);
}
}
this.quads = builder.build();
}
@Override
2019-05-23 23:02:15 +00:00
public List<BakedQuad> getQuads (@Nullable BlockState state, @Nullable Direction side, Random rand)
2017-10-31 18:03:44 +00:00
{
if(side == null)
{
return quads;
}
return ImmutableList.of();
}
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
{
if (type == TransformType.GUI)
{
return PerspectiveMapWrapper.handlePerspective(this, originalModel.transforms, type);
}
return this.originalModel.handlePerspective(type);
}
}
}