Java Code Examples for net.minecraftforge.common.model.TRSRTransformation#from()

The following examples show how to use net.minecraftforge.common.model.TRSRTransformation#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testDirectApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("clip(param)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final float param = 1.3f;
	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, ImmutableMap.of("param", param));
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(param);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example 2
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testVarApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("param := 1.4");
	factory.appendStatement("clip(param)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, NO_ARGS);
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(1.4f);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example 3
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testConstApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("clip(2.4 + 1/3)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, NO_ARGS);
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(2.4f + 1f / 3f);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example 4
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testArithmeticsVarApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("clip(2.4 / a + 1/(3 * b))");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub))
			.evaluate(DUMMY_JOINT, ImmutableMap.of("a", 5.1f, "b", -0.4f));
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(2.4f / 5.1f + 1f / (3f * -0.4f));
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example 5
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testDoubleApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("param1 := 1.4");
	factory.appendStatement("clip(param1)");
	factory.appendStatement("clip(param2)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform1 = TRSRTransformation.from(EnumFacing.NORTH);
	final TRSRTransformation transform2 = TRSRTransformation.from(EnumFacing.WEST);
	Mockito.when(jointClipMock.apply(1.4f)).thenReturn(transform1);
	Mockito.when(jointClipMock.apply(2.1f)).thenReturn(transform2);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, ImmutableMap.of("param2", 2.1f));
	Assert.assertEquals(transform1.compose(transform2), result);

	Mockito.verify(jointClipMock).apply(1.4f);
	Mockito.verify(jointClipMock).apply(2.1f);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example 6
Source File: EvalModelTest.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Test
public void testSeparateClipsApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("param := 2.5");
	factory.appendStatement("clip1(param)");
	factory.appendStatement("clip2(param)");

	final ClipStub clipStub1 = new ClipStub();
	final IJointClip jointClipMock1 = clipStub1.jointClipMock;

	final ClipStub clipStub2 = new ClipStub();
	final IJointClip jointClipMock2 = clipStub2.jointClipMock;

	final TRSRTransformation transform1 = TRSRTransformation.from(EnumFacing.EAST);
	final TRSRTransformation transform2 = TRSRTransformation.from(EnumFacing.UP);
	Mockito.when(jointClipMock1.apply(Matchers.anyFloat())).thenReturn(transform1);
	Mockito.when(jointClipMock2.apply(Matchers.anyFloat())).thenReturn(transform2);

	final TRSRTransformation result = factory.createEvaluator(clips("clip1", clipStub1).put("clip2", clipStub2)).evaluate(DUMMY_JOINT, NO_ARGS);
	Assert.assertEquals(transform1.compose(transform2), result);

	Mockito.verify(jointClipMock1).apply(2.5f);
	Mockito.verifyNoMoreInteractions(jointClipMock1);

	Mockito.verify(jointClipMock2).apply(2.5f);
	Mockito.verifyNoMoreInteractions(jointClipMock2);
}
 
Example 7
Source File: ModelNullifierBaked.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void addQuads(ModelNullifierBaked nullifierModel, boolean locked, ItemStack containedStack)
{
    IBakedModel itemModel = null;
    IBakedModel textModel = null;

    if (containedStack.isEmpty() == false)
    {
        ItemType type = new ItemType(containedStack, true);
        itemModel = ITEM_MODEL_CACHE.get(type);

        if (itemModel == null)
        {
            IModel iModel = this.getItemModel(containedStack);

            if (iModel != null && iModel.getClass().getName().equals("net.minecraftforge.client.model.FancyMissingModel") == false)
            {
                TRSRTransformation trn = new TRSRTransformation(new javax.vecmath.Vector3f(-0.5f, -0.5f, -0.5f), null, null, null);
                TRSRTransformation trr = TRSRTransformation.from(ModelRotation.X0_Y180);
                TRSRTransformation trp = new TRSRTransformation(new javax.vecmath.Vector3f( 0.5f,  0.5f,  0.5f), null, null, null);
                TRSRTransformation trs = new TRSRTransformation(null, null, new javax.vecmath.Vector3f(0.6f, 0.6f, 0.6f), null);
                TRSRTransformation tr = trn.compose(trr).compose(trp).compose(trs);

                IModelState state = new ModelStateComposition(this.modelState, TRSRTransformation.blockCenterToCorner(tr));
                itemModel = iModel.bake(state, this.format, this.bakedTextureGetter);
            }
            else
            {
                Minecraft mc = Minecraft.getMinecraft();
                itemModel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(containedStack);
                itemModel = itemModel.getOverrides().handleItemState(itemModel, containedStack, mc.world, mc.player);
            }

            ITEM_MODEL_CACHE.put(type, itemModel);
        }
    }

    this.addQuadsForSide(null, nullifierModel, itemModel, textModel, locked);

    for (EnumFacing side : EnumFacing.values())
    {
        this.addQuadsForSide(side, nullifierModel, itemModel, textModel, locked);
    }
}