forked from GregTechCEu/GregTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Highlighting to the Crafting Station (GregTechCEu#75)
- Loading branch information
Showing
5 changed files
with
91 additions
and
38 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/main/java/gregtech/api/gui/widgets/CraftingStationInputWidgetGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package gregtech.api.gui.widgets; | ||
|
||
import gregtech.api.gui.GuiTextures; | ||
import gregtech.api.gui.IRenderContext; | ||
import gregtech.api.gui.Widget; | ||
import gregtech.api.util.Position; | ||
import gregtech.common.metatileentities.storage.CraftingRecipeResolver; | ||
import net.minecraft.network.PacketBuffer; | ||
import net.minecraftforge.items.ItemStackHandler; | ||
|
||
public class CraftingStationInputWidgetGroup extends AbstractWidgetGroup { | ||
protected CraftingRecipeResolver recipeResolver; | ||
protected short tintLocations; | ||
public static final int LIGHT_RED = 0x66FF0000; | ||
|
||
public CraftingStationInputWidgetGroup(int x, int y, ItemStackHandler craftingGrid, CraftingRecipeResolver recipeResolver) { | ||
super(new Position(x, y)); | ||
|
||
//crafting grid | ||
for (int i = 0; i < 3; ++i) { | ||
for (int j = 0; j < 3; ++j) { | ||
this.addWidget(new PhantomSlotWidget(craftingGrid, j + i * 3, x + j * 18, y + i * 18).setBackgroundTexture(GuiTextures.SLOT)); | ||
} | ||
} | ||
|
||
this.recipeResolver = recipeResolver; | ||
} | ||
|
||
@Override | ||
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) { | ||
super.drawInBackground(mouseX, mouseY, context); | ||
if(this.widgets.size() == 9) { // In case someone added more... | ||
for (int i = 0; i < 9; i++) { | ||
Widget widget = widgets.get(i); | ||
if (widget instanceof PhantomSlotWidget && ((tintLocations >> i) & 1) == 0) { // In other words, is this slot usable? | ||
int color = LIGHT_RED; | ||
|
||
PhantomSlotWidget phantomSlotWidget = (PhantomSlotWidget) widget; | ||
drawSolidRect(phantomSlotWidget.getPosition().x, phantomSlotWidget.getPosition().y, | ||
phantomSlotWidget.getSize().getWidth() - 1, phantomSlotWidget.getSize().getWidth() - 1, color); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void detectAndSendChanges() { | ||
super.detectAndSendChanges(); | ||
short newTintLocations = getTintLocations(); | ||
if (tintLocations != newTintLocations) { | ||
this.tintLocations = newTintLocations; | ||
writeUpdateInfo(2, buffer -> buffer.writeShort(tintLocations)); | ||
} | ||
} | ||
|
||
private short getTintLocations() { | ||
if(recipeResolver.getCachedRecipeData() != null) { | ||
return recipeResolver.getCachedRecipeData().attemptMatchRecipe(); | ||
} else { | ||
return 511; | ||
} | ||
} | ||
|
||
public void readUpdateInfo(int id, PacketBuffer buffer) { | ||
super.readUpdateInfo(id, buffer); | ||
if (id == 2) { | ||
tintLocations = buffer.readShort(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters