mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 16:27:45 +00:00
Add variation removal support to API, add ICarvingRegistry
This commit is contained in:
1 parent
fd7fabf397
commit
974ceec043
10 files changed
+85
-12
No files matched your search
@@ -2,6 +2,6 @@ package com.cricketcraft.chisel.api;
|
||||
|
||||
public class ChiselAPIProps {
|
||||
|
||||
public static final String VERSION = "0.0.1";
|
||||
public static final String VERSION = "0.0.2";
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class CarvingUtils {
|
||||
@@ -27,4 +29,30 @@ public class CarvingUtils {
|
||||
public static ItemStack getStack(ICarvingVariation variation) {
|
||||
return new ItemStack(variation.getBlock(), 1, variation.getItemMeta());
|
||||
}
|
||||
|
||||
private static Field _chisel;
|
||||
private static boolean errored = false;
|
||||
private static final String CARVING_CLASS = "com.cricketcraft.chisel.carving.Carving";
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
public static ICarvingRegistry getChiselRegistry() {
|
||||
if (errored) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (_chisel == null) {
|
||||
_chisel = Class.forName(CARVING_CLASS).getDeclaredField("chisel");
|
||||
}
|
||||
return (ICarvingRegistry) _chisel.get(null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
errored = true;
|
||||
return getChiselRegistry();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
/**
|
||||
* Represents a group of chiselable blocks.
|
||||
* <p>
|
||||
@@ -63,4 +65,15 @@ public interface ICarvingGroup {
|
||||
* An {@link ICarvingVariation} to add to this group
|
||||
*/
|
||||
void addVariation(ICarvingVariation variation);
|
||||
|
||||
/**
|
||||
* Removes a varaition with the passed {@link Block} and metadata from this group.
|
||||
*
|
||||
* @param block
|
||||
* The {@link Block} of the {@link ICarvingVariation variation}
|
||||
* @param metadata
|
||||
* The metadata of the {@link ICarvingVariation variation}
|
||||
* @return The ICarvingVariation that was removed. Null if nothing was removed.
|
||||
*/
|
||||
ICarvingVariation removeVariation(Block block, int metadata);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.cricketcraft.chisel.block.tileentity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -178,7 +178,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
|
||||
// lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target
|
||||
private boolean canBeMadeFrom(ItemStack from, ItemStack to) {
|
||||
ArrayList<ItemStack> results = Carving.chisel.getItems(from);
|
||||
List<ItemStack> results = Carving.chisel.getItemsForChiseling(from);
|
||||
for (ItemStack s : results) {
|
||||
if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) {
|
||||
return true;
|
||||
@@ -329,7 +329,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
switch (slot) {
|
||||
case BASE:
|
||||
case TARGET:
|
||||
return !Carving.chisel.getItems(itemStack).isEmpty();
|
||||
return !Carving.chisel.getItemsForChiseling(itemStack).isEmpty();
|
||||
case OUTPUT:
|
||||
return false;
|
||||
case CHISEL:
|
||||
|
||||
@@ -12,9 +12,10 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingRegistry;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
|
||||
public class Carving {
|
||||
public class Carving implements ICarvingRegistry {
|
||||
|
||||
GroupList groups = new GroupList();
|
||||
|
||||
@@ -24,6 +25,7 @@ public class Carving {
|
||||
private Carving() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICarvingVariation getVariation(Block block, int metadata) {
|
||||
ICarvingGroup g = getGroup(block, metadata);
|
||||
if (g != null) {
|
||||
@@ -36,7 +38,8 @@ public class Carving {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ICarvingVariation> getVariations(Block block, int metadata) {
|
||||
@Override
|
||||
public List<ICarvingVariation> getGroupVariations(Block block, int metadata) {
|
||||
ICarvingGroup group = getGroup(block, metadata);
|
||||
if (group == null)
|
||||
return null;
|
||||
@@ -44,7 +47,8 @@ public class Carving {
|
||||
return group.getVariations();
|
||||
}
|
||||
|
||||
public String getOre(Block block, int metadata) {
|
||||
@Override
|
||||
public String getOreName(Block block, int metadata) {
|
||||
ICarvingGroup group = getGroup(block, metadata);
|
||||
if (group == null)
|
||||
return null;
|
||||
@@ -52,7 +56,8 @@ public class Carving {
|
||||
return group.getOreName();
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> getItems(ItemStack chiseledItem) {
|
||||
@Override
|
||||
public List<ItemStack> getItemsForChiseling(ItemStack chiseledItem) {
|
||||
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
||||
int damage = chiseledItem.getItemDamage();
|
||||
@@ -94,6 +99,7 @@ public class Carving {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICarvingGroup getGroup(Block block, int metadata) {
|
||||
int[] ids = OreDictionary.getOreIDs(new ItemStack(block, metadata));
|
||||
if (ids.length > 0) {
|
||||
@@ -108,10 +114,12 @@ public class Carving {
|
||||
return groups.getGroup(block, metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICarvingGroup getGroup(String name) {
|
||||
return groups.getGroupByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariation(String groupName, Block block, int metadata, int order) {
|
||||
if (block == null) {
|
||||
throw new NullPointerException("Cannot add variation in group " + groupName + " for null block.");
|
||||
@@ -121,6 +129,7 @@ public class Carving {
|
||||
addVariation(groupName, variation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariation(String groupName, ICarvingVariation variation) {
|
||||
if (groupName == null) {
|
||||
throw new NullPointerException("Cannot add variation to null group name.");
|
||||
@@ -138,10 +147,12 @@ public class Carving {
|
||||
groups.addVariation(groupName, variation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(ICarvingGroup group) {
|
||||
groups.add(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOre(String name, String oreName) {
|
||||
ICarvingGroup group = groups.getGroupByName(name);
|
||||
if (group != null) {
|
||||
@@ -151,6 +162,7 @@ public class Carving {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVariationSound(String name, String sound) {
|
||||
ICarvingGroup group = groups.getGroupByName(name);
|
||||
if (group != null) {
|
||||
@@ -160,16 +172,19 @@ public class Carving {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVariationSound(Block block, int metadata) {
|
||||
return getVariationSound(Item.getItemFromBlock(block), metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVariationSound(Item item, int metadata) {
|
||||
ICarvingGroup group = groups.getGroup(Block.getBlockFromItem(item), metadata);
|
||||
String sound = group == null ? null : group.getSound();
|
||||
return sound == null ? Chisel.MOD_ID + ":chisel.fallback" : sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSortedGroupNames() {
|
||||
List<String> names = new ArrayList<String>();
|
||||
names.addAll(groups.getNames());
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.CarvingUtils;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
@@ -36,6 +38,17 @@ public class CarvingGroup implements ICarvingGroup {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICarvingVariation removeVariation(Block block, int metadata) {
|
||||
ICarvingVariation toRemove = null;
|
||||
for (ICarvingVariation v : variations) {
|
||||
if (v.getBlock() == block && v.getBlockMeta() == metadata) {
|
||||
toRemove = v;
|
||||
}
|
||||
}
|
||||
return toRemove == null ? null : variations.remove(toRemove) ? toRemove : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
@@ -130,6 +130,8 @@ public class GroupList implements Set<ICarvingGroup> {
|
||||
public boolean remove(Object o) {
|
||||
if (o instanceof ICarvingGroup) {
|
||||
return groups.remove(((ICarvingGroup) o).getName()) != null;
|
||||
} else if (o instanceof ICarvingVariation) {
|
||||
// TODO support carving variation removal
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingRegistry;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.item.chisel.ItemChisel;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
@@ -18,7 +19,7 @@ public class ContainerChisel extends Container {
|
||||
int currentIndex;
|
||||
public ItemStack chisel;
|
||||
public boolean finished;
|
||||
public Carving carving;
|
||||
public ICarvingRegistry carving;
|
||||
|
||||
public ContainerChisel(InventoryPlayer inventoryplayer, InventoryChiselSelection inv) {
|
||||
inventory = inv;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.cricketcraft.chisel.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -124,7 +124,7 @@ public class InventoryChiselSelection implements IInventory {
|
||||
if (!((IChiselItem) chisel.getItem()).canChisel(container.playerInventory.player.worldObj, chisel, General.getVariation(chiseledItem)))
|
||||
return;
|
||||
|
||||
ArrayList<ItemStack> list = container.carving.getItems(chiseledItem);
|
||||
List<ItemStack> list = container.carving.getItemsForChiseling(chiseledItem);
|
||||
|
||||
activeVariations = 0;
|
||||
while (activeVariations < normalSlots && activeVariations < list.size()) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingRegistry;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.config.Configurations;
|
||||
@@ -36,7 +37,7 @@ public class ItemChisel extends Item implements IChiselItem {
|
||||
}
|
||||
}
|
||||
|
||||
public static Carving carving = Carving.chisel;
|
||||
public static ICarvingRegistry carving = Carving.chisel;
|
||||
|
||||
private ChiselType type;
|
||||
|
||||
|
||||
Reference in new issue
Block a user