solderer JEI integration
This commit is contained in:
		| @@ -15,7 +15,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; | ||||
| import storagecraft.item.ItemStorageCell; | ||||
| import storagecraft.proxy.CommonProxy; | ||||
|  | ||||
| @Mod(modid = StorageCraft.ID, version = StorageCraft.VERSION) | ||||
| @Mod(modid = StorageCraft.ID, version = StorageCraft.VERSION, dependencies = "required-after:JEI@[2.18,);") | ||||
| public final class StorageCraft | ||||
| { | ||||
| 	public static final String ID = "storagecraft"; | ||||
|   | ||||
| @@ -198,7 +198,7 @@ public abstract class GuiBase extends GuiContainer | ||||
|  | ||||
| 	public void drawTexture(int x, int y, int textureX, int textureY, int width, int height) | ||||
| 	{ | ||||
| 		this.drawTexturedModalRect(x, y, textureX, textureY, width, height); | ||||
| 		drawTexturedModalRect(x, y, textureX, textureY, width, height); | ||||
| 	} | ||||
|  | ||||
| 	public String t(String name, Object... format) | ||||
|   | ||||
							
								
								
									
										45
									
								
								src/main/java/storagecraft/jei/PluginStorageCraft.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/main/java/storagecraft/jei/PluginStorageCraft.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| package storagecraft.jei; | ||||
|  | ||||
| import mezz.jei.api.IGuiHelper; | ||||
| import mezz.jei.api.IItemRegistry; | ||||
| import mezz.jei.api.IJeiHelpers; | ||||
| import mezz.jei.api.IModPlugin; | ||||
| import mezz.jei.api.IModRegistry; | ||||
| import mezz.jei.api.IRecipeRegistry; | ||||
| import mezz.jei.api.JEIPlugin; | ||||
|  | ||||
| @JEIPlugin | ||||
| public class PluginStorageCraft implements IModPlugin | ||||
| { | ||||
| 	private IItemRegistry itemRegistry; | ||||
| 	private IJeiHelpers jeiHelpers; | ||||
|  | ||||
| 	@Override | ||||
| 	public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers) | ||||
| 	{ | ||||
| 		this.jeiHelpers = jeiHelpers; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onItemRegistryAvailable(IItemRegistry itemRegistry) | ||||
| 	{ | ||||
| 		this.itemRegistry = itemRegistry; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void register(IModRegistry registry) | ||||
| 	{ | ||||
| 		IGuiHelper guiHelper = jeiHelpers.getGuiHelper(); | ||||
|  | ||||
| 		registry.addRecipeCategories(new SoldererRecipeCategory(guiHelper)); | ||||
|  | ||||
| 		registry.addRecipeHandlers(new SoldererRecipeHandler()); | ||||
|  | ||||
| 		registry.addRecipes(SoldererRecipeMaker.getRecipes()); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onRecipeRegistryAvailable(IRecipeRegistry recipeRegistry) | ||||
| 	{ | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										78
									
								
								src/main/java/storagecraft/jei/SoldererRecipeCategory.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								src/main/java/storagecraft/jei/SoldererRecipeCategory.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,78 @@ | ||||
| package storagecraft.jei; | ||||
|  | ||||
| import mezz.jei.api.IGuiHelper; | ||||
| import mezz.jei.api.gui.IDrawable; | ||||
| import mezz.jei.api.gui.IGuiItemStackGroup; | ||||
| import mezz.jei.api.gui.IRecipeLayout; | ||||
| import mezz.jei.api.recipe.IRecipeCategory; | ||||
| import mezz.jei.api.recipe.IRecipeWrapper; | ||||
| import net.minecraft.client.Minecraft; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.util.ResourceLocation; | ||||
| import net.minecraft.util.StatCollector; | ||||
|  | ||||
| public class SoldererRecipeCategory implements IRecipeCategory | ||||
| { | ||||
| 	private IDrawable background; | ||||
|  | ||||
| 	public SoldererRecipeCategory(IGuiHelper helper) | ||||
| 	{ | ||||
| 		background = helper.createDrawable(new ResourceLocation("storagecraft", "textures/gui/solderer.png"), 0, 0, 176, 177); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public String getUid() | ||||
| 	{ | ||||
| 		return "storagecraft.solderer"; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public String getTitle() | ||||
| 	{ | ||||
| 		return StatCollector.translateToLocal("gui.storagecraft:solderer"); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public IDrawable getBackground() | ||||
| 	{ | ||||
| 		return background; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void drawExtras(Minecraft minecraft) | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void drawAnimations(Minecraft minecraft) | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void setRecipe(IRecipeLayout recipeLayout, IRecipeWrapper recipeWrapper) | ||||
| 	{ | ||||
| 		IGuiItemStackGroup group = recipeLayout.getItemStacks(); | ||||
|  | ||||
| 		int x = 44; | ||||
| 		int y = 20; | ||||
|  | ||||
| 		for (int i = 0; i < 3; ++i) | ||||
| 		{ | ||||
| 			group.init(i, true, x, y); | ||||
|  | ||||
| 			y += 18; | ||||
| 		} | ||||
|  | ||||
| 		group.init(3, false, 134, 38); | ||||
|  | ||||
| 		if (recipeWrapper instanceof SoldererRecipeWrapper) | ||||
| 		{ | ||||
| 			for (int i = 0; i < 3; ++i) | ||||
| 			{ | ||||
| 				group.set(i, (ItemStack) recipeWrapper.getInputs().get(i)); | ||||
| 			} | ||||
|  | ||||
| 			group.set(3, (ItemStack) recipeWrapper.getOutputs().get(0)); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										31
									
								
								src/main/java/storagecraft/jei/SoldererRecipeHandler.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/main/java/storagecraft/jei/SoldererRecipeHandler.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| package storagecraft.jei; | ||||
|  | ||||
| import mezz.jei.api.recipe.IRecipeHandler; | ||||
| import mezz.jei.api.recipe.IRecipeWrapper; | ||||
|  | ||||
| public class SoldererRecipeHandler implements IRecipeHandler<SoldererRecipeWrapper> | ||||
| { | ||||
| 	@Override | ||||
| 	public Class<SoldererRecipeWrapper> getRecipeClass() | ||||
| 	{ | ||||
| 		return SoldererRecipeWrapper.class; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public String getRecipeCategoryUid() | ||||
| 	{ | ||||
| 		return "storagecraft.solderer"; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public IRecipeWrapper getRecipeWrapper(SoldererRecipeWrapper recipe) | ||||
| 	{ | ||||
| 		return recipe; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean isRecipeValid(SoldererRecipeWrapper recipe) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										30
									
								
								src/main/java/storagecraft/jei/SoldererRecipeMaker.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/main/java/storagecraft/jei/SoldererRecipeMaker.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| package storagecraft.jei; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import storagecraft.tile.solderer.ISoldererRecipe; | ||||
| import storagecraft.tile.solderer.SoldererRegistry; | ||||
|  | ||||
| public class SoldererRecipeMaker | ||||
| { | ||||
| 	public static List<SoldererRecipeWrapper> getRecipes() | ||||
| 	{ | ||||
| 		List<SoldererRecipeWrapper> recipes = new ArrayList<SoldererRecipeWrapper>(); | ||||
|  | ||||
| 		for (ISoldererRecipe recipe : SoldererRegistry.recipes) | ||||
| 		{ | ||||
| 			List<ItemStack> inputs = new ArrayList<ItemStack>(); | ||||
|  | ||||
| 			inputs.add(recipe.getRow(0)); | ||||
| 			inputs.add(recipe.getRow(1)); | ||||
| 			inputs.add(recipe.getRow(2)); | ||||
|  | ||||
| 			ItemStack output = recipe.getResult(); | ||||
|  | ||||
| 			recipes.add(new SoldererRecipeWrapper(inputs, output)); | ||||
| 		} | ||||
|  | ||||
| 		return recipes; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										79
									
								
								src/main/java/storagecraft/jei/SoldererRecipeWrapper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								src/main/java/storagecraft/jei/SoldererRecipeWrapper.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| package storagecraft.jei; | ||||
|  | ||||
| import com.google.common.base.Objects; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| import mezz.jei.plugins.vanilla.VanillaRecipeWrapper; | ||||
| import net.minecraft.item.ItemStack; | ||||
|  | ||||
| public class SoldererRecipeWrapper extends VanillaRecipeWrapper | ||||
| { | ||||
| 	private int hashCode; | ||||
| 	private List<ItemStack> inputs; | ||||
| 	private ItemStack output; | ||||
|  | ||||
| 	public SoldererRecipeWrapper(List<ItemStack> inputs, ItemStack output) | ||||
| 	{ | ||||
| 		this.inputs = inputs; | ||||
| 		this.output = output; | ||||
|  | ||||
| 		int available = 0; | ||||
|  | ||||
| 		for (int i = 0; i < 3; ++i) | ||||
| 		{ | ||||
| 			if (inputs.get(i) != null) | ||||
| 			{ | ||||
| 				available = i; | ||||
|  | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		hashCode = Objects.hashCode(inputs.get(available), output); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public List<ItemStack> getInputs() | ||||
| 	{ | ||||
| 		return inputs; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public List<ItemStack> getOutputs() | ||||
| 	{ | ||||
| 		return Collections.singletonList(output); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean equals(Object obj) | ||||
| 	{ | ||||
| 		if (!(obj instanceof SoldererRecipeWrapper)) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		SoldererRecipeWrapper other = (SoldererRecipeWrapper) obj; | ||||
|  | ||||
| 		for (int i = 0; i < inputs.size(); i++) | ||||
| 		{ | ||||
| 			if (!ItemStack.areItemStacksEqual(inputs.get(i), other.inputs.get(i))) | ||||
| 			{ | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		return ItemStack.areItemStacksEqual(output, other.output); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public int hashCode() | ||||
| 	{ | ||||
| 		return hashCode; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public String toString() | ||||
| 	{ | ||||
| 		return inputs + " = " + output; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge