Mana pools now try catalyst recipes first before recipes without catalyst specified. Also make mana bar not render in spectator. Closes #291

This commit is contained in:
Vincent Lee committed 2016-05-20 14:36:28 -05:00
1 parent 995c19c04a
commit c9de3bcc03
3 files changed
+88 -76

No files matched your search

@@ -22,7 +22,7 @@ public interface IManaDissolvable {
/**
* Called for every tick the item is on a mana pool. If the stack has stack
* size 0 the item is killed. This is called in both the server and client.
* size 0 the item is killed. This is called serverside.
*/
public void onDissolveTick(IManaPool pool, ItemStack stack, EntityItem item);
@@ -167,44 +167,47 @@ public final class HUDHandler {
}
profiler.startSection("manaBar");
EntityPlayer player = mc.thePlayer;
int totalMana = 0;
int totalMaxMana = 0;
boolean anyRequest = false;
boolean creative = false;
if(!player.isSpectator()) {
int totalMana = 0;
int totalMaxMana = 0;
boolean anyRequest = false;
boolean creative = false;
IInventory mainInv = player.inventory;
IInventory baublesInv = PlayerHandler.getPlayerBaubles(player);
IInventory mainInv = player.inventory;
IInventory baublesInv = PlayerHandler.getPlayerBaubles(player);
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stack = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stack = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
if(stack != null) {
Item item = stack.getItem();
if(item instanceof IManaUsingItem)
anyRequest = anyRequest || ((IManaUsingItem) item).usesMana(stack);
if(stack != null) {
Item item = stack.getItem();
if(item instanceof IManaUsingItem)
anyRequest = anyRequest || ((IManaUsingItem) item).usesMana(stack);
if(item instanceof IManaItem) {
if(!((IManaItem) item).isNoExport(stack)) {
totalMana += ((IManaItem) item).getMana(stack);
totalMaxMana += ((IManaItem) item).getMaxMana(stack);
if(item instanceof IManaItem) {
if(!((IManaItem) item).isNoExport(stack)) {
totalMana += ((IManaItem) item).getMana(stack);
totalMaxMana += ((IManaItem) item).getMaxMana(stack);
}
}
if(item instanceof ICreativeManaProvider && ((ICreativeManaProvider) item).isCreative(stack))
creative = true;
}
if(item instanceof ICreativeManaProvider && ((ICreativeManaProvider) item).isCreative(stack))
creative = true;
}
}
if(anyRequest)
renderManaInvBar(event.getResolution(), creative, totalMana, totalMaxMana);
if(anyRequest)
renderManaInvBar(event.getResolution(), creative, totalMana, totalMaxMana);
}
profiler.endStartSection("itemsRemaining");
ItemsRemainingRenderHandler.render(event.getResolution(), event.getPartialTicks());
@@ -272,36 +275,29 @@ public final class HUDHandler {
Profiler profiler = mc.mcProfiler;
profiler.startSection("poolRecipe");
for(RecipeManaInfusion recipe : BotaniaAPI.manaInfusionRecipes) {
if(recipe.matches(stack)) {
if(recipe.getCatalyst() == null || recipe.getCatalyst() == tile.getWorld().getBlockState(tile.getPos().down())) {
int x = res.getScaledWidth() / 2 - 11;
int y = res.getScaledHeight() / 2 + 10;
RecipeManaInfusion recipe = TilePool.getMatchingRecipe(stack, tile.getWorld().getBlockState(tile.getPos().down()));
if(recipe != null) {
int x = res.getScaledWidth() / 2 - 11;
int y = res.getScaledHeight() / 2 + 10;
int u = tile.getCurrentMana() >= recipe.getManaToConsume() ? 0 : 22;
int v = mc.thePlayer.getName().equals("haighyorkie") && mc.thePlayer.isSneaking() ? 23 : 8;
int u = tile.getCurrentMana() >= recipe.getManaToConsume() ? 0 : 22;
int v = mc.thePlayer.getName().equals("haighyorkie") && mc.thePlayer.isSneaking() ? 23 : 8;
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
mc.renderEngine.bindTexture(manaBar);
RenderHelper.drawTexturedModalRect(x, y, 0, u, v, 22, 15);
GlStateManager.color(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(manaBar);
RenderHelper.drawTexturedModalRect(x, y, 0, u, v, 22, 15);
GlStateManager.color(1F, 1F, 1F, 1F);
net.minecraft.client.renderer.RenderHelper.enableGUIStandardItemLighting();
mc.getRenderItem().renderItemAndEffectIntoGUI(stack, x - 20, y);
mc.getRenderItem().renderItemAndEffectIntoGUI(recipe.getOutput(), x + 26, y);
mc.getRenderItem().renderItemOverlayIntoGUI(mc.fontRendererObj, recipe.getOutput(), x + 26, y, "");
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
net.minecraft.client.renderer.RenderHelper.enableGUIStandardItemLighting();
mc.getRenderItem().renderItemAndEffectIntoGUI(stack, x - 20, y);
mc.getRenderItem().renderItemAndEffectIntoGUI(recipe.getOutput(), x + 26, y);
mc.getRenderItem().renderItemOverlayIntoGUI(mc.fontRendererObj, recipe.getOutput(), x + 26, y, "");
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
GlStateManager.disableLighting();
GlStateManager.disableBlend();
break;
}
}
GlStateManager.disableLighting();
GlStateManager.disableBlend();
}
profiler.endSection();
}
@@ -62,7 +62,9 @@ import vazkii.botania.common.network.PacketHandler;
import javax.annotation.Nonnull;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAttachable, IThrottledPacket {
@@ -135,14 +137,30 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt
invalidate();
}
public static RecipeManaInfusion getMatchingRecipe(@Nonnull ItemStack stack, @Nonnull IBlockState state) {
List<RecipeManaInfusion> matchingNonCatRecipes = new ArrayList<>();
List<RecipeManaInfusion> matchingCatRecipes = new ArrayList<>();
for (RecipeManaInfusion recipe : BotaniaAPI.manaInfusionRecipes) {
if (recipe.matches(stack)) {
if(recipe.getCatalyst() == null)
matchingNonCatRecipes.add(recipe);
else if (recipe.getCatalyst() == state)
matchingCatRecipes.add(recipe);
}
}
// Recipes with matching catalyst take priority above recipes with no catalyst specified
return !matchingCatRecipes.isEmpty() ? matchingCatRecipes.get(0) :
!matchingNonCatRecipes.isEmpty() ? matchingNonCatRecipes.get(0) :
null;
}
public boolean collideEntityItem(EntityItem item) {
if(worldObj.isRemote || item.isDead)
return false;
boolean didChange = false;
ItemStack stack = item.getEntityItem();
if(stack == null)
return false;
if(stack.getItem() instanceof IManaDissolvable) {
((IManaDissolvable) stack.getItem()).onDissolveTick(this, stack, item);
@@ -158,32 +176,30 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt
if(age > 100 && age < 130)
return false;
for(RecipeManaInfusion recipe : BotaniaAPI.manaInfusionRecipes) {
if(recipe.matches(stack) && (recipe.getCatalyst() == null || worldObj.getBlockState(pos.down()) == recipe.getCatalyst())) {
int mana = recipe.getManaToConsume();
if(getCurrentMana() >= mana) {
recieveMana(-mana);
RecipeManaInfusion recipe = getMatchingRecipe(stack, worldObj.getBlockState(pos.down()));
stack.stackSize--;
if(stack.stackSize == 0)
item.setDead();
if(recipe != null) {
int mana = recipe.getManaToConsume();
if(getCurrentMana() >= mana) {
recieveMana(-mana);
ItemStack output = recipe.getOutput().copy();
EntityItem outputItem = new EntityItem(worldObj, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
try {
MethodHandles.itemAge_setter.invokeExact(outputItem, 105);
} catch (Throwable ignored) {}
worldObj.spawnEntityInWorld(outputItem);
stack.stackSize--;
if(stack.stackSize == 0)
item.setDead();
craftingFanciness();
didChange = true;
}
ItemStack output = recipe.getOutput().copy();
EntityItem outputItem = new EntityItem(worldObj, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
try {
MethodHandles.itemAge_setter.invokeExact(outputItem, 105);
} catch (Throwable ignored) {}
worldObj.spawnEntityInWorld(outputItem);
break;
craftingFanciness();
return true;
}
}
return didChange;
return false;
}
private void craftingFanciness() {