Fixes crashes when trying to open gui on a MCMP block

This commit is contained in:
raoulvdberge
2017-03-01 14:14:48 +01:00
parent fcd9c0b618
commit db86e7037a
3 changed files with 38 additions and 27 deletions

View File

@@ -7,6 +7,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiReaderWriter;
import com.raoulvdberge.refinedstorage.container.*;
import com.raoulvdberge.refinedstorage.gui.grid.GridDisplayDummy;
import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid;
import com.raoulvdberge.refinedstorage.integration.mcmp.IntegrationMCMP;
import com.raoulvdberge.refinedstorage.tile.*;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.TileCraftingMonitor;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.WirelessCraftingMonitor;
@@ -14,6 +15,9 @@ import com.raoulvdberge.refinedstorage.tile.grid.IGrid;
import com.raoulvdberge.refinedstorage.tile.grid.TileGrid;
import com.raoulvdberge.refinedstorage.tile.grid.WirelessFluidGrid;
import com.raoulvdberge.refinedstorage.tile.grid.WirelessGrid;
import mcmultipart.api.multipart.IMultipartTile;
import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.block.TileMultipartContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
@@ -23,6 +27,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
import java.util.Optional;
public class GuiHandler implements IGuiHandler {
private Container getContainer(int ID, EntityPlayer player, TileEntity tile) {
switch (ID) {
@@ -89,12 +95,24 @@ public class GuiHandler implements IGuiHandler {
return getWirelessCraftingMonitorContainer(player, x, y);
}
return getContainer(ID, player, world.getTileEntity(new BlockPos(x, y, z)));
return getContainer(ID, player, unwrapMultipart(world.getTileEntity(new BlockPos(x, y, z))));
}
private TileEntity unwrapMultipart(TileEntity tile) {
if (IntegrationMCMP.isLoaded() && tile instanceof TileMultipartContainer.Ticking) {
Optional<IMultipartTile> multipartTile = ((TileMultipartContainer.Ticking) tile).getPartTile(EnumCenterSlot.CENTER);
if (multipartTile.isPresent()) {
return multipartTile.get().getTileEntity();
}
}
return tile;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
TileEntity tile = unwrapMultipart(world.getTileEntity(new BlockPos(x, y, z)));
switch (ID) {
case RSGui.CONTROLLER:

View File

@@ -6,7 +6,6 @@ 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;
@@ -274,7 +273,7 @@ public class ProxyClient extends ProxyCommon {
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
CraftingPattern pattern = ItemPattern.getPatternFromCache(Minecraft.getMinecraft().world, stack);
if (BakedModelPattern.displayPatternOutput(pattern) &&
if (BakedModelPattern.canDisplayPatternOutput(pattern) &&
mcColors.getColorFromItemstack(pattern.getOutputs().get(0), tintIndex) != -1) {
return mcColors.getColorFromItemstack(pattern.getOutputs().get(0), tintIndex); // Take the item
}

View File

@@ -26,23 +26,24 @@ import java.util.List;
public class BakedModelPattern implements IBakedModel, IPerspectiveAwareModel {
private IBakedModel patternModel;
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();
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);
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;
}
@@ -85,7 +86,7 @@ public class BakedModelPattern implements IBakedModel, IPerspectiveAwareModel {
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
CraftingPattern pattern = ItemPattern.getPatternFromCache(world, stack);
if (displayPatternOutput(pattern)) {
if (canDisplayPatternOutput(pattern)) {
return Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(pattern.getOutputs().get(0), world, entity);
}
@@ -96,17 +97,10 @@ public class BakedModelPattern implements IBakedModel, IPerspectiveAwareModel {
@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());
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) {
public static boolean canDisplayPatternOutput(CraftingPattern pattern) {
return GuiBase.isShiftKeyDown() && pattern.isValid() && pattern.getOutputs().size() == 1;
}
}