Skip to content

Commit

Permalink
Attempting to add a meta item
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantum64 committed Sep 16, 2016
1 parent f655fda commit a2262af
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/main/java/co/q64/exgregilo/ExGregilo.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void preInit(FMLPreInitializationEvent event) {
public void init(FMLInitializationEvent event) {
linkManager.registerLink(new ExNihilo());
linkManager.registerLink(new GregTech());
getLinkManager().loadLinks();
}

@EventHandler
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/q64/exgregilo/api/links/LinkBase.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.q64.exgregilo.api.links;

public interface LinkBase {
public void preLoadLink();
public void loadLink();

public void postLoadLink();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/co/q64/exgregilo/data/ModData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class ModData {
public static final String GREGTECH_ID = "gregtech";
public static final String EX_COMPRESSUM_ID = "excompressum";

public static final String ICON_TEX_PATH = MODID + ":icons/";
public static final String BLOCK_ICON_TEX_PATH = MODID + ":icons/";
public static final String GUI_TEX_PATH = MODID + ":textures/gui/";
public static final String ITEM_ICON_TEX_PATH = MODID + ":icons/";
}
19 changes: 11 additions & 8 deletions src/main/java/co/q64/exgregilo/links/LinkManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LinkManagerImpl implements LinkManager {
@Override
public void registerLink(LinkBase base) {
if (enabled) {
throw new IllegalStateException("Links must be registered before PostEnable");
throw new IllegalStateException("Links need to be registered in PreLoad");
}
ModLink link = getModLink(base.getClass());
if (link == null) {
Expand Down Expand Up @@ -51,6 +51,15 @@ public <T> T getLink(Class<T> linkClass) {
}

public void enableLinks() {
for (LinkBase link : enabledLinks) {
link.postLoadLink();
}
for (LinkBase link : enabledLinks) {
link.afterPostLoadLink();
}
}

public void loadLinks() {
if (enabled) {
throw new IllegalStateException("Links have already been enabled!");
}
Expand All @@ -61,13 +70,7 @@ public void enableLinks() {
}
pendingLinks.clear();
for (LinkBase link : enabledLinks) {
link.preLoadLink(); // TODO Move if this doesn't work
}
for (LinkBase link : enabledLinks) {
link.postLoadLink();
}
for (LinkBase link : enabledLinks) {
link.afterPostLoadLink();
link.loadLink(); // TODO Move if this doesn't work
}
enabled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void afterPostLoadLink() {
}

@Override
public void preLoadLink() {
public void loadLink() {

}

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/co/q64/exgregilo/links/gregtech/GregTech.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.util.GT_OreDictUnificator;

import java.util.ArrayList;
Expand All @@ -24,13 +25,19 @@
import co.q64.exgregilo.links.gregtech.crafting.RecipeMap;
import co.q64.exgregilo.links.gregtech.item.ItemList;
import co.q64.exgregilo.links.gregtech.tile.AutoSieve;
import co.q64.exgregilo.links.gregtech.tools.MetaGeneratedTools;
import co.q64.exgregilo.links.gregtech.tools.ToolCrafting;

@ModLink(modName = "GregTech", modId = ModData.GREGTECH_ID)
public class GregTech implements LinkBase {
private Map<Block, Map<ItemStack, Integer>> sifting = new HashMap<Block, Map<ItemStack, Integer>>();
private GT_MetaGenerated_Tool tools;

@Override
public void preLoadLink() {
public void loadLink() {
this.tools = new MetaGeneratedTools();
OrePrefixes.tool.add(new ToolCrafting()); // Why exactly is it done like this...?

if (ExGregiloAPI.getLinkManager().isEnabled(ExNihilo.class)) {
GT_OreDictUnificator.registerOre(OreDictAddons.SILK_MESH, new ItemStack(ExGregiloAPI.getLinkManager().getLink(ExNihilo.class).getSilkMesh(), 1));
} else {
Expand Down Expand Up @@ -168,4 +175,8 @@ private Block getDustBlock() {
public Map<Block, Map<ItemStack, Integer>> getSiftingMap() {
return sifting;
}

public GT_MetaGenerated_Tool getTools() {
return tools;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class OreDictAddons {
public static final String SILK_MESH = "craftingSilkMesh";
public static final String WIRE_MESH = "craftingToolWireMesh";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
import co.q64.exgregilo.data.ModData;

public class RecipeMap {
public static final GT_Recipe_Map AUTO_SIEVE_RECIPES = new GT_Recipe_Map(new HashSet<GT_Recipe>(100), "gt.recipe.autosieve", "Auto Sieve", null, ModData.GUI_TEX_PATH + "Autosieve", 1, 6, 1, 0, 1, GT_Values.E, 0, GT_Values.E, true, true);
public static final GT_Recipe_Map AUTO_SIEVE_RECIPES = new GT_Recipe_Map(new HashSet<GT_Recipe>(100), "gt.recipe.autosieve", "Auto Sieve", null, ModData.ITEM_ICON_TEX_PATH + "Autosieve", 1, 6, 1, 0, 1, GT_Values.E, 0, GT_Values.E, true, true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum BlockTextures implements IIconContainer, Runnable {
//formatter:off
BLANK("BLANK"),
OVERLAY_AUTO_SIEVE_TOP("OVERLAY_AUTO_SIEVE_TOP"),
OVERLAY_AUTO_SIEVE_FRONT("OVERLAY_AUTO_SIEVE_FRONT"),
OVERLAY_AUTO_SIEVE_BASIC_TOP("OVERLAY_AUTO_SIEVE_BASIC_TOP");
//formatter:on
;
Expand All @@ -25,7 +26,7 @@ private BlockTextures(String textureName) {

@Override
public void run() {
icon = GregTech_API.sBlockIcons.registerIcon(ModData.ICON_TEX_PATH + textureName);
icon = GregTech_API.sBlockIcons.registerIcon(ModData.BLOCK_ICON_TEX_PATH + textureName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package co.q64.exgregilo.links.gregtech.render;

import gregtech.api.GregTech_API;
import gregtech.api.interfaces.IIconContainer;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import co.q64.exgregilo.data.ModData;

public enum ItemTextures implements IIconContainer, Runnable {
WIRE_MESH("WIRE_MESH");

private static final String BLANK_OVERLAY = "BLANK";
private String textureName;
private String overlayName;
private IIcon mIcon;
private IIcon mOverlay;

private ItemTextures(String textureName) {
this(textureName, BLANK_OVERLAY);
}

private ItemTextures(String textureName, String overlayName) {
this.textureName = textureName;
this.overlayName = overlayName;
GregTech_API.sGTItemIconload.add(this);
}

@Override
public IIcon getIcon() {
return mIcon;
}

@Override
public IIcon getOverlayIcon() {
return mOverlay;
}

@Override
public ResourceLocation getTextureFile() {
return TextureMap.locationItemsTexture;
}

@Override
public void run() {
mIcon = GregTech_API.sItemIcons.registerIcon(ModData.ITEM_ICON_TEX_PATH + textureName);
mOverlay = GregTech_API.sItemIcons.registerIcon(ModData.ITEM_ICON_TEX_PATH + overlayName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public AutoSieve(int aID, String aName, String aNameRegional, int aTier) {
//formatter:off
new GT_RenderedTexture(BlockTextures.BLANK),
new GT_RenderedTexture(BlockTextures.BLANK),
new GT_RenderedTexture(BlockTextures.BLANK),
new GT_RenderedTexture(BlockTextures.BLANK),
new GT_RenderedTexture(BlockTextures.OVERLAY_AUTO_SIEVE_FRONT),
new GT_RenderedTexture(BlockTextures.OVERLAY_AUTO_SIEVE_FRONT),
aTier == 1 ? new GT_RenderedTexture(BlockTextures.OVERLAY_AUTO_SIEVE_BASIC_TOP) : new GT_RenderedTexture(BlockTextures.OVERLAY_AUTO_SIEVE_TOP),
aTier == 1 ? new GT_RenderedTexture(BlockTextures.OVERLAY_AUTO_SIEVE_BASIC_TOP) : new GT_RenderedTexture(BlockTextures.OVERLAY_AUTO_SIEVE_TOP),
new GT_RenderedTexture(BlockTextures.BLANK),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package co.q64.exgregilo.links.gregtech.tools;

import gregtech.api.items.GT_MetaGenerated_Tool;
import co.q64.exgregilo.links.gregtech.crafting.OreDictAddons;

public class MetaGeneratedTools extends GT_MetaGenerated_Tool {
public static final int WIRE_MESH_ID = 0;

public MetaGeneratedTools() {
super("exgregilo.metatool.01");
addTool(WIRE_MESH_ID, "Wire Mesh", "Place in an Advanced Sieve", new WireMesh(), new Object[] { OreDictAddons.WIRE_MESH });
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package co.q64.exgregilo.links.gregtech.tools;

import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.SubTag;
import gregtech.api.interfaces.IOreRecipeRegistrator;
import gregtech.api.util.GT_ModHandler;
import net.minecraft.item.ItemStack;
import co.q64.exgregilo.api.ExGregiloAPI;
import co.q64.exgregilo.links.gregtech.GregTech;

public class ToolCrafting implements IOreRecipeRegistrator {

@Override
public void registerOre(OrePrefixes prefix, Materials material, String oreDictName, String modName, ItemStack stack) {
if ((!material.contains(SubTag.WOOD)) && (!material.contains(SubTag.BOUNCY)) && (!material.contains(SubTag.NO_SMASHING))) {
//formatter:off
GT_ModHandler.addCraftingRecipe(ExGregiloAPI.getLinkManager().getLink(GregTech.class).getTools().getToolWithStats(MetaGeneratedTools.WIRE_MESH_ID, 1, material, material.mHandleMaterial, null), GT_ModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS | GT_ModHandler.RecipeBits.BUFFERED, new Object[]{
"WWW",
"WGW",
"WWW",
Character.valueOf('W'), OrePrefixes.wireGt01.get(material),
Character.valueOf('G'), OrePrefixes.gearGtSmall.get(material.mHandleMaterial)});
//formatter:on
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/co/q64/exgregilo/links/gregtech/tools/WireMesh.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package co.q64.exgregilo.links.gregtech.tools;

import co.q64.exgregilo.links.gregtech.render.ItemTextures;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.common.tools.GT_Tool;

public class WireMesh extends GT_Tool {

@Override
public float getBaseDamage() {
return 1.0f;
}

@Override
public boolean isMinableBlock(Block block, byte metaData) {
return false;
}

@Override
public IIconContainer getIcon(boolean isToolHead, ItemStack stack) {
return ItemTextures.WIRE_MESH;
}

@Override
public float getMaxDurabilityMultiplier() {
return 0.1F;
}

@Override
public short[] getRGBa(boolean isToolHead, ItemStack stack) {
return isToolHead ? GT_MetaGenerated_Tool.getPrimaryMaterial(stack).mRGBa : null;
}
}

0 comments on commit a2262af

Please sign in to comment.