2018-07-01 21:17:28 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2019-02-10 22:57:03 +00:00
|
|
|
* Copyright (c) 2016-2019.
|
2018-07-01 21:17:28 +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-06-25 01:08:20 +00:00
|
|
|
package net.minecraftforge.client.model;
|
|
|
|
|
2018-04-01 07:24:37 +00:00
|
|
|
import java.util.EnumMap;
|
2017-06-25 01:08:20 +00:00
|
|
|
import java.util.Optional;
|
2018-09-08 20:34:59 +00:00
|
|
|
import java.util.Random;
|
|
|
|
|
2017-06-25 01:08:20 +00:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2019-05-23 23:02:15 +00:00
|
|
|
import net.minecraft.block.BlockState;
|
2019-02-14 23:08:53 +00:00
|
|
|
import net.minecraft.client.renderer.model.BakedQuad;
|
|
|
|
import net.minecraft.client.renderer.model.IBakedModel;
|
|
|
|
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
|
|
|
import net.minecraft.client.renderer.model.ItemOverrideList;
|
2017-06-25 01:08:20 +00:00
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
2019-05-23 23:02:15 +00:00
|
|
|
import net.minecraft.util.Direction;
|
2017-06-25 01:08:20 +00:00
|
|
|
import net.minecraftforge.common.model.IModelState;
|
|
|
|
import net.minecraftforge.common.model.TRSRTransformation;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import javax.vecmath.Matrix4f;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class PerspectiveMapWrapper implements IBakedModel
|
|
|
|
{
|
|
|
|
private final IBakedModel parent;
|
|
|
|
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
|
|
|
|
|
|
|
|
public PerspectiveMapWrapper(IBakedModel parent, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms)
|
|
|
|
{
|
|
|
|
this.parent = parent;
|
|
|
|
this.transforms = transforms;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PerspectiveMapWrapper(IBakedModel parent, IModelState state)
|
|
|
|
{
|
|
|
|
this(parent, getTransforms(state));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(IModelState state)
|
|
|
|
{
|
2018-04-01 07:24:37 +00:00
|
|
|
EnumMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
|
2017-06-25 01:08:20 +00:00
|
|
|
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
|
|
|
|
{
|
|
|
|
Optional<TRSRTransformation> tr = state.apply(Optional.of(type));
|
|
|
|
if(tr.isPresent())
|
|
|
|
{
|
2018-04-01 07:24:37 +00:00
|
|
|
map.put(type, tr.get());
|
2017-06-25 01:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-01 07:24:37 +00:00
|
|
|
return ImmutableMap.copyOf(map);
|
2017-06-25 01:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(ItemCameraTransforms transforms)
|
|
|
|
{
|
2018-04-01 07:24:37 +00:00
|
|
|
EnumMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
|
2017-06-25 01:08:20 +00:00
|
|
|
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
|
|
|
|
{
|
2018-04-01 07:24:37 +00:00
|
|
|
if (transforms.hasCustomTransform(type))
|
|
|
|
{
|
|
|
|
map.put(type, TRSRTransformation.blockCenterToCorner(TRSRTransformation.from(transforms.getTransform(type))));
|
|
|
|
}
|
2017-06-25 01:08:20 +00:00
|
|
|
}
|
2018-04-01 07:24:37 +00:00
|
|
|
return ImmutableMap.copyOf(map);
|
2017-06-25 01:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, ItemCameraTransforms.TransformType cameraTransformType)
|
|
|
|
{
|
2018-04-01 07:24:37 +00:00
|
|
|
TRSRTransformation tr = transforms.getOrDefault(cameraTransformType, TRSRTransformation.identity());
|
|
|
|
if (!tr.isIdentity())
|
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrixVec());
|
2018-04-01 07:24:37 +00:00
|
|
|
}
|
|
|
|
return Pair.of(model, null);
|
2017-06-25 01:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, IModelState state, ItemCameraTransforms.TransformType cameraTransformType)
|
|
|
|
{
|
|
|
|
TRSRTransformation tr = state.apply(Optional.of(cameraTransformType)).orElse(TRSRTransformation.identity());
|
2018-04-01 07:24:37 +00:00
|
|
|
if (!tr.isIdentity())
|
2017-06-25 01:08:20 +00:00
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrixVec());
|
2017-06-25 01:08:20 +00:00
|
|
|
}
|
|
|
|
return Pair.of(model, null);
|
|
|
|
}
|
|
|
|
|
2018-05-17 05:44:34 +00:00
|
|
|
@Override public boolean isAmbientOcclusion() { return parent.isAmbientOcclusion(); }
|
2019-05-23 23:02:15 +00:00
|
|
|
@Override public boolean isAmbientOcclusion(BlockState state) { return parent.isAmbientOcclusion(state); }
|
2018-05-17 05:44:34 +00:00
|
|
|
@Override public boolean isGui3d() { return parent.isGui3d(); }
|
|
|
|
@Override public boolean isBuiltInRenderer() { return parent.isBuiltInRenderer(); }
|
|
|
|
@Override public TextureAtlasSprite getParticleTexture() { return parent.getParticleTexture(); }
|
2017-06-25 01:08:20 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-05-17 05:44:34 +00:00
|
|
|
@Override public ItemCameraTransforms getItemCameraTransforms() { return parent.getItemCameraTransforms(); }
|
2019-05-23 23:02:15 +00:00
|
|
|
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { return parent.getQuads(state, side, rand); }
|
2018-05-17 05:44:34 +00:00
|
|
|
@Override public ItemOverrideList getOverrides() { return parent.getOverrides(); }
|
2017-06-25 01:08:20 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
|
|
|
|
{
|
|
|
|
return handlePerspective(this, transforms, cameraTransformType);
|
|
|
|
}
|
|
|
|
}
|