Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 1.8
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java
#	src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java
  • Loading branch information
jaquadro committed Aug 16, 2015
2 parents 48a46bd + dc54c29 commit 627f531
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 72 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
minecraft_version=1.8
forge_version=1.8-11.14.3.1449
mod_version=2.1.6
forge_version=1.8-11.14.3.1450
mod_version=2.1.7
chameleon_version=0.1.0
chameleon_max_version=1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.registry.GameData;
import net.minecraftforge.fml.common.registry.GameRegistry;
import org.apache.logging.log4j.Level;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TileEntityDrawersComp extends TileEntityDrawers
{
Expand Down Expand Up @@ -181,6 +185,9 @@ private void populateSlots (ItemStack stack) {

ItemStack lTier1 = findLowerTier(stack);
if (lTier1 != null) {
if (!worldObj.isRemote && StorageDrawers.config.cache.debugTrace)
FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, "Picked candidate " + lTier1.toString() + " with conv=" + lookupSizeResult);

populateSlot(index++, lTier1, 1);
for (int i = 0; i < index - 1; i++)
convRate[i] *= lookupSizeResult;
Expand All @@ -191,6 +198,9 @@ private void populateSlots (ItemStack stack) {

ItemStack lTier2 = findLowerTier(lTier1);
if (lTier2 != null) {
if (!worldObj.isRemote && StorageDrawers.config.cache.debugTrace)
FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, "Picked candidate " + lTier2.toString() + " with conv=" + lookupSizeResult);

populateSlot(index++, lTier2, 1);
for (int i = 0; i < index - 1; i++)
convRate[i] *= lookupSizeResult;
Expand All @@ -212,27 +222,69 @@ private ItemStack findHigherTier (ItemStack stack) {
}

CraftingManager cm = CraftingManager.getInstance();
List<ItemStack> candidates = new ArrayList<ItemStack>();

setupLookup(lookup3, stack);
ItemStack match = cm.findMatchingRecipe(lookup3, worldObj);
List<ItemStack> fwdCandidates = findAllMatchingRecipes(lookup3);

if (match == null || match.getItem() == null) {
if (fwdCandidates.size() == 0) {
setupLookup(lookup2, stack);
match = cm.findMatchingRecipe(lookup2, worldObj);
fwdCandidates = findAllMatchingRecipes(lookup2);
}

if (match != null && match.getItem() != null) {
if (fwdCandidates.size() > 0) {
int size = lookupSizeResult;

setupLookup(lookup1, match);
ItemStack comp = cm.findMatchingRecipe(lookup1, worldObj);
if (!DrawerData.areItemsEqual(comp, stack) || comp.stackSize != size)
return null;
for (int i = 0, n1 = fwdCandidates.size(); i < n1; i++) {
ItemStack match = fwdCandidates.get(i);
setupLookup(lookup1, match);
List<ItemStack> backCandidates = findAllMatchingRecipes(lookup1);

for (int j = 0, n2 = backCandidates.size(); j < n2; j++) {
ItemStack comp = backCandidates.get(j);
if (comp.stackSize != size)
continue;

if (!DrawerData.areItemsEqual(comp, stack, false))
continue;

candidates.add(match);
if (!worldObj.isRemote && StorageDrawers.config.cache.debugTrace)
FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, "Found ascending candidate for " + stack.toString() + ": " + match.toString() + " size=" + lookupSizeResult + ", inverse=" + comp.toString());

break;
}
}

lookupSizeResult = size;
}

return match;
ItemStack modMatch = findMatchingModCandidate(stack, candidates);
if (modMatch != null)
return modMatch;

if (candidates.size() > 0)
return candidates.get(0);

return null;
}

private List<ItemStack> findAllMatchingRecipes (InventoryCrafting crafting) {
List<ItemStack> candidates = new ArrayList<ItemStack>();

CraftingManager cm = CraftingManager.getInstance();
List recipeList = cm.getRecipeList();

for (int i = 0, n = recipeList.size(); i < n; i++) {
IRecipe recipe = (IRecipe) recipeList.get(i);
if (recipe.matches(crafting, worldObj)) {
ItemStack result = recipe.getCraftingResult(crafting);
if (result != null && result.getItem() != null)
candidates.add(result);
}
}

return candidates;
}

private ItemStack findLowerTier (ItemStack stack) {
Expand All @@ -246,13 +298,14 @@ private ItemStack findLowerTier (ItemStack stack) {
List recipeList = cm.getRecipeList();

List<ItemStack> candidates = new ArrayList<ItemStack>();
Map<ItemStack, Integer> candidatesRate = new HashMap<ItemStack, Integer>();

for (int i = 0, n = recipeList.size(); i < n; i++) {
IRecipe recipe = (IRecipe) recipeList.get(i);
ItemStack match = null;

ItemStack output = recipe.getRecipeOutput();
if (!DrawerData.areItemsEqual(stack, output))
if (!DrawerData.areItemsEqual(stack, output, false))
continue;

IRecipeHandler handler = StorageDrawers.recipeHandlerRegistry.getRecipeHandler(recipe.getClass());
Expand All @@ -275,19 +328,29 @@ private ItemStack findLowerTier (ItemStack stack) {
if (match != null) {
setupLookup(lookup1, stack);
ItemStack comp = cm.findMatchingRecipe(lookup1, worldObj);
if (DrawerData.areItemsEqual(match, comp) && comp.stackSize == recipe.getRecipeSize()) {
if (DrawerData.areItemsEqual(match, comp, false) && comp.stackSize == recipe.getRecipeSize()) {
lookupSizeResult = recipe.getRecipeSize();
candidates.add(match);
candidatesRate.put(match, lookupSizeResult);

if (!worldObj.isRemote && StorageDrawers.config.cache.debugTrace)
FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, "Found descending candidate for " + stack.toString() + ": " + match.toString() + " size=" + lookupSizeResult + ", inverse=" + comp.toString());
}
}
}

ItemStack modMatch = findMatchingModCandidate(stack, candidates);
if (modMatch != null)
if (modMatch != null) {
lookupSizeResult = candidatesRate.get(modMatch);
return modMatch;
}

if (candidates.size() > 0)
return candidates.get(0);
if (candidates.size() > 0) {
ItemStack match = candidates.get(0);
lookupSizeResult = candidatesRate.get(match);

return match;
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,26 @@ public void renderItemOverlayIntoGUI (FontRenderer font, ItemStack item, int x,
if (item != null)
{
float scale = .5f;
float xoff = 0;
if (font.getUnicodeFlag()) {
scale = 1f;
xoff = 1;
}

if (item.stackSize > 1 || text != null)
{
if (item.stackSize >= 10000)
text = (text == null) ? String.format("%.1fK", item.stackSize / 1000f) : text;
if (item.stackSize >= 100000000 || (item.stackSize >= 1000000 && font.getUnicodeFlag()))
text = (text == null) ? String.format("%.0fM", item.stackSize / 1000000f) : text;
else if (item.stackSize >= 1000000)
text = (text == null) ? String.format("%.1fM", item.stackSize / 1000000f) : text;
else if (item.stackSize >= 100000 || (item.stackSize >= 10000 && font.getUnicodeFlag()))
text = (text == null) ? String.format("%.0fK", item.stackSize / 1000f) : text;
else if (item.stackSize >= 10000)
text = (text == null) ? String.format("%.1fK", item.stackSize / 1000f) : text;
else
text = (text == null) ? String.valueOf(item.stackSize) : text;

int textX = (int)((x + 16 - font.getStringWidth(text) * scale) / scale) - 1;
int textX = (int)((x + 16 + xoff - font.getStringWidth(text) * scale) / scale) - 1;
int textY = (int)((y + 16 - 7 * scale) / scale) - 1;

GlStateManager.disableLighting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,22 @@ private void renderFastItem (ItemStack itemStack, TileEntityDrawers tile, int sl
GlStateManager.pushMatrix();

alignRendering(side);
moveRendering(size, getOffsetXForSide(side, xunit) * 16 - (8 * size), 12.25f - yunit, .999f - depth + 0); // 0 = trimDepth
moveRendering(size, getOffsetXForSide(side, xunit) * 16 - (8 * size), 12.25f - yunit, 1f - depth + 0); // 0 = trimDepth

List<IRenderLabel> renderHandlers = StorageDrawers.renderRegistry.getRenderHandlers();
for (int i = 0, n = renderHandlers.size(); i < n; i++) {
renderHandlers.get(i).render(tile, tile, slot, 0, partialTickTime);
}

GlStateManager.disableLighting();

GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(-1, -1);

renderItem.renderItemIntoGUI(itemStack, 0, 0);

GlStateManager.disablePolygonOffset();

GlStateManager.popMatrix();
}

Expand Down Expand Up @@ -242,7 +248,7 @@ private void alignRendering (EnumFacing side) {

private void moveRendering (float size, float offsetX, float offsetY, float offsetZ) {
GlStateManager.translate(0, 0, offsetZ);
GlStateManager.scale(1 / 16f, 1 / 16f, -.0001f);
GlStateManager.scale(1 / 16f, 1 / 16f, -.00001f);
GlStateManager.translate(offsetX, offsetY, 0);
GlStateManager.scale(size, size, 1);
}
Expand Down Expand Up @@ -281,10 +287,15 @@ private void renderLock (IBlockState blockState, int side, boolean locked) {
double depth = block.isHalfDepth(blockState) ? .5 : 1;
TextureAtlasSprite iconLock = Chameleon.instance.iconRegistry.getIcon(StorageDrawers.proxy.iconLockResource);

ChamRender.instance.setRenderBounds(0.46875, 0.9375, 0, 0.53125, 1, depth + .005);
GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(-1, -1);

ChamRender.instance.setRenderBounds(0.46875, 0.9375, 0, 0.53125, 1, depth);
ChamRender.instance.state.setRotateTransform(ChamRender.ZPOS, side);
ChamRender.instance.renderPartialFace(ChamRender.ZPOS, null, blockState, BlockPos.ORIGIN, iconLock, 0, 0, 1, 1, 1, 1, 1);
ChamRender.instance.state.clearRotateTransform();

GlStateManager.disablePolygonOffset();
}

private void renderVoid (IBlockState blockState, int side, boolean voided) {
Expand All @@ -296,10 +307,15 @@ private void renderVoid (IBlockState blockState, int side, boolean voided) {
double depth = block.isHalfDepth(blockState) ? .5 : 1;
TextureAtlasSprite iconVoid = Chameleon.instance.iconRegistry.getIcon(StorageDrawers.proxy.iconVoidResource);

ChamRender.instance.setRenderBounds(1 - .0625, 0.9375, 0, 1, 1, depth + .005);
GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(-1, -1);

ChamRender.instance.setRenderBounds(1 - .0625, 0.9375, 0, 1, 1, depth);
ChamRender.instance.state.setRotateTransform(ChamRender.ZPOS, side);
ChamRender.instance.renderPartialFace(ChamRender.ZPOS, null, blockState, BlockPos.ORIGIN, iconVoid, 0, 0, 1, 1, 1, 1, 1);
ChamRender.instance.state.clearRotateTransform();

GlStateManager.disablePolygonOffset();
}

private void renderShroud (TileEntityDrawers tile, IBlockState blockState, int side, boolean shrouded) {
Expand All @@ -317,6 +333,9 @@ private void renderShroud (TileEntityDrawers tile, IBlockState blockState, int s
int drawerCount = tile.getDrawerCount();
float size = (drawerCount == 1) ? .25f : .125f;

GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(-1, -1);

for (int i = 0; i < count; i++) {
IDrawer drawer = tile.getDrawer(i);
if (drawer == null || drawer.isEmpty())
Expand All @@ -328,11 +347,13 @@ private void renderShroud (TileEntityDrawers tile, IBlockState blockState, int s
TextureAtlasSprite iconCover = Chameleon.instance.iconRegistry.getIcon(StorageDrawers.proxy.iconShroudCover);

ChamRender.instance.setRenderBounds(xunit - size / 2, (yunit - .25) * unit + size / 2, 0,
xunit - size / 2 + size, (yunit - .25) * unit + size / 2 + size, depth - frontDepth + .005);
xunit - size / 2 + size, (yunit - .25) * unit + size / 2 + size, depth - frontDepth);
ChamRender.instance.state.setRotateTransform(ChamRender.ZPOS, side);
ChamRender.instance.renderFace(ChamRender.ZPOS, null, blockState, BlockPos.ORIGIN, iconCover, 1, 1, 1);
ChamRender.instance.state.clearRotateTransform();
}

GlStateManager.disablePolygonOffset();
}

private void renderIndicator (TileEntityDrawers tile, IBlockState blockState, int side, int level) {
Expand All @@ -358,15 +379,20 @@ private void renderIndicator (TileEntityDrawers tile, IBlockState blockState, in
Area2D statusArea = statusInfo.getSlot(i).getStatusArea();
Area2D activeArea = statusInfo.getSlot(i).getStatusActiveArea();

GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(-1, -1);

ChamRender.instance.setRenderBounds(statusArea.getX() * unit, statusArea.getY() * unit, 0,
(statusArea.getX() + statusArea.getWidth()) * unit, (statusArea.getY() + statusArea.getHeight()) * unit, depth - frontDepth + .005);
(statusArea.getX() + statusArea.getWidth()) * unit, (statusArea.getY() + statusArea.getHeight()) * unit, depth - frontDepth);
ChamRender.instance.state.setRotateTransform(ChamRender.ZPOS, side);
ChamRender.instance.renderFace(ChamRender.ZPOS, null, blockState, BlockPos.ORIGIN, iconOff, 1, 1, 1);
ChamRender.instance.state.clearRotateTransform();

GlStateManager.doPolygonOffset(-1, -10);

if (level == 1 && drawer.getMaxCapacity() > 0 && drawer.getRemainingCapacity() == 0) {
ChamRender.instance.setRenderBounds(statusArea.getX() * unit, statusArea.getY() * unit, 0,
(statusArea.getX() + statusArea.getWidth()) * unit, (statusArea.getY() + statusArea.getHeight()) * unit, depth - frontDepth + .006);
(statusArea.getX() + statusArea.getWidth()) * unit, (statusArea.getY() + statusArea.getHeight()) * unit, depth - frontDepth);
ChamRender.instance.state.setRotateTransform(ChamRender.ZPOS, side);
ChamRender.instance.renderFace(ChamRender.ZPOS, null, blockState, BlockPos.ORIGIN, iconOn, 1, 1, 1);
ChamRender.instance.state.clearRotateTransform();
Expand All @@ -388,12 +414,14 @@ else if (level >= 2) {
indYCur = Math.min(indYCur, indYEnd);

ChamRender.instance.setRenderBounds(indXStart * unit, indYStart * unit, 0,
indXCur * unit, indYCur * unit, depth - frontDepth + .006);
indXCur * unit, indYCur * unit, depth - frontDepth);
ChamRender.instance.state.setRotateTransform(ChamRender.ZPOS, side);
ChamRender.instance.renderFace(ChamRender.ZPOS, null, blockState, BlockPos.ORIGIN, iconOn, 1, 1, 1);
ChamRender.instance.state.clearRotateTransform();
}
}

GlStateManager.disablePolygonOffset();
}
}

Expand Down Expand Up @@ -477,6 +505,9 @@ public void renderItemIntoGUI (FontRenderer fontRenderer, TextureManager texMana
if (renderWithColor)
GL11.glColor4f(r, g, b, 1.0F);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
GL11.glPolygonOffset(-1f, -1);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
Expand All @@ -489,9 +520,9 @@ public void renderItemIntoGUI (FontRenderer fontRenderer, TextureManager texMana
if (renderEffect && itemStack.hasEffect(i))
renderEffect(texManager, x, y);
}
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
}
}
@Override
Expand Down Expand Up @@ -577,11 +608,15 @@ private void renderItemIntoGUIBlock (FontRenderer fontRenderer, TextureManager t
GL11.glColor4f(r * 1, g * 1, b * 1, 1.0F);
GL11.glRotatef(-90, 0, 1, 0);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
GL11.glPolygonOffset(-1f, -1f);
this.renderBlocksRi.useInventoryTint = this.renderWithColor;
this.renderBlocksRi.renderBlockAsItem(block, itemStack.getItemDamage(), 1);
this.renderBlocksRi.useInventoryTint = true;
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
if (block.getRenderBlockPass() == 0)
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
Expand Down Expand Up @@ -836,7 +871,7 @@ private void renderFastItem (ItemStack itemStack, TileEntityDrawers tile, int sl
GL11.glPushMatrix();
alignRendering(side);
moveRendering(size, getOffsetXForSide(side, xunit) * 16 - (8 * size), 12.25f - yunit, .999f - depth + block.trimDepth);
moveRendering(size, getOffsetXForSide(side, xunit) * 16 - (8 * size), 12.25f - yunit, 1f - depth + block.trimDepth);
List<IRenderLabel> renderHandlers = StorageDrawers.renderRegistry.getRenderHandlers();
for (int i = 0, n = renderHandlers.size(); i < n; i++) {
Expand Down
Loading

0 comments on commit 627f531

Please sign in to comment.