further fixes to the integration table, #1861
This commit is contained in:
parent
fd926ff0e0
commit
eda4d58c9e
2 changed files with 66 additions and 37 deletions
|
@ -36,7 +36,6 @@ public class TileIntegrationTable extends TileLaserTableBase {
|
|||
private InventoryMapper invOutput = new InventoryMapper(inv, SLOT_OUTPUT, 1, false);
|
||||
private IFlexibleRecipe activeRecipe;
|
||||
private CraftingResult craftingPreview;
|
||||
private boolean canCraft = false;
|
||||
|
||||
public IInventory getRecipeOutput() {
|
||||
return invRecipeOutput;
|
||||
|
@ -50,6 +49,13 @@ public class TileIntegrationTable extends TileLaserTableBase {
|
|||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
updateRecipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
@ -58,32 +64,21 @@ public class TileIntegrationTable extends TileLaserTableBase {
|
|||
return;
|
||||
}
|
||||
|
||||
if (activeRecipe == null || craftingPreview == null) {
|
||||
setEnergy(0);
|
||||
return;
|
||||
}
|
||||
|
||||
tick++;
|
||||
if (tick % CYCLE_LENGTH != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
canCraft = false;
|
||||
|
||||
ItemStack inputA = inv.getStackInSlot(SLOT_INPUT_A);
|
||||
ItemStack inputB = inv.getStackInSlot(SLOT_INPUT_B);
|
||||
ItemStack[] components = getComponents();
|
||||
setNewActiveRecipe(inputA, inputB, components);
|
||||
|
||||
if (activeRecipe == null || craftingPreview == null) {
|
||||
setEnergy(0);
|
||||
return;
|
||||
}
|
||||
|
||||
invRecipeOutput.setInventorySlotContents(0, (ItemStack) craftingPreview.crafted);
|
||||
|
||||
if (!isRoomForOutput((ItemStack) craftingPreview.crafted)) {
|
||||
setEnergy(0);
|
||||
return;
|
||||
}
|
||||
|
||||
canCraft = true;
|
||||
|
||||
if (getEnergy() >= craftingPreview.energyCost
|
||||
&& lastMode != ActionMachineControl.Mode.Off) {
|
||||
setEnergy(0);
|
||||
|
@ -101,6 +96,8 @@ public class TileIntegrationTable extends TileLaserTableBase {
|
|||
}
|
||||
|
||||
private void setNewActiveRecipe(ItemStack inputA, ItemStack inputB, ItemStack[] components) {
|
||||
craftingPreview = null;
|
||||
|
||||
for (IIntegrationRecipeFactory recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
|
||||
if (recipe.isValidInputA(inputA) && recipe.isValidInputB(inputB)) {
|
||||
craftingPreview = recipe.craftPreview(this, null);
|
||||
|
@ -135,7 +132,7 @@ public class TileIntegrationTable extends TileLaserTableBase {
|
|||
|
||||
@Override
|
||||
public boolean canCraft() {
|
||||
return canCraft && isActive();
|
||||
return isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -161,11 +158,13 @@ public class TileIntegrationTable extends TileLaserTableBase {
|
|||
|
||||
private boolean isValidInputB(ItemStack stack) {
|
||||
ItemStack inputA = inv.getStackInSlot(SLOT_INPUT_A);
|
||||
|
||||
for (IIntegrationRecipeFactory recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
|
||||
if (recipe.isValidInputB(stack) && (inputA == null || recipe.isValidInputA(inputA))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -186,7 +185,36 @@ public class TileIntegrationTable extends TileLaserTableBase {
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return activeRecipe != null && super.isActive();
|
||||
return craftingPreview != null && super.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
super.setInventorySlotContents(slot, stack);
|
||||
|
||||
updateRecipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
ItemStack result = super.decrStackSize(slot, amount);
|
||||
|
||||
updateRecipe();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateRecipe() {
|
||||
ItemStack inputA = inv.getStackInSlot(SLOT_INPUT_A);
|
||||
ItemStack inputB = inv.getStackInSlot(SLOT_INPUT_B);
|
||||
ItemStack[] components = getComponents();
|
||||
setNewActiveRecipe(inputA, inputB, components);
|
||||
|
||||
if (craftingPreview != null) {
|
||||
invRecipeOutput.setInventorySlotContents(0, (ItemStack) craftingPreview.crafted);
|
||||
} else {
|
||||
invRecipeOutput.setInventorySlotContents(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -160,29 +160,30 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
|
|||
public void getGUINetworkData(int id, int data) {
|
||||
int currentStored = (int) (energy * 100.0);
|
||||
int requiredEnergy = (int) (clientRequiredEnergy * 100.0);
|
||||
|
||||
switch (id) {
|
||||
case 0:
|
||||
requiredEnergy = (requiredEnergy & 0xFFFF0000) | (data & 0xFFFF);
|
||||
case 0:
|
||||
requiredEnergy = (requiredEnergy & 0xFFFF0000) | (data & 0xFFFF);
|
||||
clientRequiredEnergy = requiredEnergy / 100.0f;
|
||||
break;
|
||||
case 1:
|
||||
currentStored = (currentStored & 0xFFFF0000) | (data & 0xFFFF);
|
||||
break;
|
||||
case 1:
|
||||
currentStored = (currentStored & 0xFFFF0000) | (data & 0xFFFF);
|
||||
energy = currentStored / 100.0f;
|
||||
break;
|
||||
case 2:
|
||||
requiredEnergy = (requiredEnergy & 0xFFFF) | ((data & 0xFFFF) << 16);
|
||||
break;
|
||||
case 2:
|
||||
requiredEnergy = (requiredEnergy & 0xFFFF) | ((data & 0xFFFF) << 16);
|
||||
clientRequiredEnergy = requiredEnergy / 100.0f;
|
||||
break;
|
||||
case 3:
|
||||
currentStored = (currentStored & 0xFFFF) | ((data & 0xFFFF) << 16);
|
||||
break;
|
||||
case 3:
|
||||
currentStored = (currentStored & 0xFFFF) | ((data & 0xFFFF) << 16);
|
||||
energy = currentStored / 100.0f;
|
||||
break;
|
||||
case 4:
|
||||
recentEnergyAverage = recentEnergyAverage & 0xFFFF0000 | (data & 0xFFFF);
|
||||
break;
|
||||
case 5:
|
||||
recentEnergyAverage = (recentEnergyAverage & 0xFFFF) | ((data & 0xFFFF) << 16);
|
||||
break;
|
||||
break;
|
||||
case 4:
|
||||
recentEnergyAverage = recentEnergyAverage & 0xFFFF0000 | (data & 0xFFFF);
|
||||
break;
|
||||
case 5:
|
||||
recentEnergyAverage = (recentEnergyAverage & 0xFFFF) | ((data & 0xFFFF) << 16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue