-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from CottonMC/rei
Add REI plugin
- Loading branch information
Showing
12 changed files
with
345 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package vivatech.rei; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import me.shedaniel.rei.api.RecipeCategory; | ||
import me.shedaniel.rei.api.RecipeDisplay; | ||
import me.shedaniel.rei.gui.widget.RecipeBaseWidget; | ||
import me.shedaniel.rei.gui.widget.Widget; | ||
import net.minecraft.client.resource.language.I18n; | ||
import net.minecraft.recipe.Recipe; | ||
import net.minecraft.util.Identifier; | ||
import vivatech.rei.widget.CottonSlotWidget; | ||
import vivatech.rei.widget.ProgressBarWidget; | ||
|
||
import java.awt.Rectangle; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
abstract class BaseRecipeCategory implements RecipeCategory<RecipeDisplay<Recipe<?>>> { | ||
private final Identifier id; | ||
private final String translationKey; | ||
|
||
BaseRecipeCategory(Identifier id, String translationKey) { | ||
this.id = id; | ||
this.translationKey = translationKey; | ||
} | ||
|
||
@Override | ||
public Identifier getIdentifier() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public String getCategoryName() { | ||
return I18n.translate(translationKey); | ||
} | ||
|
||
@Override | ||
public List<Widget> setupDisplay(Supplier<RecipeDisplay<Recipe<?>>> recipeDisplaySupplier, Rectangle bounds) { | ||
RecipeDisplay<?> display = recipeDisplaySupplier.get(); | ||
int x = (int) bounds.getCenterX(); | ||
int y = (int) bounds.getCenterY() - 9; | ||
|
||
return ImmutableList.of( | ||
new RecipeBaseWidget(bounds), | ||
new ProgressBarWidget(x - 18 - 5, y, 40, 18, 200), | ||
new CottonSlotWidget(x - 2 * 18 - 9, y, display.getInput().get(0), true, true), | ||
CottonSlotWidget.createBig(x + 2 * 18 - 9, y, display.getOutput(), true, true) | ||
); | ||
} | ||
} |
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,17 @@ | ||
package vivatech.rei; | ||
|
||
import me.shedaniel.rei.api.Renderable; | ||
import me.shedaniel.rei.api.Renderer; | ||
import net.minecraft.item.ItemStack; | ||
import vivatech.init.VivatechBlocks; | ||
|
||
final class CrushingCategory extends BaseRecipeCategory { | ||
CrushingCategory() { | ||
super(VivatechREIPlugin.CRUSHING, "gui.vivatech.crushing"); | ||
} | ||
|
||
@Override | ||
public Renderer getIcon() { | ||
return Renderable.fromItemStack(new ItemStack(VivatechBlocks.CRUSHER)); | ||
} | ||
} |
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,52 @@ | ||
package vivatech.rei; | ||
|
||
import me.shedaniel.rei.api.RecipeDisplay; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Identifier; | ||
import vivatech.recipe.CrushingRecipe; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
final class CrushingDisplay implements RecipeDisplay<CrushingRecipe> { | ||
private final CrushingRecipe recipe; | ||
private final List<List<ItemStack>> input; | ||
private final List<ItemStack> output; | ||
// private final List<ItemStack> bonusStacks; | ||
|
||
CrushingDisplay(CrushingRecipe recipe) { | ||
this.recipe = recipe; | ||
input = recipe.getPreviewInputs().stream() | ||
.map(ingredient -> Arrays.asList(ingredient.getStackArray())) | ||
.collect(Collectors.toList()); | ||
output = Collections.singletonList(recipe.getOutput()); | ||
//bonusStacks = LootUtils.getAllStacks(recipe.getBonusLootTable()); | ||
} | ||
|
||
@Override | ||
public Optional<CrushingRecipe> getRecipe() { | ||
return Optional.of(recipe); | ||
} | ||
|
||
@Override | ||
public List<List<ItemStack>> getInput() { | ||
return input; | ||
} | ||
|
||
@Override | ||
public List<ItemStack> getOutput() { | ||
return output; | ||
} | ||
|
||
@Override | ||
public Identifier getRecipeCategory() { | ||
return VivatechREIPlugin.CRUSHING; | ||
} | ||
|
||
/*public List<ItemStack> getBonusStacks() { | ||
return bonusStacks; | ||
}*/ | ||
} |
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,17 @@ | ||
package vivatech.rei; | ||
|
||
import me.shedaniel.rei.api.Renderable; | ||
import me.shedaniel.rei.api.Renderer; | ||
import net.minecraft.item.ItemStack; | ||
import vivatech.init.VivatechBlocks; | ||
|
||
final class PressingCategory extends BaseRecipeCategory { | ||
PressingCategory() { | ||
super(VivatechREIPlugin.PRESSING, "gui.vivatech.pressing"); | ||
} | ||
|
||
@Override | ||
public Renderer getIcon() { | ||
return Renderable.fromItemStack(new ItemStack(VivatechBlocks.PRESS)); | ||
} | ||
} |
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,52 @@ | ||
package vivatech.rei; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import me.shedaniel.rei.api.RecipeDisplay; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Identifier; | ||
import vivatech.recipe.PressingRecipe; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
final class PressingDisplay implements RecipeDisplay<PressingRecipe> { | ||
private final PressingRecipe recipe; | ||
private final List<List<ItemStack>> input; | ||
private final List<ItemStack> output; | ||
|
||
PressingDisplay(PressingRecipe recipe) { | ||
this.recipe = recipe; | ||
input = recipe.getPreviewInputs().stream() | ||
.map(ingredient -> Arrays.asList(ingredient.getStackArray())) | ||
.collect(Collectors.toList()); | ||
|
||
output = ImmutableList.of(recipe.getOutput()); | ||
} | ||
|
||
@Override | ||
public Optional<PressingRecipe> getRecipe() { | ||
return Optional.of(recipe); | ||
} | ||
|
||
@Override | ||
public List<List<ItemStack>> getInput() { | ||
return input; | ||
} | ||
|
||
@Override | ||
public List<ItemStack> getOutput() { | ||
return output; | ||
} | ||
|
||
@Override | ||
public List<List<ItemStack>> getRequiredItems() { | ||
return input; | ||
} | ||
|
||
@Override | ||
public Identifier getRecipeCategory() { | ||
return VivatechREIPlugin.PRESSING; | ||
} | ||
} |
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,36 @@ | ||
package vivatech.rei; | ||
|
||
import me.shedaniel.rei.api.REIPluginEntry; | ||
import me.shedaniel.rei.api.RecipeHelper; | ||
import net.minecraft.recipe.Recipe; | ||
import net.minecraft.util.Identifier; | ||
import vivatech.recipe.CrushingRecipe; | ||
import vivatech.recipe.PressingRecipe; | ||
|
||
public final class VivatechREIPlugin implements REIPluginEntry { | ||
public static final Identifier ID = new Identifier("vivatech", "rei_plugin"); | ||
public static final Identifier CRUSHING = new Identifier("vivatech", "crushing"); | ||
public static final Identifier PRESSING = new Identifier("vivatech", "pressing"); | ||
|
||
@Override | ||
public Identifier getPluginIdentifier() { | ||
return ID; | ||
} | ||
|
||
@Override | ||
public void registerPluginCategories(RecipeHelper recipeHelper) { | ||
recipeHelper.registerCategory(new CrushingCategory()); | ||
recipeHelper.registerCategory(new PressingCategory()); | ||
} | ||
|
||
@Override | ||
public void registerRecipeDisplays(RecipeHelper recipeHelper) { | ||
for (Recipe<?> recipe : recipeHelper.getAllSortedRecipes()) { | ||
if (recipe instanceof PressingRecipe) { | ||
recipeHelper.registerDisplay(PRESSING, new PressingDisplay((PressingRecipe) recipe)); | ||
} else if (recipe instanceof CrushingRecipe) { | ||
recipeHelper.registerDisplay(CRUSHING, new CrushingDisplay((CrushingRecipe) recipe)); | ||
} | ||
} | ||
} | ||
} |
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,38 @@ | ||
package vivatech.rei.widget; | ||
|
||
import io.github.cottonmc.cotton.gui.EmptyInventory; | ||
import io.github.cottonmc.cotton.gui.widget.WItemSlot; | ||
import me.shedaniel.rei.gui.widget.SlotWidget; | ||
import net.minecraft.item.ItemStack; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A slot widget that uses Cotton's {@link WItemSlot} for rendering. | ||
*/ | ||
public final class CottonSlotWidget extends SlotWidget { | ||
private final WItemSlot renderSlot; | ||
private final int x; | ||
private final int y; | ||
|
||
private CottonSlotWidget(int x, int y, List<ItemStack> itemList, boolean showToolTips, boolean clickToMoreRecipes, WItemSlot renderSlot) { | ||
super(x, y, itemList, false, showToolTips, clickToMoreRecipes); | ||
this.renderSlot = renderSlot; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public CottonSlotWidget(int x, int y, List<ItemStack> itemList, boolean showToolTips, boolean clickToMoreRecipes) { | ||
this(x, y, itemList, showToolTips, clickToMoreRecipes, WItemSlot.of(EmptyInventory.INSTANCE, 0)); | ||
} | ||
|
||
public static CottonSlotWidget createBig(int x, int y, List<ItemStack> itemList, boolean showToolTips, boolean clickToMoreRecipes) { | ||
return new CottonSlotWidget(x, y, itemList, showToolTips, clickToMoreRecipes, WItemSlot.outputOf(EmptyInventory.INSTANCE, 0)); | ||
} | ||
|
||
@Override | ||
public void render(int mouseX, int mouseY, float delta) { | ||
renderSlot.paintBackground(x, y); | ||
super.render(mouseX, mouseY, delta); | ||
} | ||
} |
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,56 @@ | ||
package vivatech.rei.widget; | ||
|
||
import io.github.cottonmc.cotton.gui.widget.WBar; | ||
import me.shedaniel.rei.gui.widget.Widget; | ||
import net.minecraft.client.gui.Element; | ||
import net.minecraft.client.render.GuiLighting; | ||
import net.minecraft.container.PropertyDelegate; | ||
import vivatech.VivatechClient; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* A progress bar widget that uses Cotton's {@link WBar} for drawing. | ||
*/ | ||
public final class ProgressBarWidget extends Widget { | ||
private final int x; | ||
private final int y; | ||
private final WBar renderBar; | ||
|
||
public ProgressBarWidget(int x, int y, int width, int height, int maxProgress) { | ||
this.x = x; | ||
this.y = y; | ||
PropertyDelegate renderProperties = new PropertyDelegate() { | ||
@Override | ||
public int get(int i) { | ||
if (i == 0) | ||
return ((int) System.currentTimeMillis() / 10) % maxProgress; | ||
else | ||
return maxProgress; | ||
} | ||
|
||
@Override | ||
public void set(int i, int value) { | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return 2; | ||
} | ||
}; | ||
renderBar = new RenderWBar(VivatechClient.PROGRESS_BAR_BG, VivatechClient.PROGRESS_BAR, 0, 1, WBar.Direction.RIGHT, renderProperties); | ||
renderBar.setSize(width, height); | ||
} | ||
|
||
@Override | ||
public void render(int mouseX, int mouseY, float delta) { | ||
GuiLighting.disable(); | ||
renderBar.paintBackground(x, y); | ||
} | ||
|
||
@Override | ||
public List<? extends Element> children() { | ||
return Collections.emptyList(); | ||
} | ||
} |
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,15 @@ | ||
package vivatech.rei.widget; | ||
|
||
import io.github.cottonmc.cotton.gui.widget.WBar; | ||
import net.minecraft.container.PropertyDelegate; | ||
import net.minecraft.util.Identifier; | ||
|
||
/** | ||
* A {@link WBar} subclass that sets the property delegate through the constructor. | ||
*/ | ||
final class RenderWBar extends WBar { | ||
RenderWBar(Identifier bg, Identifier bar, int field, int maxfield, Direction dir, PropertyDelegate properties) { | ||
super(bg, bar, field, maxfield, dir); | ||
this.properties = properties; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ | |
], | ||
"client": [ | ||
"vivatech.VivatechClient" | ||
], | ||
"rei_plugins": [ | ||
"vivatech.rei.VivatechREIPlugin" | ||
] | ||
}, | ||
|
||
|