Mechanical Crafting in JEI

- Added Mechanical Crafting to the JEI plugin
This commit is contained in:
simibubi 2020-02-03 01:47:59 +01:00
parent 005a9e3177
commit 0099fe9b0d
4 changed files with 225 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import com.simibubi.create.compat.jei.category.BlockCuttingCategory;
import com.simibubi.create.compat.jei.category.BlockCuttingCategory.CondensedBlockCuttingRecipe;
import com.simibubi.create.compat.jei.category.BlockzapperUpgradeCategory;
import com.simibubi.create.compat.jei.category.CrushingCategory;
import com.simibubi.create.compat.jei.category.MechanicalCraftingCategory;
import com.simibubi.create.compat.jei.category.MixingCategory;
import com.simibubi.create.compat.jei.category.MysteriousItemConversionCategory;
import com.simibubi.create.compat.jei.category.PackingCategory;
@ -23,6 +24,7 @@ import com.simibubi.create.compat.jei.category.SawingCategory;
import com.simibubi.create.compat.jei.category.SmokingViaFanCategory;
import com.simibubi.create.compat.jei.category.SplashingCategory;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.modules.contraptions.components.crafter.MechanicalCraftingRecipe;
import com.simibubi.create.modules.contraptions.components.mixer.MixingRecipe;
import com.simibubi.create.modules.contraptions.components.press.MechanicalPressTileEntity;
import com.simibubi.create.modules.contraptions.processing.ProcessingOutput;
@ -44,6 +46,7 @@ import net.minecraft.item.crafting.ICraftingRecipe;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.ShapedRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
@ -64,6 +67,8 @@ public class CreateJEI implements IModPlugin {
private PackingCategory packingCategory;
private PolishingCategory polishingCategory;
private MysteriousItemConversionCategory mysteryConversionCategory;
private MechanicalCraftingCategory smallMechanicalCraftingCategory;
private MechanicalCraftingCategory largeMechanicalCraftingCategory;
@Override
public ResourceLocation getPluginUid() {
@ -83,6 +88,8 @@ public class CreateJEI implements IModPlugin {
packingCategory = new PackingCategory();
polishingCategory = new PolishingCategory();
mysteryConversionCategory = new MysteriousItemConversionCategory();
smallMechanicalCraftingCategory = new MechanicalCraftingCategory(false);
largeMechanicalCraftingCategory = new MechanicalCraftingCategory(true);
}
@Override
@ -94,7 +101,8 @@ public class CreateJEI implements IModPlugin {
public void registerCategories(IRecipeCategoryRegistration registration) {
registration.addRecipeCategories(crushingCategory, splashingCategory, pressingCategory, smokingCategory,
blastingCategory, blockzapperCategory, mixingCategory, sawingCategory, blockCuttingCategory,
packingCategory, polishingCategory, mysteryConversionCategory);
packingCategory, polishingCategory, mysteryConversionCategory, smallMechanicalCraftingCategory,
largeMechanicalCraftingCategory);
}
@Override
@ -121,6 +129,18 @@ public class CreateJEI implements IModPlugin {
packingCategory.getUid());
registration.addRecipes(findRecipes(AllRecipes.SANDPAPER_POLISHING), polishingCategory.getUid());
registration.addRecipes(MysteriousItemConversionCategory.getRecipes(), mysteryConversionCategory.getUid());
registration.addRecipes(findRecipes(
r -> (r instanceof MechanicalCraftingRecipe) && MechanicalCraftingCategory.isSmall((ShapedRecipe) r)),
smallMechanicalCraftingCategory.getUid());
registration.addRecipes(
findRecipes(r -> (r instanceof ShapedRecipe) && !(r instanceof MechanicalCraftingRecipe)
&& MechanicalCraftingCategory.isSmall((ShapedRecipe) r)),
smallMechanicalCraftingCategory.getUid());
registration.addRecipes(
findRecipes(r -> (r instanceof ShapedRecipe) && !MechanicalCraftingCategory.isSmall((ShapedRecipe) r)),
largeMechanicalCraftingCategory.getUid());
}
@Override
@ -149,6 +169,10 @@ public class CreateJEI implements IModPlugin {
registration.addRecipeCatalyst(new ItemStack(AllBlocks.BASIN.get()), packingCategory.getUid());
registration.addRecipeCatalyst(AllItems.SAND_PAPER.asStack(), polishingCategory.getUid());
registration.addRecipeCatalyst(AllItems.RED_SAND_PAPER.asStack(), polishingCategory.getUid());
registration.addRecipeCatalyst(new ItemStack(AllBlocks.MECHANICAL_CRAFTER.get()),
smallMechanicalCraftingCategory.getUid());
registration.addRecipeCatalyst(new ItemStack(AllBlocks.MECHANICAL_CRAFTER.get()),
largeMechanicalCraftingCategory.getUid());
}
@Override

View File

@ -0,0 +1,122 @@
package com.simibubi.create.compat.jei.category;
import java.util.Arrays;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.Create;
import com.simibubi.create.ScreenResources;
import com.simibubi.create.compat.jei.DoubleItemIcon;
import com.simibubi.create.compat.jei.EmptyBackground;
import com.simibubi.create.compat.jei.category.animations.AnimatedCrafter;
import com.simibubi.create.foundation.utility.Lang;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
public class MechanicalCraftingCategory implements IRecipeCategory<ShapedRecipe> {
private AnimatedCrafter crafter;
private ResourceLocation id;
private IDrawable icon;
private IDrawable background;
private boolean large;
public MechanicalCraftingCategory(boolean large) {
this.large = large;
icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.MECHANICAL_CRAFTER.get()), () -> ItemStack.EMPTY);
crafter = new AnimatedCrafter(large);
id = new ResourceLocation(Create.ID, "mechanical_crafting" + (large ? "_large" : ""));
background = new EmptyBackground(large ? 177 : 177, large ? 235 : 81);
}
public static boolean isSmall(ShapedRecipe recipe) {
return Math.max((recipe).getWidth(), (recipe).getHeight()) <= 4;
}
@Override
public IDrawable getIcon() {
return icon;
}
@Override
public ResourceLocation getUid() {
return id;
}
@Override
public String getTitle() {
return Lang.translate("recipe.mechanical_crafting");
}
@Override
public IDrawable getBackground() {
return background;
}
@Override
public void setIngredients(ShapedRecipe recipe, IIngredients ingredients) {
ingredients.setInputIngredients(recipe.getIngredients());
ingredients.setOutput(VanillaTypes.ITEM, recipe.getRecipeOutput());
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, ShapedRecipe recipe, IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
NonNullList<Ingredient> recipeIngredients = recipe.getIngredients();
itemStacks.init(0, false, large ? 136 : 141, large ? 196 : 50);
itemStacks.set(0, recipe.getRecipeOutput().getStack());
int x = getGridX(recipe);
int y = getGridY(recipe);
int size = recipeIngredients.size();
for (int i = 0; i < size; i++) {
itemStacks.init(i + 1, true, x + (i % recipe.getWidth()) * 19, y + (i / recipe.getWidth()) * 19);
itemStacks.set(i + 1, Arrays.asList(recipeIngredients.get(i).getMatchingStacks()));
}
}
public int getGridY(ShapedRecipe recipe) {
return 3 + (int) (((large ? 9 : 4) - recipe.getRecipeHeight()) * 19 / 2f);
}
public int getGridX(ShapedRecipe recipe) {
return 3 + (int) (((large ? 9 : 4) - recipe.getRecipeWidth()) * 19 / 2f);
}
@Override
public void draw(ShapedRecipe recipe, double mouseX, double mouseY) {
int x = getGridX(recipe);
int y = getGridY(recipe);
for (int row = 0; row < recipe.getHeight(); row++)
for (int col = 0; col < recipe.getWidth(); col++)
if (!recipe.getIngredients().get(row * recipe.getWidth() + col).hasNoMatchingItems())
ScreenResources.JEI_SLOT.draw(x + col * 19, y + row * 19);
ScreenResources.JEI_SLOT.draw(large ? 136 : 141, large ? 196 : 50);
if (large)
ScreenResources.JEI_ARROW.draw(86, 200);
else
ScreenResources.JEI_DOWN_ARROW.draw(136, 32);
ScreenResources.JEI_SHADOW.draw(large ? 20 : 84, large ? 223 : 68);
crafter.draw(large ? 105 : 185, large ? 189 : -1);
}
@Override
public Class<? extends ShapedRecipe> getRecipeClass() {
return ShapedRecipe.class;
}
}

View File

@ -0,0 +1,77 @@
package com.simibubi.create.compat.jei.category.animations;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.gui.ScreenElementRenderer;
import com.simibubi.create.modules.contraptions.components.crafter.MechanicalCrafterBlock;
import net.minecraft.block.BlockState;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
public class AnimatedCrafter extends AnimatedKinetics {
boolean four;
public AnimatedCrafter(boolean four) {
this.four = four;
}
@Override
public int getWidth() {
return 50;
}
@Override
public int getHeight() {
return 50;
}
@Override
public void draw(int xOffset, int yOffset) {
GlStateManager.pushMatrix();
GlStateManager.enableDepthTest();
GlStateManager.rotatef(-15.5f, 1, 0, 0);
GlStateManager.rotatef(-22.5f, 0, 1, 0);
GlStateManager.translatef(xOffset, yOffset, 0);
GlStateManager.translatef(-45, -5, 0);
GlStateManager.scaled(.45f, .45f, .45f);
ScreenElementRenderer.renderBlock(() -> cogwheel(true));
ScreenElementRenderer.renderBlock(this::body);
GlStateManager.translatef(0, 50, 0);
ScreenElementRenderer.renderBlock(() -> cogwheel(false));
ScreenElementRenderer.renderBlock(this::body);
if (four) {
GlStateManager.translatef(50, -50, 0);
ScreenElementRenderer.renderBlock(() -> cogwheel(false));
ScreenElementRenderer.renderBlock(this::body);
GlStateManager.translatef(0, 50, 0);
ScreenElementRenderer.renderBlock(() -> cogwheel(true));
ScreenElementRenderer.renderBlock(this::body);
} else {
GlStateManager.translatef(0, 50, 0);
ScreenElementRenderer.renderBlock(() -> cogwheel(true));
ScreenElementRenderer.renderBlock(this::body);
}
GlStateManager.popMatrix();
}
private BlockState cogwheel(boolean forward) {
float t = 25;
GlStateManager.translatef(t, -t, -t);
GlStateManager.rotated(getCurrentAngle() * 2 * (forward ? 1 : -1), 0, 0, 1);
GlStateManager.translatef(-t, t, t);
return AllBlocks.SHAFTLESS_COGWHEEL.get().getDefaultState().with(BlockStateProperties.AXIS, Axis.X);
}
private BlockState body() {
return AllBlocks.MECHANICAL_CRAFTER.get().getDefaultState().with(MechanicalCrafterBlock.HORIZONTAL_FACING,
Direction.WEST);
}
}

View File

@ -253,6 +253,7 @@
"create.recipe.mixing": "Mixing",
"create.recipe.packing": "Compacting",
"create.recipe.sawing": "Sawing",
"create.recipe.mechanical_crafting": "Mechanical Crafting",
"create.recipe.block_cutting": "Block Cutting",
"create.recipe.blockzapperUpgrade": "Handheld Blockzapper",
"create.recipe.sandpaper_polishing": "Sandpaper Polishing",