Clean up in Carving API, add support for new API classes in Carving

This commit is contained in:
tterrag1098 committed 2015-01-15 06:06:07 -05:00
1 parent f0e11d8eee
commit a110c4e8ef
7 files changed
+53 -38

No files matched your search

@@ -1,18 +1,17 @@
package com.cricketcraft.chisel.api;
import com.cricketcraft.chisel.carving.CarvableHelper;
import com.cricketcraft.chisel.carving.CarvableVariation;
public interface ICarvable {
/**
* This grabs the variations possible
* Gets a {@link CarvableVariation} from this block, based on metadata.
* <p>
* Typically you can refer this method to {@link CarvableHelper#getVariation(int)} but this method is provided for more complex metadata handling.
*
* @param metadata
* This is the metadata that a block will use and the basis of
* chisel Traditionally you make an instance of CarvableHelper
* ex. CarvableHelper carverHelper = new CarvableHelper(); In
* this method you return carverHelper.getVariation(metadata) and
* that should be all you need if you register it correctly.
* The metadata of the block
*/
public CarvableVariation getVariation(int metadata);
}
@@ -1,5 +1,7 @@
package com.cricketcraft.chisel.api.carving;
import net.minecraft.item.ItemStack;
public class CarvingUtils {
/**
@@ -14,4 +16,15 @@ public class CarvingUtils {
public static int compare(ICarvingVariation v1, ICarvingVariation v2) {
return v1.getOrder() - v2.getOrder();
}
/**
* Gets an {@link ItemStack} representing the passed {@link ICarvingVariation}.
*
* @param variation
* An {@link ICarvingVariation}
* @return An {@link ItemStack}
*/
public static ItemStack getStack(ICarvingVariation variation) {
return new ItemStack(variation.getBlock(), 1, variation.getItemMeta());
}
}
@@ -1,7 +1,7 @@
package com.cricketcraft.chisel.api.carving;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
/**
* Represents a variation of a chiselable block.
@@ -11,18 +11,26 @@ import net.minecraft.item.ItemStack;
*/
public interface ICarvingVariation extends Comparable<ICarvingVariation> {
/**
* The base block of this variation.
*
* @return A {@link Block} that is the base of this variation
*/
Block getBlock();
/**
* The metadata of this variation
*
* @return An int representing the metadata of this variation's {@link Block} in the world.
*/
int getBlockMeta();
int getItemMeta();
/**
* Gets an {@link ItemStack} representing this variation.
* The item metadata of this variation
*
* @return An {@link ItemStack} to represent this variation
* @return An int representing the metadata of this variations's {@link Item}.
*/
ItemStack getStack();
int getItemMeta();
/**
* The "order" of this variation. Represents its position in the list of variations.
@@ -24,14 +24,6 @@ public class Carving {
private Carving() {
}
String key(Item item, int metadata) {
return Item.itemRegistry.getNameForObject(item) + "|" + metadata;
}
String key(Block block, int metadata) {
return Block.blockRegistry.getNameForObject(block) + "|" + metadata;
}
public List<ICarvingVariation> getVariations(Block block, int metadata) {
ICarvingGroup group = getGroup(block, metadata);
if (group == null)
@@ -105,20 +97,26 @@ public class Carving {
return groups.getGroupByName(name);
}
public CarvingVariation addVariation(String name, Block block, int metadata, int order) {
public void addVariation(String groupName, Block block, int metadata, int order) {
CarvingVariation variation = new CarvingVariation(block, metadata, order);
ICarvingVariation variation = new CarvingVariation(block, metadata, order);
addVariation(groupName, variation);
}
ICarvingGroup group = groups.getGroupByName(name);
public void addVariation(String groupName, ICarvingVariation variation) {
ICarvingGroup group = groups.getGroupByName(groupName);
if (group == null) {
group = new CarvingGroup(name);
groups.add(group);
group = new CarvingGroup(groupName);
addGroup(group);
}
groups.addVariation(name, variation);
groups.addVariation(groupName, variation);
}
return variation;
public void addGroup(ICarvingGroup group) {
groups.add(group);
}
public void registerOre(String name, String oreName) {
@@ -20,11 +20,6 @@ public class CarvingVariation implements ICarvingVariation {
this.damage = metadata;
}
@Override
public ItemStack getStack() {
return new ItemStack(block, 1, damage);
}
@Override
public Block getBlock() {
return block;
@@ -69,11 +69,6 @@ public class GroupList implements Set<ICarvingGroup> {
return data.getRight();
}
@Override
public ItemStack getStack() {
return null;
}
@Override
public int getOrder() {
return 0;
@@ -127,6 +122,12 @@ public class GroupList implements Set<ICarvingGroup> {
if (groups.containsKey(key)) {
return false;
}
for (ICarvingVariation v : group.getVariations()) {
ICarvingGroup g = lookup.get(v);
if (g == null) {
lookup.put(new VariationWrapper(v), group);
}
}
groups.put(key, group);
return true;
}
@@ -15,6 +15,7 @@ import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
import com.cricketcraft.chisel.api.carving.CarvingUtils;
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
import com.cricketcraft.chisel.carving.Carving;
@@ -165,7 +166,7 @@ public class RecipeHandlerChisel extends TemplateRecipeHandler {
private static List<ItemStack> getVariationStacks(ICarvingGroup g) {
List<ItemStack> stacks = new ArrayList<ItemStack>();
for (ICarvingVariation v : g.getVariations()) {
stacks.add(v.getStack());
stacks.add(CarvingUtils.getStack(v));
}
String oreName = g.getOreName();
if (oreName != null) {