Added first cut of tesseract recipe.

Refactor of machine recipes to support better multiple outputs and the giving of experience.
Alloy furnace now gives the same experience as a vanilla furnace if items taken manually.
This commit is contained in:
cp committed 2013-09-17 23:57:52 +08:00
1 parent 7dbe3085f0
commit 801320e472
16 files changed
+226 -51

No files matched your search

@@ -1,6 +1,5 @@
package crazypants.enderio.machine;
import crazypants.enderio.ModObject;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@@ -16,10 +15,10 @@ public abstract class AbstractMachineContainer extends Container {
addMachineSlots(playerInv);
addSlotToContainer(new Slot(te, te.inventory.length - 1, 12, 60) {
addSlotToContainer(new Slot(te, te.getSlotDefinition().getMinUpgradeSlot(), 12, 60) {
@Override
public boolean isItemValid(ItemStack itemStack) {
return tileEntity.isItemValidForSlot(tileEntity.inventory.length - 1, itemStack);
return tileEntity.isItemValidForSlot(tileEntity.getSlotDefinition().getMinUpgradeSlot(), itemStack);
}
});
@@ -44,11 +43,10 @@ public abstract class AbstractMachineContainer extends Container {
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
boolean hasOutput = tileEntity.getSizeInventory() > 2; // Assume one input
// and capacitor
int outputSlot = tileEntity.getSizeInventory() - 2;
int capacitorSlot = outputSlot + 1;
int startPlayerSlot = capacitorSlot + 1;
SlotDefinition slotDef = tileEntity.getSlotDefinition();
int startPlayerSlot = slotDef.getNumSlots();
int endPlayerSlot = startPlayerSlot + 26;
int startHotBarSlot = endPlayerSlot + 1;
int endHotBarSlot = startHotBarSlot + 9;
@@ -60,47 +58,36 @@ public abstract class AbstractMachineContainer extends Container {
ItemStack origStack = slot.getStack();
copystack = origStack.copy();
if ((hasOutput ? (slotIndex < outputSlot) : (slotIndex <= outputSlot)) || slotIndex == capacitorSlot) {
if (slotDef.isInputSlot(slotIndex) || slotDef.isUpgradeSlot(slotIndex)) {
// merge from machine input slots to inventory
if (!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, false)) {
return null;
}
} else if (hasOutput && slotIndex == outputSlot) { // merge result
} else if (slotDef.isOutputSlot(slotIndex)) {
// merge result
if (!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, true)) {
return null;
}
slot.onSlotChange(origStack, copystack);
} else /* if (slotIndex > capacitorSlot) */{ // from inventory into inputs
boolean merged = false;
for (int i = 0; (hasOutput ? (i < outputSlot) : (i <= outputSlot)) && !merged; i++) {
if (tileEntity.isItemValidForSlot(i, origStack)) {
merged = mergeItemStack(origStack, i, i + 1, false);
}
}
// check for capacitor mergers
if (!merged) {
if (tileEntity.isItemValidForSlot(capacitorSlot, origStack)) {
merged = mergeItemStack(origStack, capacitorSlot, capacitorSlot + 1, false);
}
}
if(!merged) {
if(slotIndex >= startPlayerSlot && slotIndex <= endPlayerSlot) {
if(!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false)) {
return null;
}
} else if(slotIndex >= startHotBarSlot && slotIndex <= endHotBarSlot) {
if(!mergeItemStack(origStack, startPlayerSlot, endPlayerSlot, false)) {
return null;
} else {
//Check from inv->input then inv->upgrade then inv->hotbar or hotbar->inv
if (slotIndex >= startPlayerSlot) {
if (!tileEntity.isValidInput(origStack) || !mergeItemStack(origStack, slotDef.getMinInputSlot(), slotDef.getMaxInputSlot() + 1, false)) {
if (!tileEntity.isValidUpgrade(origStack) || !mergeItemStack(origStack, slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1, false)) {
if (slotIndex <= endPlayerSlot) {
if (!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false)) {
return null;
}
} else if (slotIndex >= startHotBarSlot && slotIndex <= endHotBarSlot) {
if (!mergeItemStack(origStack, startPlayerSlot, endPlayerSlot, false)) {
return null;
}
}
}
}
}
}
if (origStack.stackSize == 0) {
@@ -108,7 +95,7 @@ public abstract class AbstractMachineContainer extends Container {
} else {
slot.onSlotChanged();
}
slot.onSlotChanged();
if (origStack.stackSize == copystack.stackSize) {
@@ -56,12 +56,47 @@ public abstract class AbstractMachineEntity extends TileEntity implements IInven
redstoneControlMode = RedstoneControlMode.IGNORE;
}
public SlotDefinition getSlotDefinition() {
return slotDefinition;
}
public boolean isValidUpgrade(ItemStack itemstack) {
for(int i=slotDefinition.getMinUpgradeSlot(); i <= slotDefinition.getMaxUpgradeSlot(); i++) {
if(isItemValidForSlot(i, itemstack)) {
return true;
}
}
return false;
}
public boolean isValidInput(ItemStack itemstack) {
for(int i=slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) {
if(isItemValidForSlot(i, itemstack)) {
return true;
}
}
return false;
}
public boolean isValidOutput(ItemStack itemstack) {
for(int i=slotDefinition.getMinOutputSlot(); i <= slotDefinition.getMaxOutputSlot(); i++) {
if(isItemValidForSlot(i, itemstack)) {
return true;
}
}
return false;
}
@Override
public final boolean isItemValidForSlot(int i, ItemStack itemstack) {
System.out.println("AbstractMachineEntity.isItemValidForSlot: Testing slot " + i + " from valid input.");
if (slotDefinition.isUpgradeSlot(i)) {
System.out.println("AbstractMachineEntity.isItemValidForSlot: is a valid upgrade");
return itemstack.itemID == ModObject.itemBasicCapacitor.actualId && itemstack.getItemDamage() > 0;
}
return isMachineItemValidForSlot(i, itemstack);
boolean ret = isMachineItemValidForSlot(i, itemstack);
System.out.println("AbstractMachineEntity.isItemValidForSlot: isMachineItemValidForSlot says: " + ret);
return ret;
}
protected abstract boolean isMachineItemValidForSlot(int i, ItemStack itemstack);
@@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity implements ISidedInventory {
protected PoweredTask currentTask = null;
protected IMachineRecipe lastCompletedRecipe;
public AbstractPoweredTaskEntity(SlotDefinition slotDefinition) {
super(slotDefinition);
@@ -59,6 +60,13 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
public float getProgress() {
return currentTask == null ? 0 : currentTask.getProgress();
}
public float getExperienceForOutput(ItemStack output) {
if(lastCompletedRecipe == null) {
return 0;
}
return lastCompletedRecipe.getExperianceForOutput(output);
}
@Override
protected boolean processTasks(boolean redstoneChecksPassed) {
@@ -99,6 +107,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
protected void taskComplete() {
int outputIndex = inventory.length - 2;
if (currentTask != null) {
lastCompletedRecipe = currentTask.getRecipe();
ItemStack[] output = currentTask.getCompletedResult();
if (output != null && output.length > 0) {
ItemStack result = currentTask.getCompletedResult()[0];
@@ -190,6 +199,8 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
public void readFromNBT(NBTTagCompound nbtRoot) {
super.readFromNBT(nbtRoot);
currentTask = PoweredTask.readFromNBT(nbtRoot.getCompoundTag("currentTask"));
String uid = nbtRoot.getString("lastCompletedRecipe");
lastCompletedRecipe = MachineRecipeRegistry.instance.getRecipeForUid(uid);
}
@Override
@@ -200,6 +211,9 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
currentTask.writeToNBT(currentTaskNBT);
nbtRoot.setCompoundTag("currentTask", currentTaskNBT);
}
if(lastCompletedRecipe != null) {
nbtRoot.setString("lastCompletedRecipe", lastCompletedRecipe.getUid());
}
}
}
@@ -11,6 +11,8 @@ public interface IMachineRecipe {
public boolean isRecipe(RecipeInput... inputs);
ItemStack[] getCompletedResult(RecipeInput... inputs);
float getExperianceForOutput(ItemStack output);
boolean isValidInput(int slotNumber, ItemStack item);
@@ -26,6 +26,9 @@ public class MachineRecipeRegistry {
}
public IMachineRecipe getRecipeForUid(String uid) {
if(uid == null) {
return null;
}
for (Map<String, IMachineRecipe> recipes : machineRecipes.values()) {
for (IMachineRecipe recipe : recipes.values()) {
if (uid.equals(recipe.getUid())) {
@@ -63,6 +63,12 @@ public class MachineRecipes {
ItemStack capacitorBank = new ItemStack(blockCapacitorBank.actualId,1,0);
GameRegistry.addShapedRecipe(capacitorBank , "bab", "aca", "bab", 'a', activtedCapacitor,'b', industialBinder, 'c', capacitor);
ItemStack enderCapacitor = new ItemStack(itemBasicCapacitor.actualId, 1, Capacitors.ENDER_CAPACITOR.ordinal());
ItemStack tesseract = new ItemStack(ModObject.blockHyperCube.actualId, 1, 0);
ItemStack obsidian = new ItemStack(Block.obsidian);
ItemStack enderPearl = new ItemStack(Item.enderPearl);
GameRegistry.addShapedRecipe(tesseract, "oeo", "e e", "oco", 'o', obsidian,'e', enderPearl, 'c', enderCapacitor);
//To-do: Sort this class
}
@@ -118,4 +118,8 @@ public class PoweredTask {
return null;
}
public IMachineRecipe getRecipe() {
return recipe;
}
}
@@ -44,15 +44,39 @@ public class SlotDefinition {
public int getNumInputSlots() {
return Math.max(0, maxInputSlot - minInputSlot + 1);
}
public int getNumOutputSlots() {
return Math.max(0, maxOutputSlot - minOutputSlot + 1);
public int getNumOutputSlots() {
return Math.max(0, maxOutputSlot - minOutputSlot + 1);
}
public int getNumSlots() {
return Math.max(Math.max(maxInputSlot, maxOutputSlot), maxUpgradeSlot) + 1;
}
public int getMinUpgradeSlot() {
return minUpgradeSlot;
}
public int getMaxUpgradeSlot() {
return maxUpgradeSlot;
}
public int getMinInputSlot() {
return minInputSlot;
}
public int getMaxInputSlot() {
return maxInputSlot;
}
public int getMinOutputSlot() {
return minOutputSlot;
}
public int getMaxOutputSlot() {
return maxOutputSlot;
}
@Override
public String toString() {
return "SlotDefinition [minUpgradeSlot=" + minUpgradeSlot + ", maxUpgradeSlot=" + maxUpgradeSlot + ", minInputSlot=" + minInputSlot + ", maxInputSlot="
@@ -170,10 +170,11 @@ public class BasicAlloyRecipe implements IMachineRecipe {
return true;
}
}
@Override
public float getExperianceForOutput(ItemStack output) {
return 0;
}
}
@@ -1,15 +1,22 @@
package crazypants.enderio.machine.alloy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.AbstractMachineContainer;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.util.Util;
public class ContainerAlloySmelter extends AbstractMachineContainer {
public ContainerAlloySmelter(InventoryPlayer playerInv, AbstractMachineEntity te) {
private EntityPlayer thePlayer;
private TileAlloySmelter smelter;
public ContainerAlloySmelter(InventoryPlayer playerInv, TileAlloySmelter te) {
super(playerInv, te);
thePlayer = playerInv.player;
smelter = te;
}
@Override
@@ -32,13 +39,60 @@ public class ContainerAlloySmelter extends AbstractMachineContainer {
return tileEntity.isItemValidForSlot(2, itemStack);
}
});
addSlotToContainer(new Slot(tileEntity, 3, 79, 57) {
addSlotToContainer(new SlotSmelter(tileEntity, 3, 79, 57) {
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
});
}
private class SlotSmelter extends Slot {
int numResults = 0;
public SlotSmelter(IInventory par1iInventory, int par2, int par3, int par4) {
super(par1iInventory, par2, par3, par4);
}
public ItemStack decrStackSize(int par1) {
if (getHasStack()) {
numResults += Math.min(par1, getStack().stackSize);
}
return super.decrStackSize(par1);
}
@Override
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack output) {
onCrafting(output);
super.onPickupFromSlot(par1EntityPlayer, output);
}
protected void onCrafting(ItemStack par1ItemStack, int par2) {
numResults += par2;
onCrafting(par1ItemStack);
}
protected void onCrafting(ItemStack output) {
output.onCrafting(thePlayer.worldObj, thePlayer, numResults);
if (output != null) {
if (!thePlayer.worldObj.isRemote) {
ItemStack outputSized = output.copy();
outputSized.stackSize = numResults;
float experience = smelter.getExperienceForOutput(outputSized);
Util.giveExperience(thePlayer, experience);
}
}
numResults = 0;
}
}
}
@@ -50,7 +50,7 @@ public class TileAlloySmelter extends AbstractPoweredTaskEntity {
@Override
public boolean isMachineItemValidForSlot(int i, ItemStack itemstack) {
if (i >= 3) {
if (i >= slotDefinition.getNumSlots()) {
return false;
}
return !MachineRecipeRegistry.instance.getRecipesForInput(getMachineName(), RecipeInput.create(i, itemstack)).isEmpty();
@@ -76,6 +76,15 @@ public class VanillaSmeltingRecipe implements IMachineRecipe {
result.stackSize = result.stackSize * getNumInputs(inputs);
return new ItemStack[] { result };
}
@Override
public float getExperianceForOutput(ItemStack output) {
if(output == null) {
return 0;
}
float result = FurnaceRecipes.smelting().getExperience(output);
return result * output.stackSize;
}
@Override
public boolean isValidInput(int slotNumber, ItemStack item) {
@@ -63,4 +63,9 @@ public class CrusherMachineRecipe implements IMachineRecipe {
return res;
}
@Override
public float getExperianceForOutput(ItemStack output) {
return 0;
}
}
@@ -134,4 +134,9 @@ public class BasicPainterTemplate implements IMachineRecipe {
return null;
}
@Override
public float getExperianceForOutput(ItemStack output) {
return 0;
}
}
@@ -98,4 +98,12 @@ public class FusedQuartzRecipe implements IMachineRecipe {
return 0;
}
@Override
public float getExperianceForOutput(ItemStack output) {
if(output == null) {
return 0;
}
return 0.2F * output.stackSize;
}
}
+18
View File
@@ -2,11 +2,13 @@ package crazypants.util;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class Util {
@@ -52,6 +54,22 @@ public class Util {
}
}
public static void giveExperience(EntityPlayer thePlayer, float experience) {
if (experience < 1.0F) {
int rndRound = MathHelper.floor_float(experience);
if (rndRound < MathHelper.ceiling_float_int(experience) && (float) Math.random() < experience) {
++rndRound;
}
experience = rndRound;
}
int intExp = Math.round(experience);
while (intExp > 0) {
int j = EntityXPOrb.getXPSplit(intExp);
intExp -= j;
thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(thePlayer.worldObj, thePlayer.posX, thePlayer.posY + 0.5D, thePlayer.posZ + 0.5D, j));
}
}
// derived from ItemBlock.onItemUse
public static BlockCoord canPlaceItem(ItemStack itemUsed, int blockIdToBePlaced, EntityPlayer player, World world, int x, int y, int z, int side) {
int i1 = world.getBlockId(x, y, z);