use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.
the class TileAssemblyTable method activateNextRecipe.
private void activateNextRecipe() {
AssemblyInstruction activeRecipe = getActiveRecipe();
if (activeRecipe != null) {
int index = 0;
int activeIndex = 0;
boolean isActiveLast = false;
long enoughCount = recipesStates.values().stream().filter(state -> state == EnumAssemblyRecipeState.SAVED_ENOUGH || state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE).count();
if (enoughCount <= 1) {
return;
}
for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
EnumAssemblyRecipeState state = entry.getValue();
if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
isActiveLast = false;
}
if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
state = EnumAssemblyRecipeState.SAVED_ENOUGH;
entry.setValue(state);
activeIndex = index;
isActiveLast = true;
}
index++;
}
index = 0;
for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
AssemblyRecipe recipe = entry.getKey().recipe;
EnumAssemblyRecipeState state = entry.getValue();
if (state == EnumAssemblyRecipeState.SAVED_ENOUGH && recipe != activeRecipe.recipe && (index > activeIndex || isActiveLast)) {
state = EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE;
entry.setValue(state);
break;
}
index++;
}
}
}
use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.
the class TileAssemblyTable method readPayload.
@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
super.readPayload(id, buffer, side, ctx);
if (id == NET_GUI_DATA) {
recipesStates.clear();
int count = buffer.readInt();
for (int i = 0; i < count; i++) {
AssemblyInstruction instruction = lookupRecipe(buffer.readString(), buffer.readItemStack());
recipesStates.put(instruction, EnumAssemblyRecipeState.values()[buffer.readInt()]);
}
}
if (id == NET_RECIPE_STATE) {
AssemblyInstruction recipe = lookupRecipe(buffer.readString(), buffer.readItemStack());
EnumAssemblyRecipeState state = EnumAssemblyRecipeState.values()[buffer.readInt()];
if (recipesStates.containsKey(recipe)) {
recipesStates.put(recipe, state);
}
}
}
use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.
the class GuiAssemblyTable method drawBackgroundLayer.
@Override
protected void drawBackgroundLayer(float partialTicks) {
ICON_GUI.drawAt(mainGui.rootElement);
long target = container.tile.getTarget();
if (target != 0) {
double v = (double) container.tile.power / target;
ICON_PROGRESS.drawCutInside(new GuiRectangle(RECT_PROGRESS.x, (int) (RECT_PROGRESS.y + RECT_PROGRESS.height * Math.max(1 - v, 0)), RECT_PROGRESS.width, (int) Math.ceil(RECT_PROGRESS.height * Math.min(v, 1))).offset(mainGui.rootElement));
}
for (int i = 0; i < container.tile.recipesStates.size(); i++) {
EnumAssemblyRecipeState state = new ArrayList<>(container.tile.recipesStates.values()).get(i);
if (state == EnumAssemblyRecipeState.SAVED) {
ICON_SAVED.drawAt(getArea(i));
}
if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
ICON_SAVED_ENOUGH.drawAt(getArea(i));
}
if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
ICON_SAVED_ENOUGH_ACTIVE.drawAt(getArea(i));
}
}
}
use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.
the class TileAssemblyTable method updateRecipes.
private void updateRecipes() {
// TODO: rework this to not iterate over every recipe every tick
int count = recipesStates.size();
for (AssemblyRecipe recipe : AssemblyRecipeRegistry.REGISTRY.values()) {
Set<ItemStack> outputs = recipe.getOutputs(inv.stacks);
for (ItemStack out : outputs) {
boolean found = false;
for (AssemblyInstruction instruction : recipesStates.keySet()) {
if (instruction.recipe == recipe && out == instruction.output) {
found = true;
break;
}
}
AssemblyInstruction instruction = new AssemblyInstruction(recipe, out);
if (!found && !recipesStates.containsKey(instruction)) {
recipesStates.put(instruction, EnumAssemblyRecipeState.POSSIBLE);
}
}
}
boolean findActive = false;
for (Iterator<Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState>> iterator = recipesStates.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry = iterator.next();
AssemblyInstruction instruction = entry.getKey();
EnumAssemblyRecipeState state = entry.getValue();
boolean enough = extract(inv, instruction.recipe.getInputsFor(instruction.output), true, false);
if (state == EnumAssemblyRecipeState.POSSIBLE) {
if (!enough) {
iterator.remove();
}
} else {
if (enough) {
if (state == EnumAssemblyRecipeState.SAVED) {
state = EnumAssemblyRecipeState.SAVED_ENOUGH;
}
} else {
if (state != EnumAssemblyRecipeState.SAVED) {
state = EnumAssemblyRecipeState.SAVED;
}
}
}
if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
findActive = true;
}
entry.setValue(state);
}
if (!findActive) {
for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
EnumAssemblyRecipeState state = entry.getValue();
if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
state = EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE;
entry.setValue(state);
break;
}
}
}
if (count != recipesStates.size()) {
sendNetworkGuiUpdate(NET_GUI_DATA);
}
}
use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.
the class GuiAssemblyTable method mouseClicked.
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
if (mouseButton == 0) {
for (int i = 0; i < container.tile.recipesStates.size(); i++) {
TileAssemblyTable.AssemblyInstruction instruction = new ArrayList<>(container.tile.recipesStates.keySet()).get(i);
EnumAssemblyRecipeState state = new ArrayList<>(container.tile.recipesStates.values()).get(i);
if (getArea(i).contains(mouseX, mouseY)) {
container.tile.sendRecipeStateToServer(instruction, state == EnumAssemblyRecipeState.POSSIBLE ? EnumAssemblyRecipeState.SAVED : EnumAssemblyRecipeState.POSSIBLE);
}
}
}
}
Aggregations