mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-19 03:59:15 +00:00
Move CarvableHelper to API
This commit is contained in:
1 parent
3013e263a2
commit
47abdbbc10
33 files changed
+216
-220
No files matched your search
@@ -3,5 +3,5 @@ package com.cricketcraft.chisel.api;
|
||||
public class ChiselAPIProps {
|
||||
|
||||
public static final String VERSION = "0.0.2";
|
||||
|
||||
public static String MOD_ID = null; // Set by Chisel
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.cricketcraft.chisel.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||
|
||||
public class FMPIMC {
|
||||
|
||||
public static void registerFMP(Block block) {
|
||||
registerFMP(block, 0, 15);
|
||||
}
|
||||
|
||||
public static void registerFMP(Block block, int minMeta, int maxMeta) {
|
||||
for (int c = minMeta; c <= maxMeta; c++) {
|
||||
registerFMP(block, c);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerFMP(Block block, int meta) {
|
||||
FMLInterModComms.sendMessage("ForgeMicroblock", "microMaterial", new ItemStack(block, 1, meta));
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@ package com.cricketcraft.chisel.api;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.chisel.carving.CarvableHelper;
|
||||
|
||||
/**
|
||||
* To be implemented on blocks that can be chiseled and need advanced metadata to variation mapping. Currently not very usable without internal classes.
|
||||
|
||||
@@ -55,5 +55,10 @@ public enum IMC {
|
||||
/**
|
||||
* The modid of Chisel so you can easily send IMC to this mod.
|
||||
*/
|
||||
public static final String CHISEL_MODID = Chisel.MOD_ID;
|
||||
@Deprecated
|
||||
public static final String CHISEL_MODID = "chisel";
|
||||
|
||||
public static final String getModid() {
|
||||
return ChiselAPIProps.MOD_ID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.cricketcraft.chisel.api.ChiselAPIProps;
|
||||
import com.cricketcraft.chisel.api.FMPIMC;
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class CarvableHelper {
|
||||
|
||||
public static Class<? extends ItemBlock> itemCarvableClass = null;
|
||||
public static IIcon missingIcon = null;
|
||||
|
||||
private Block theBlock;
|
||||
|
||||
public ArrayList<IVariationInfo> infoList = new ArrayList<IVariationInfo>();
|
||||
IVariationInfo[] infoMap = new IVariationInfo[16];
|
||||
public boolean forbidChiseling = false;
|
||||
|
||||
public CarvableHelper(Block block) {
|
||||
this.theBlock = block;
|
||||
}
|
||||
public void addVariation(String description, int metadata, ISubmapManager<? extends RenderBlocks> manager) {
|
||||
addVariation(description , metadata, null, manager);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, Block bb) {
|
||||
addVariation(description, metadata, null, bb, 0, ChiselAPIProps.MOD_ID);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, Block bb, int blockMeta) {
|
||||
addVariation(description, metadata, null, bb, blockMeta, ChiselAPIProps.MOD_ID);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, Block bb, int blockMeta, Material material) {
|
||||
addVariation(description, metadata, null, bb, blockMeta, ChiselAPIProps.MOD_ID);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, String texture) {
|
||||
addVariation(description, metadata, texture, (ISubmapManager<? extends RenderBlocks>) null);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, String texture, ISubmapManager<? extends RenderBlocks> manager) {
|
||||
addVariation(description, metadata, texture, null, 0, ChiselAPIProps.MOD_ID, manager);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, Block bb, String modid) {
|
||||
addVariation(description, metadata, null, bb, 0, modid);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, Block bb, int blockMeta, String modid) {
|
||||
addVariation(description, metadata, null, bb, blockMeta, modid);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, Block bb, int blockMeta, Material material, String modid) {
|
||||
addVariation(description, metadata, null, bb, blockMeta, modid);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, String texture, String modid) {
|
||||
addVariation(description, metadata, texture, null, 0, modid);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, String texture, Block block, int blockMeta, String modid) {
|
||||
addVariation(description, metadata, texture, block, blockMeta, modid, null);
|
||||
}
|
||||
|
||||
public void addVariation(String description, int metadata, String texture, Block block, int blockMeta, String modid, ISubmapManager<? extends RenderBlocks> customManager) {
|
||||
|
||||
if (infoList.size() >= 16)
|
||||
return;
|
||||
|
||||
ICarvingVariation var = CarvingUtils.getDefaultVariationFor(theBlock, metadata, metadata);
|
||||
TextureType type = TextureType.getTypeFor(this, modid, texture);
|
||||
if (type == TextureType.CUSTOM && customManager == null) {
|
||||
throw new IllegalArgumentException(String.format("Could not find texture %s, and no custom texture manager was provided.", texture));
|
||||
}
|
||||
|
||||
IVariationInfo info;
|
||||
if (customManager != null) {
|
||||
info = new VariationInfoBase(var, description, customManager);
|
||||
} else {
|
||||
info = new VariationInfoBase(var, description, type.createManagerFor(var, texture));
|
||||
}
|
||||
|
||||
// TODO handling for block texture override params
|
||||
|
||||
infoList.add(info);
|
||||
infoMap[metadata] = info;
|
||||
}
|
||||
|
||||
|
||||
public IVariationInfo getVariation(int metadata) {
|
||||
if (metadata < 0 || metadata > 15)
|
||||
metadata = 0;
|
||||
|
||||
IVariationInfo info = infoMap[metadata];
|
||||
if (info == null)
|
||||
return null;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public IIcon getIcon(int side, int metadata) {
|
||||
if (metadata < 0 || metadata > 15)
|
||||
metadata = 0;
|
||||
|
||||
IVariationInfo info = infoMap[metadata];
|
||||
if (info == null)
|
||||
return getMissingIcon();
|
||||
|
||||
return info.getSubmapManager().getIcon(side, metadata);
|
||||
}
|
||||
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
int metadata = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if (metadata < 0 || metadata > 15)
|
||||
metadata = 0;
|
||||
|
||||
IVariationInfo info = infoMap[metadata];
|
||||
if (info == null)
|
||||
return getMissingIcon();
|
||||
|
||||
return info.getSubmapManager().getIcon(world, x, y, z, side);
|
||||
}
|
||||
|
||||
public void registerAll(Block block, String name) {
|
||||
registerAll(block, name, itemCarvableClass);
|
||||
}
|
||||
|
||||
public void registerBlock(Block block, String name) {
|
||||
registerBlock(block, name, itemCarvableClass);
|
||||
}
|
||||
|
||||
void registerBlock(Block block, String name, Class<? extends ItemBlock> cl) {
|
||||
block.setBlockName("chisel." + name);
|
||||
GameRegistry.registerBlock(block, cl, name);
|
||||
}
|
||||
|
||||
public void registerAll(Block block, String name, Class<? extends ItemBlock> cl) {
|
||||
registerBlock(block, name, cl);
|
||||
registerVariations(name, block);
|
||||
}
|
||||
|
||||
public void registerVariations(String name, Block block) {
|
||||
for (IVariationInfo info : infoList) {
|
||||
registerVariation(name, info);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerVariation(String name, IVariationInfo info) {
|
||||
|
||||
Block block = info.getVariation().getBlock();
|
||||
|
||||
if (block.renderAsNormalBlock() || block.isOpaqueCube() || block.isNormalCube()) {
|
||||
FMPIMC.registerFMP(block, info.getVariation().getBlockMeta());
|
||||
}
|
||||
|
||||
if (forbidChiseling)
|
||||
return;
|
||||
|
||||
CarvingUtils.getChiselRegistry().addVariation(name, info.getVariation());
|
||||
}
|
||||
|
||||
public void registerBlockIcons(String modName, Block block, IIconRegister register) {
|
||||
for (IVariationInfo info : infoList) {
|
||||
info.getSubmapManager().registerIcons(modName, block, register);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerSubBlocks(Block block, CreativeTabs tabs, List<ItemStack> list) {
|
||||
for (IVariationInfo info : infoList) {
|
||||
list.add(new ItemStack(block, 1, info.getVariation().getItemMeta()));
|
||||
}
|
||||
}
|
||||
|
||||
public void registerOre(String ore) {
|
||||
OreDictionary.registerOre(ore, infoList.get(0).getVariation().getBlock());
|
||||
}
|
||||
|
||||
public IIcon getMissingIcon() {
|
||||
return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class CarvingUtils {
|
||||
|
||||
/**
|
||||
@@ -30,56 +35,141 @@ public class CarvingUtils {
|
||||
return new ItemStack(variation.getBlock(), 1, variation.getItemMeta());
|
||||
}
|
||||
|
||||
private static Field _chisel;
|
||||
private static boolean registryErrored = false;
|
||||
private static final String CARVING_CLASS = "com.cricketcraft.chisel.carving.Carving";
|
||||
|
||||
private static Class<ICarvableHelper> _carvableHelper;
|
||||
private static boolean helperErrored = false;
|
||||
private static final String CARVABLE_HELPER_CLASS = "com.cricketcraft.carving.CarvableHelper";
|
||||
public static ICarvingRegistry chisel;
|
||||
|
||||
/**
|
||||
* @return The instance of the chisel carving registry from the chisel mod.
|
||||
* <p>
|
||||
* If chisel is not installed or some other error occurs this will return null.
|
||||
* If chisel is not installed this will return null.
|
||||
*/
|
||||
public static ICarvingRegistry getChiselRegistry() {
|
||||
if (registryErrored) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (_chisel == null) {
|
||||
_chisel = Class.forName(CARVING_CLASS).getDeclaredField("chisel");
|
||||
}
|
||||
return (ICarvingRegistry) _chisel.get(null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
registryErrored = true;
|
||||
return getChiselRegistry();
|
||||
}
|
||||
return chisel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An instance of an {@link ICarvableHelper}.
|
||||
* <p>
|
||||
* If chisel is not installed or some other error occurs this will return null.
|
||||
* Creates a standard {@link ICarvingVariation} for the given data. Use this if you do not need any custom behavior in your own variation.
|
||||
*
|
||||
* @param block
|
||||
* The block of the variation
|
||||
* @param metadata
|
||||
* The metadata of both the block and item
|
||||
* @param order
|
||||
* The sorting order.
|
||||
* @return A standard {@link ICarvingVariation} instance.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ICarvableHelper getCarvableHelperInstance() {
|
||||
if (helperErrored) {
|
||||
return null;
|
||||
public static ICarvingVariation getDefaultVariationFor(Block block, int metadata, int order) {
|
||||
return new SimpleCarvingVariation(block, metadata, order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a standard {@link ICarvingGroup} for the given name. Use this if you do not need any custom behavior in your own group.
|
||||
*
|
||||
* @param name
|
||||
* The name of the group.
|
||||
* @return A standard {@link ICarvingGroup} instance.
|
||||
*/
|
||||
public static ICarvingGroup getDefaultGroupFor(String name) {
|
||||
return new SimpleCarvingGroup(name);
|
||||
}
|
||||
|
||||
public static class SimpleCarvingVariation implements ICarvingVariation {
|
||||
|
||||
private int order;
|
||||
private Block block;
|
||||
private int meta;
|
||||
private int damage;
|
||||
|
||||
public SimpleCarvingVariation(Block block, int metadata, int order) {
|
||||
this.order = order;
|
||||
this.block = block;
|
||||
this.meta = metadata;
|
||||
this.damage = metadata;
|
||||
}
|
||||
|
||||
try {
|
||||
if (_carvableHelper == null) {
|
||||
_carvableHelper = (Class<ICarvableHelper>) Class.forName(CARVABLE_HELPER_CLASS);
|
||||
}
|
||||
return _carvableHelper.newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
helperErrored = true;
|
||||
return getCarvableHelperInstance();
|
||||
@Override
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemMeta() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleCarvingGroup implements ICarvingGroup {
|
||||
|
||||
private String name;
|
||||
private String sound;
|
||||
private String oreName;
|
||||
|
||||
private List<ICarvingVariation> variations = Lists.newArrayList();
|
||||
|
||||
public SimpleCarvingGroup(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<ICarvingVariation> getVariations() {
|
||||
return Lists.newArrayList(variations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariation(ICarvingVariation variation) {
|
||||
variations.add(variation);
|
||||
Collections.sort(variations, new Comparator<ICarvingVariation>() {
|
||||
|
||||
@Override
|
||||
public int compare(ICarvingVariation o1, ICarvingVariation o2) {
|
||||
return CarvingUtils.compare(o1, o2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeVariation(ICarvingVariation variation) {
|
||||
ICarvingVariation toRemove = null;
|
||||
for (ICarvingVariation v : variations) {
|
||||
if (v.getBlock() == variation.getBlock() && v.getBlockMeta() == variation.getBlockMeta()) {
|
||||
toRemove = v;
|
||||
}
|
||||
}
|
||||
return toRemove == null ? false : variations.remove(toRemove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSound(String sound) {
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOreName() {
|
||||
return oreName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOreName(String oreName) {
|
||||
this.oreName = oreName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class VariationInfoBase implements IVariationInfo {
|
||||
|
||||
private ICarvingVariation variation;
|
||||
private String unlocDesc;
|
||||
private ISubmapManager manager;
|
||||
private ISubmapManager<? extends RenderBlocks> manager;
|
||||
private TextureType type;
|
||||
|
||||
public VariationInfoBase(ICarvingVariation variation, String unlocDesc, ISubmapManager manager) {
|
||||
|
||||
public VariationInfoBase(ICarvingVariation variation, String unlocDesc, ISubmapManager<? extends RenderBlocks> manager) {
|
||||
this(variation, unlocDesc, manager, TextureType.CUSTOM);
|
||||
}
|
||||
|
||||
public VariationInfoBase(ICarvingVariation variation, String unlocDesc, ISubmapManager manager, TextureType type) {
|
||||
|
||||
public VariationInfoBase(ICarvingVariation variation, String unlocDesc, ISubmapManager<? extends RenderBlocks> manager, TextureType type) {
|
||||
this.variation = variation;
|
||||
this.unlocDesc = unlocDesc;
|
||||
this.manager = manager;
|
||||
@@ -34,7 +35,7 @@ public class VariationInfoBase implements IVariationInfo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISubmapManager getSubmapManager() {
|
||||
public ISubmapManager<? extends RenderBlocks> getSubmapManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.client.render.RenderBlocksCTM;
|
||||
import com.cricketcraft.chisel.client.render.RenderBlocksColumn;
|
||||
|
||||
|
||||
Reference in new issue
Block a user