Fix Crafting Pattern Models (#1026)
* Fix perspective issues * Fix color for child models * To address raoulvberge's remarks Adds static method for rendering pattern, holds local variable for colors object
This commit is contained in:
@@ -4,7 +4,9 @@ import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.block.*;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiCraftingPreview;
|
||||
import com.raoulvdberge.refinedstorage.gui.grid.GuiCraftingStart;
|
||||
import com.raoulvdberge.refinedstorage.integration.mcmp.IntegrationMCMP;
|
||||
@@ -30,10 +32,13 @@ import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMap;
|
||||
import net.minecraft.client.renderer.color.IItemColor;
|
||||
import net.minecraft.client.renderer.color.ItemColors;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -46,6 +51,7 @@ import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -257,6 +263,27 @@ public class ProxyClient extends ProxyCommon {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent e) {
|
||||
super.init(e);
|
||||
|
||||
// Register IItemColor to handle passthrough
|
||||
ItemColors mcColors = Minecraft.getMinecraft().getItemColors();
|
||||
mcColors.registerItemColorHandler(new IItemColor() {
|
||||
@Override
|
||||
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
|
||||
CraftingPattern pattern = ItemPattern.getPatternFromCache(Minecraft.getMinecraft().world, stack);
|
||||
|
||||
if (BakedModelPattern.displayPatternOutput(pattern) &&
|
||||
mcColors.getColorFromItemstack(pattern.getOutputs().get(0), tintIndex) != -1) {
|
||||
return mcColors.getColorFromItemstack(pattern.getOutputs().get(0), tintIndex); // Take the item
|
||||
}
|
||||
|
||||
return 0xFFFFFF; // Full white, no need to apply color
|
||||
}
|
||||
}, RSItems.PATTERN);
|
||||
}
|
||||
|
||||
public static void onReceiveCraftingPreviewResponse(MessageGridCraftingPreviewResponse message) {
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.render;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemPattern;
|
||||
@@ -14,13 +15,34 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
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 BakedModelPattern implements IBakedModel {
|
||||
public class BakedModelPattern implements IBakedModel, IPerspectiveAwareModel {
|
||||
private IBakedModel patternModel;
|
||||
|
||||
private static TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s) {
|
||||
return new TRSRTransformation(
|
||||
new javax.vecmath.Vector3f(tx / 16, ty / 16, tz / 16),
|
||||
TRSRTransformation.quatFromXYZDegrees(new javax.vecmath.Vector3f(ax, ay, az)),
|
||||
new javax.vecmath.Vector3f(s, s, s),
|
||||
null);
|
||||
}
|
||||
|
||||
private static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms =
|
||||
ImmutableMap.<ItemCameraTransforms.TransformType, TRSRTransformation>builder()
|
||||
.put(ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 3, 1, 0, 0, 0, 0.55f))
|
||||
.put(ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, get(0, 3, 1, 0, 0, 0, 0.55f))
|
||||
.put(ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f))
|
||||
.put(ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f))
|
||||
.put(ItemCameraTransforms.TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f))
|
||||
.put(ItemCameraTransforms.TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1)).build();
|
||||
|
||||
public BakedModelPattern(IBakedModel patternModel) {
|
||||
this.patternModel = patternModel;
|
||||
}
|
||||
@@ -63,7 +85,7 @@ public class BakedModelPattern implements IBakedModel {
|
||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
|
||||
CraftingPattern pattern = ItemPattern.getPatternFromCache(world, stack);
|
||||
|
||||
if (GuiBase.isShiftKeyDown() && pattern.isValid() && pattern.getOutputs().size() == 1) {
|
||||
if (displayPatternOutput(pattern)) {
|
||||
return Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(pattern.getOutputs().get(0), world, entity);
|
||||
}
|
||||
|
||||
@@ -71,4 +93,20 @@ public class BakedModelPattern implements IBakedModel {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
|
||||
return Pair.of(this,
|
||||
transforms.get(cameraTransformType) != null ?
|
||||
transforms.get(cameraTransformType).getMatrix() : get(0, 0, 0, 0, 0, 0, 1.0f).getMatrix());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the pattern output should be displayed
|
||||
* @param pattern The pattern to check
|
||||
* @return True to render output, not pattern item
|
||||
*/
|
||||
public static boolean displayPatternOutput(CraftingPattern pattern) {
|
||||
return GuiBase.isShiftKeyDown() && pattern.isValid() && pattern.getOutputs().size() == 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user