Giving the Scribe much needed TLC
This commit is contained in:
parent
2bbd616838
commit
bcbeb7bc51
5 changed files with 66 additions and 52 deletions
|
|
@ -17,7 +17,7 @@ public class ContainerScribe extends Container
|
|||
EntityPlayer player;
|
||||
|
||||
private int lastUseTime;
|
||||
private int lastChopTime;
|
||||
private int fuelTime;
|
||||
private int lastFuelTime;
|
||||
|
||||
public ContainerScribe(EntityPlayer player, TileScribe scribe)
|
||||
|
|
@ -26,7 +26,7 @@ public class ContainerScribe extends Container
|
|||
this.scribe = scribe;
|
||||
|
||||
lastUseTime = 0;
|
||||
lastChopTime = 0;
|
||||
fuelTime = 0;
|
||||
lastFuelTime = 0;
|
||||
|
||||
this.addSlotToContainer(new Slot(scribe, 0, 68, 35)); // input
|
||||
|
|
@ -72,13 +72,13 @@ public class ContainerScribe extends Container
|
|||
|
||||
if (this.lastUseTime != this.scribe.processTime)
|
||||
crafting.sendProgressBarUpdate(this, 0, this.scribe.processTime);
|
||||
if (this.lastChopTime != this.scribe.fuelTime)
|
||||
if (this.fuelTime != this.scribe.fuelTime)
|
||||
crafting.sendProgressBarUpdate(this, 1, this.scribe.fuelTime);
|
||||
if (this.lastFuelTime != this.scribe.currentFuelBuffer)
|
||||
crafting.sendProgressBarUpdate(this, 2, this.scribe.currentFuelBuffer);
|
||||
}
|
||||
this.lastUseTime = this.scribe.processTime;
|
||||
this.lastChopTime = this.scribe.fuelTime;
|
||||
this.fuelTime = this.scribe.fuelTime;
|
||||
this.lastFuelTime = this.scribe.currentFuelBuffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class GUIScribe extends GuiContainer
|
|||
int l = (this.height - this.ySize) / 2;
|
||||
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
|
||||
|
||||
if (this.scribe.isUsingFuel())
|
||||
if (this.scribe.hasConsumedBook())
|
||||
{
|
||||
int i1 = this.scribe.getProgressScaled(24);
|
||||
this.drawTexturedModalRect(k + 89, l + 36, 176, 14, i1 + 1, 16);
|
||||
|
|
|
|||
|
|
@ -52,18 +52,13 @@ public class MachineRecipes
|
|||
ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.cobblestone, 1), new ItemStack(Blocks.sand, 2));
|
||||
ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.sandstone, 1, Short.MAX_VALUE), new ItemStack(Blocks.sand, 4));
|
||||
ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.red_sandstone, 1, Short.MAX_VALUE), new ItemStack(Blocks.sand, 4, 1));
|
||||
|
||||
registerOreDict();
|
||||
|
||||
for (int i = 0; i < ItemDust.getDusts().size(); i++)
|
||||
OreDictionary.registerOre("dust" + ItemDust.getDusts().get(i), new ItemStack(LibItems.dusts, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
static void registerOreDict()
|
||||
{
|
||||
ArrayList<String> dustNames = ItemDust.getDusts();
|
||||
|
||||
for (int i = 0; i < dustNames.size(); i++)
|
||||
OreDictionary.registerOre("dust" + dustNames.get(i), new ItemStack(LibItems.dusts, 1, i));
|
||||
}
|
||||
|
||||
static void parseScribeRecipes()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import java.util.Map.Entry;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.item.ItemEnchantedBook;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
|
|
@ -37,6 +38,21 @@ public class ScribeRecipes
|
|||
}
|
||||
}
|
||||
|
||||
public int getInputStackSizeForOutput(ItemStack output)
|
||||
{
|
||||
Iterator iterator = this.recipes.entrySet().iterator();
|
||||
Entry entry;
|
||||
do
|
||||
{
|
||||
if (!iterator.hasNext())
|
||||
return -1;
|
||||
|
||||
entry = (Entry) iterator.next();
|
||||
}
|
||||
while (!this.compareBooks(output, (ItemStack) entry.getValue()));
|
||||
return ((ItemStack) entry.getKey()).stackSize;
|
||||
}
|
||||
|
||||
public ItemStack getResult(ItemStack stack)
|
||||
{
|
||||
Iterator iterator = this.recipes.entrySet().iterator();
|
||||
|
|
@ -56,7 +72,18 @@ public class ScribeRecipes
|
|||
|
||||
private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
return stack2.getItem() == stack1.getItem() && (stack2.getItemDamage() == 32767 || stack2.getItemDamage() == stack1.getItemDamage()) && stack1.stackSize == stack2.stackSize;
|
||||
return stack2.getItem() == stack1.getItem() && (stack2.getItemDamage() == 32767 || stack2.getItemDamage() == stack1.getItemDamage()) && stack1.stackSize >= stack2.stackSize;
|
||||
}
|
||||
|
||||
private boolean compareBooks(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
if (stack1.getItem() instanceof ItemEnchantedBook && stack2.getItem() instanceof ItemEnchantedBook)
|
||||
{
|
||||
ItemEnchantedBook book1 = (ItemEnchantedBook) stack1.getItem();
|
||||
ItemEnchantedBook book2 = (ItemEnchantedBook) stack2.getItem();
|
||||
return book1.getEnchantments(stack1) == book2.getEnchantments(stack2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map getRecipeList()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
|
||||
public class TileScribe extends TileEntityLockable implements ITickable, ISidedInventory
|
||||
{
|
||||
private static int proTicks = 700;
|
||||
private static int proTicks = 100;
|
||||
private static String customName;
|
||||
private ItemStack[] ItemStacks = new ItemStack[3];
|
||||
public int fuelTime;
|
||||
|
|
@ -34,7 +34,7 @@ public class TileScribe extends TileEntityLockable implements ITickable, ISidedI
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
boolean isBurning = this.isUsingFuel();
|
||||
boolean isBurning = this.hasConsumedBook();
|
||||
boolean flag = false;
|
||||
|
||||
if (this.fuelTime > 0)
|
||||
|
|
@ -49,20 +49,10 @@ public class TileScribe extends TileEntityLockable implements ITickable, ISidedI
|
|||
this.currentFuelBuffer = this.fuelTime = getBookUseTime(this.ItemStacks[1]);
|
||||
|
||||
if (this.fuelTime > 0)
|
||||
{
|
||||
flag = true;
|
||||
|
||||
if (this.ItemStacks[1] != null)
|
||||
{
|
||||
--this.ItemStacks[1].stackSize;
|
||||
|
||||
if (this.ItemStacks[1].stackSize == 0)
|
||||
this.ItemStacks[1] = ItemStacks[1].getItem().getContainerItem(ItemStacks[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isUsingFuel() && this.canProcess())
|
||||
if (this.hasConsumedBook() && this.canProcess())
|
||||
{
|
||||
++this.processTime;
|
||||
|
||||
|
|
@ -72,22 +62,24 @@ public class TileScribe extends TileEntityLockable implements ITickable, ISidedI
|
|||
this.processTime = 0;
|
||||
this.totalTime = this.getBookUseTime(this.ItemStacks[0]);
|
||||
this.processItem();
|
||||
this.ItemStacks[1] = null;
|
||||
if(this.ItemStacks[0].stackSize < 1)
|
||||
this.ItemStacks[0] = null;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
this.processTime = 0;
|
||||
}
|
||||
else if (!this.isUsingFuel() && this.processTime > 0)
|
||||
else if (!this.hasConsumedBook() && this.processTime > 0)
|
||||
this.processTime = MathHelper.clamp_int(this.processTime - 2, 0, this.totalTime);
|
||||
|
||||
if (isBurning != this.fuelTime > 0)
|
||||
{
|
||||
flag = true;
|
||||
BlockScribe.updateBlockState(this.isUsingFuel(), this.worldObj, this.pos);
|
||||
BlockScribe.updateBlockState(this.hasConsumedBook(), this.worldObj, this.pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
this.markDirty();
|
||||
}
|
||||
|
|
@ -236,7 +228,7 @@ public class TileScribe extends TileEntityLockable implements ITickable, ISidedI
|
|||
return this.fuelTime * par1 / this.currentFuelBuffer;
|
||||
}
|
||||
|
||||
public boolean isUsingFuel()
|
||||
public boolean hasConsumedBook()
|
||||
{
|
||||
return this.fuelTime > 0;
|
||||
}
|
||||
|
|
@ -246,25 +238,28 @@ public class TileScribe extends TileEntityLockable implements ITickable, ISidedI
|
|||
ItemStack input = this.ItemStacks[0];
|
||||
if (input != null)
|
||||
{
|
||||
ItemStack output = ScribeRecipes.getInstance().getResult(input);
|
||||
if (output == null)
|
||||
return false;
|
||||
ItemStack outputSlot = this.ItemStacks[2];
|
||||
if (outputSlot == null)
|
||||
return true;
|
||||
if (!outputSlot.isItemEqual(output))
|
||||
return false;
|
||||
int result = outputSlot.stackSize + output.stackSize;
|
||||
return result <= output.getMaxStackSize();
|
||||
if (this.ItemStacks[1] != null && isBook(ItemStacks[1]))
|
||||
{
|
||||
ItemStack output = ScribeRecipes.getInstance().getResult(input);
|
||||
if (output == null)
|
||||
return false;
|
||||
ItemStack outputSlot = this.ItemStacks[2];
|
||||
if (input.stackSize < ScribeRecipes.getInstance().getInputStackSizeForOutput(output))
|
||||
return false;
|
||||
if (outputSlot == null)
|
||||
return true;
|
||||
if (!outputSlot.isItemEqual(output))
|
||||
return false;
|
||||
int result = outputSlot.stackSize + output.stackSize;
|
||||
return result <= output.getMaxStackSize();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidForScribe(ItemStack itemstack)
|
||||
{
|
||||
if (ScribeRecipes.getInstance().getResult(itemstack) != null)
|
||||
return true;
|
||||
return false;
|
||||
return (ScribeRecipes.getInstance().getResult(itemstack) != null);
|
||||
}
|
||||
|
||||
public void processItem()
|
||||
|
|
@ -278,23 +273,19 @@ public class TileScribe extends TileEntityLockable implements ITickable, ISidedI
|
|||
ItemStacks[2] = output.copy();
|
||||
else if (outputSlot.isItemEqual(output))
|
||||
outputSlot.stackSize += output.stackSize;
|
||||
ItemStacks[0] = null;
|
||||
int qtyToDecr = ScribeRecipes.getInstance().getInputStackSizeForOutput(output);
|
||||
input.stackSize -= qtyToDecr;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getBookUseTime(ItemStack itemstack)
|
||||
{
|
||||
if (itemstack == null)
|
||||
return 0;
|
||||
return isBook(itemstack) ? proTicks : 0;
|
||||
return itemstack == null ? 0 : (isBook(itemstack) ? proTicks : 0);
|
||||
}
|
||||
|
||||
public static boolean isBook(ItemStack itemstack)
|
||||
{
|
||||
ItemStack temp = new ItemStack(Items.writable_book);
|
||||
if (temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage())
|
||||
return true;
|
||||
return false;
|
||||
return itemstack.getItem() == Items.writable_book;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -403,6 +394,7 @@ public class TileScribe extends TileEntityLockable implements ITickable, ISidedI
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue