mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 16:27:45 +00:00
Rewrite how Carving stores variants and groups
This commit is contained in:
1 parent
155bc00f0e
commit
447e472c04
10 files changed
+327
-119
No files matched your search
@@ -43,8 +43,8 @@ import com.cricketcraft.chisel.block.BlockLavastone;
|
||||
import com.cricketcraft.chisel.block.BlockLeaf;
|
||||
import com.cricketcraft.chisel.block.BlockMarbleBookshelf;
|
||||
import com.cricketcraft.chisel.block.BlockMarbleCarpet;
|
||||
import com.cricketcraft.chisel.block.BlockMarbleStairsMaker;
|
||||
import com.cricketcraft.chisel.block.BlockMarbleStairsMakerCreator;
|
||||
import com.cricketcraft.chisel.block.CarvableStairsMaker;
|
||||
import com.cricketcraft.chisel.block.IStairsCreator;
|
||||
import com.cricketcraft.chisel.block.BlockMarbleTexturedOre;
|
||||
import com.cricketcraft.chisel.block.BlockPresent;
|
||||
import com.cricketcraft.chisel.block.BlockRoadLine;
|
||||
@@ -134,14 +134,11 @@ public enum Features {
|
||||
antiBlock.carverHelper.setChiselBlockName("Anti Block");
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
final String blockName = "antiBlock" + ItemDye.field_150921_b[i];
|
||||
String oreName = "antiBlock" + ItemDye.field_150921_b[i];
|
||||
|
||||
antiBlock.carverHelper.addVariation("tile.antiBlock." + ItemDye.field_150921_b[i] + ".desc", i, "antiblock/" + ItemDye.field_150921_b[i] + "-antiBlock");
|
||||
Carving.chisel.registerOre(blockName, oreName);
|
||||
}
|
||||
|
||||
antiBlock.carverHelper.register(antiBlock, "antiBlock");
|
||||
Carving.chisel.registerOre("antiBlock", "antiBlock");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -317,8 +314,7 @@ public enum Features {
|
||||
carpet_block.carverHelper.addVariation("tile.carpet_block.15.desc", 15, "carpet/black");
|
||||
carpet_block.carverHelper.forbidChiseling = true;
|
||||
carpet_block.carverHelper.register(carpet_block, "carpet_block");
|
||||
OreDictionary.registerOre("carpet", carpet_block);
|
||||
Carving.chisel.registerOre("carpet_block", "carpet");
|
||||
OreDictionary.registerOre("blockCarpet", carpet_block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -361,12 +357,13 @@ public enum Features {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
String group = "carpet." + i;
|
||||
|
||||
Carving.needle.addVariation(group, Blocks.carpet, i, 0);
|
||||
Carving.needle.addVariation(group, carpet, i, 2);
|
||||
Carving.needle.addVariation(group, carpet_block, i, 1);
|
||||
// TODO needle stuff
|
||||
// Carving.needle.addVariation(group, Blocks.carpet, i, 0);
|
||||
// Carving.needle.addVariation(group, carpet, i, 2);
|
||||
// Carving.needle.addVariation(group, carpet_block, i, 1);
|
||||
}
|
||||
|
||||
Carving.chisel.registerOre("carpet", "carpet");
|
||||
OreDictionary.registerOre("carpet", carpet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1057,7 +1054,7 @@ public enum Features {
|
||||
|
||||
@Override
|
||||
void addBlocks() {
|
||||
BlockMarbleStairsMaker makerIceStairs = new BlockMarbleStairsMaker(Blocks.ice);
|
||||
CarvableStairsMaker makerIceStairs = new CarvableStairsMaker(Blocks.ice);
|
||||
makerIceStairs.carverHelper.setChiselBlockName("Ice Stairs");
|
||||
makerIceStairs.carverHelper.addVariation("tile.iceStairs.0.desc", 0, Blocks.ice);
|
||||
makerIceStairs.carverHelper.addVariation("tile.iceStairs.1.desc", 1, "ice/a1-ice-light");
|
||||
@@ -1075,14 +1072,14 @@ public enum Features {
|
||||
makerIceStairs.carverHelper.addVariation("tile.iceStairs.13.desc", 13, "ice/zelda");
|
||||
makerIceStairs.carverHelper.addVariation("tile.iceStairs.14.desc", 14, "ice/bismuth");
|
||||
makerIceStairs.carverHelper.addVariation("tile.iceStairs.15.desc", 15, "ice/poison");
|
||||
makerIceStairs.create(new BlockMarbleStairsMakerCreator() {
|
||||
makerIceStairs.create(new IStairsCreator() {
|
||||
|
||||
@Override
|
||||
public BlockCarvableStairs create(Block block, int meta, CarvableHelper helper) {
|
||||
return new BlockCarvableIceStairs(block, meta, helper);
|
||||
}
|
||||
}, "ice_stairs", ChiselBlocks.iceStairs);
|
||||
Carving.chisel.registerOre("iceStairs", "iceStairs");
|
||||
Carving.chisel.registerOre("ice_stairs", "iceStairs");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1310,7 +1307,7 @@ public enum Features {
|
||||
registerSlabTop(limestone_slab, limestone_slab.top);
|
||||
Carving.chisel.registerOre("limestone_slab", "limestone_slab");
|
||||
|
||||
BlockMarbleStairsMaker makerLimestoneStairs = new BlockMarbleStairsMaker(limestone);
|
||||
CarvableStairsMaker makerLimestoneStairs = new CarvableStairsMaker(limestone);
|
||||
makerLimestoneStairs.carverHelper.setChiselBlockName("Limestone Stairs");
|
||||
makerLimestoneStairs.carverHelper.addVariation("tile.limestoneStairs.0.desc", 0, "limestone");
|
||||
makerLimestoneStairs.carverHelper.addVariation("tile.limestoneStairs.1.desc", 1, "limestone/terrain-cobbsmalltilelight");
|
||||
@@ -1388,7 +1385,7 @@ public enum Features {
|
||||
registerSlabTop(marble_slab, marble_slab.top);
|
||||
Carving.chisel.registerOre("marble_slab", "marble_slab");
|
||||
|
||||
BlockMarbleStairsMaker makerMarbleStairs = new BlockMarbleStairsMaker(marble);
|
||||
CarvableStairsMaker makerMarbleStairs = new CarvableStairsMaker(marble);
|
||||
makerMarbleStairs.carverHelper.setChiselBlockName("Marble Stairs");
|
||||
makerMarbleStairs.carverHelper.addVariation("tile.marbleStairs.0.desc", 0, "marble");
|
||||
makerMarbleStairs.carverHelper.addVariation("tile.marbleStairs.6.desc", 1, "marbleslab/a1-stoneornamental-marblebrick");
|
||||
@@ -1644,7 +1641,7 @@ public enum Features {
|
||||
|
||||
@Override
|
||||
void addBlocks() {
|
||||
BlockMarbleStairsMaker makerPackedIceStairs = new BlockMarbleStairsMaker(Blocks.packed_ice);
|
||||
CarvableStairsMaker makerPackedIceStairs = new CarvableStairsMaker(Blocks.packed_ice);
|
||||
makerPackedIceStairs.carverHelper.setChiselBlockName("Packed Ice Stairs");
|
||||
makerPackedIceStairs.carverHelper.addVariation("tile.packediceStairs.0.desc", 0, Blocks.packed_ice);
|
||||
makerPackedIceStairs.carverHelper.addVariation("tile.packediceStairs.1.desc", 1, "ice/a1-ice-light");
|
||||
@@ -1662,14 +1659,14 @@ public enum Features {
|
||||
makerPackedIceStairs.carverHelper.addVariation("tile.packediceStairs.13.desc", 13, "ice/zelda");
|
||||
makerPackedIceStairs.carverHelper.addVariation("tile.packediceStairs.14.desc", 14, "ice/bismuth");
|
||||
makerPackedIceStairs.carverHelper.addVariation("tile.packediceStairs.15.desc", 15, "ice/poison");
|
||||
makerPackedIceStairs.create(new BlockMarbleStairsMakerCreator() {
|
||||
makerPackedIceStairs.create(new IStairsCreator() {
|
||||
|
||||
@Override
|
||||
public BlockCarvableStairs create(Block block, int meta, CarvableHelper helper) {
|
||||
return new BlockCarvablePackedIceStairs(block, meta, helper);
|
||||
}
|
||||
}, "packedice_stairs", ChiselBlocks.packediceStairs);
|
||||
Carving.chisel.registerOre("packedIceStairs", "packedIceStairs");
|
||||
Carving.chisel.registerOre("packedice_stairs", "packedIceStairs");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1708,7 +1705,7 @@ public enum Features {
|
||||
GameRegistry.registerBlock(present[x], "chest" + x);
|
||||
Carving.chisel.addVariation("present", present[x], 0, (x + 1));
|
||||
}
|
||||
Carving.chisel.registerOre("chest", "chest");
|
||||
Carving.chisel.registerOre("present", "chest");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1885,8 +1882,8 @@ public enum Features {
|
||||
road_line.carverHelper.addVariation("tile.roadLine.1.desc", 1, "line-marking/double-white-center");
|
||||
road_line.carverHelper.addVariation("tile.roadLine.2.desc", 2, "line-marking/yellow-center");
|
||||
road_line.carverHelper.addVariation("tile.roadLine.3.desc", 3, "line-marking/double-yellow-center");
|
||||
GameRegistry.registerBlock(road_line, ItemCarvable.class, "road_line");
|
||||
Carving.chisel.registerOre("roadLine", "roadLine");
|
||||
road_line.carverHelper.register(road_line, "road_line");
|
||||
Carving.chisel.registerOre("road_line", "roadLine");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1992,7 +1989,7 @@ public enum Features {
|
||||
// 13), "Sandstone snake block body");
|
||||
Carving.chisel.addVariation("sandstone", sand_snakestone, 1, 16);
|
||||
Carving.chisel.addVariation("sandstone", sand_snakestone, 13, 17);
|
||||
Carving.chisel.registerOre("sandSnakestone", "sandSnakestone");
|
||||
// Carving.chisel.registerOre("sandstone", "sandSnakestone");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2008,7 +2005,7 @@ public enum Features {
|
||||
// "Stone snake block body");
|
||||
Carving.chisel.addVariation("stonebrick", stone_snakestone, 1, 16);
|
||||
Carving.chisel.addVariation("stonebrick", stone_snakestone, 13, 17);
|
||||
Carving.chisel.registerOre("snakestoneStone", "snakestoneStone");
|
||||
// Carving.chisel.registerOre("snakestoneStone", "snakestoneStone");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2021,7 +2018,7 @@ public enum Features {
|
||||
GameRegistry.registerBlock(obsidian_snakestone, ItemCarvable.class, "obsidian_snakestone");
|
||||
Carving.chisel.addVariation("obsidian", obsidian_snakestone, 1, 16);
|
||||
Carving.chisel.addVariation("obsidian", obsidian_snakestone, 13, 17);
|
||||
Carving.chisel.registerOre("obsidianSnakestone", "obsidianSnakestone");
|
||||
// Carving.chisel.registerOre("obsidianSnakestone", "obsidianSnakestone");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2411,7 +2408,7 @@ public enum Features {
|
||||
for (int i = 0; i < plank_names.length; i++) {
|
||||
String n = plank_names[i];
|
||||
String u = plank_ucnames[i];
|
||||
final String orename = n.replace('-', '_') + "_planks";
|
||||
final String name = n.replace('-', '_') + "_planks";
|
||||
|
||||
planks[i] = (BlockCarvable) (new BlockCarvable(Material.wood)).setCreativeTab(ChiselTabs.tabWoodChiselBlocks).setHardness(2.0F).setResistance(5.0F).setStepSound(Block.soundTypeWood);
|
||||
planks[i].carverHelper.setChiselBlockName(u + " Wood Planks");
|
||||
@@ -2430,11 +2427,11 @@ public enum Features {
|
||||
planks[i].carverHelper.addVariation(u + " wood scaffold", 12, "planks-" + n + "/crateex");
|
||||
planks[i].carverHelper.addVariation(u + " wood planks in disarray", 14, "planks-" + n + "/chaotic-hor");
|
||||
planks[i].carverHelper.addVariation("Vertical " + n + " wood planks in disarray", 15, "planks-" + n + "/chaotic");
|
||||
planks[i].carverHelper.register(planks[i], orename);
|
||||
Carving.chisel.addVariation(orename, Blocks.planks, i, 0);
|
||||
planks[i].carverHelper.register(planks[i], name);
|
||||
Carving.chisel.addVariation(name, Blocks.planks, i, 0);
|
||||
planks[i].setHarvestLevel("axe", 0);
|
||||
Carving.chisel.registerOre("wood", "wood");
|
||||
Carving.chisel.setVariationSound(orename, Chisel.MOD_ID + ":chisel.wood");
|
||||
Carving.chisel.registerOre(name, "wood");
|
||||
Carving.chisel.setVariationSound(name, Chisel.MOD_ID + ":chisel.wood");
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2566,7 +2563,7 @@ public enum Features {
|
||||
boolean needsMetaRecipes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static void registerSlabTop(Block bottom, Block top) {
|
||||
String name = Block.blockRegistry.getNameForObject(bottom);
|
||||
name = name.substring(name.indexOf(':') + 1) + "_top";
|
||||
|
||||
+5
-11
@@ -2,7 +2,6 @@ package com.cricketcraft.chisel.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
|
||||
import com.cricketcraft.chisel.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.carving.CarvableVariation;
|
||||
@@ -10,14 +9,14 @@ import com.cricketcraft.chisel.item.ItemCarvable;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class BlockMarbleStairsMaker {
|
||||
public class CarvableStairsMaker {
|
||||
|
||||
public CarvableHelper carverHelper;
|
||||
// int idStart;
|
||||
Block blockBase;
|
||||
String blockName;
|
||||
|
||||
public BlockMarbleStairsMaker(Block base) {
|
||||
public CarvableStairsMaker(Block base) {
|
||||
carverHelper = new CarvableHelper();
|
||||
blockBase = base;
|
||||
}
|
||||
@@ -26,7 +25,7 @@ public class BlockMarbleStairsMaker {
|
||||
create(null, name, blocks);
|
||||
}
|
||||
|
||||
public void create(BlockMarbleStairsMakerCreator creator, String name, Block[] blocks) {
|
||||
public void create(IStairsCreator creator, String name, Block[] blocks) {
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
String n = name + "." + i;
|
||||
blocks[i] = creator == null ? new BlockCarvableStairs(blockBase, i * 2, carverHelper) : creator.create(blockBase, i * 2, carverHelper);
|
||||
@@ -37,15 +36,10 @@ public class BlockMarbleStairsMaker {
|
||||
for (int meta = 0; meta < 2 && i * 2 + meta < carverHelper.variations.size(); meta++) {
|
||||
CarvableVariation variation = carverHelper.variations.get(i * 2 + meta);
|
||||
|
||||
for (int j = 0; j < 8; j++)
|
||||
carverHelper.registerVariation(name + ".orientation." + j, variation, blocks[i], j + meta * 8);
|
||||
carverHelper.registerVariation(name, variation, blocks[i], meta * 8);
|
||||
|
||||
CraftingManager.getInstance().addRecipe(new ItemStack(blocks[i], 4, meta * 8), new Object[] { "* ", "** ", "***", '*', new ItemStack(blockBase, 1, i * 2 + meta) });
|
||||
GameRegistry.addRecipe(new ItemStack(blocks[i], 4, meta * 8), "* ", "** ", "***", '*', new ItemStack(blockBase, 1, i * 2 + meta));
|
||||
}
|
||||
|
||||
CarvableHelper.chiselBlocks.add(blocks[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ import net.minecraft.block.Block;
|
||||
|
||||
import com.cricketcraft.chisel.carving.CarvableHelper;
|
||||
|
||||
public interface BlockMarbleStairsMakerCreator {
|
||||
public interface IStairsCreator {
|
||||
|
||||
public BlockCarvableStairs create(Block block, int meta, CarvableHelper helper);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.block.BlockCarvableSlab;
|
||||
@@ -28,8 +29,6 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class CarvableHelper {
|
||||
|
||||
public static final ArrayList<Block> chiselBlocks = new ArrayList<Block>();
|
||||
|
||||
public static final int NORMAL = 0;
|
||||
public static final int TOPSIDE = 1;
|
||||
public static final int TOPBOTSIDE = 2;
|
||||
@@ -270,7 +269,6 @@ public class CarvableHelper {
|
||||
void registerBlock(Block block, String name, Class<? extends ItemCarvable> cl) {
|
||||
block.setBlockName(name);
|
||||
GameRegistry.registerBlock(block, cl, name);
|
||||
chiselBlocks.add(block);
|
||||
}
|
||||
|
||||
public void register(Block block, String name, Class<? extends ItemCarvable> cl) {
|
||||
@@ -388,7 +386,10 @@ public class CarvableHelper {
|
||||
|
||||
public static Set<Block> getChiselBlockSet() {
|
||||
HashSet<Block> tools = new HashSet<Block>();
|
||||
tools.addAll(CarvableHelper.chiselBlocks);
|
||||
return tools;
|
||||
}
|
||||
|
||||
public void registerOre(String ore) {
|
||||
OreDictionary.registerOre(ore, variations.get(0).block);
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,18 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
|
||||
public class Carving {
|
||||
|
||||
HashMap<String, CarvingGroup> carvingGroupsByName = new HashMap<String, CarvingGroup>();
|
||||
HashMap<String, CarvingGroup> carvingGroupsByOre = new HashMap<String, CarvingGroup>();
|
||||
HashMap<String, CarvingGroup> carvingGroupsByVariation = new HashMap<String, CarvingGroup>();
|
||||
GroupList groups = new GroupList();
|
||||
|
||||
public static Carving chisel = new Carving();
|
||||
public static Carving needle = new Carving();
|
||||
public static final Carving chisel = new Carving();
|
||||
public static final Carving needle = new Carving();
|
||||
|
||||
private Carving() {
|
||||
}
|
||||
|
||||
String key(Item item, int metadata) {
|
||||
return Item.itemRegistry.getNameForObject(item) + "|" + metadata;
|
||||
@@ -31,7 +33,7 @@ public class Carving {
|
||||
}
|
||||
|
||||
public List<ICarvingVariation> getVariations(Block block, int metadata) {
|
||||
CarvingGroup group = getGroup(block, metadata);
|
||||
ICarvingGroup group = getGroup(block, metadata);
|
||||
if (group == null)
|
||||
return null;
|
||||
|
||||
@@ -39,7 +41,7 @@ public class Carving {
|
||||
}
|
||||
|
||||
public String getOre(Block block, int metadata) {
|
||||
CarvingGroup group = getGroup(block, metadata);
|
||||
ICarvingGroup group = getGroup(block, metadata);
|
||||
if (group == null)
|
||||
return null;
|
||||
|
||||
@@ -51,7 +53,7 @@ public class Carving {
|
||||
|
||||
int damage = chiseledItem.getItemDamage();
|
||||
|
||||
CarvingGroup group = getGroup(Block.getBlockFromItem(chiseledItem.getItem()), damage);
|
||||
ICarvingGroup group = getGroup(Block.getBlockFromItem(chiseledItem.getItem()), damage);
|
||||
if (group == null)
|
||||
return items;
|
||||
|
||||
@@ -88,63 +90,53 @@ public class Carving {
|
||||
return items;
|
||||
}
|
||||
|
||||
public CarvingGroup getGroup(Block block, int metadata) {
|
||||
// Check name first
|
||||
CarvingGroup res;
|
||||
int i = OreDictionary.getOreID(block.getUnlocalizedName());
|
||||
if (i < 1)
|
||||
return null;
|
||||
|
||||
// get All dictionary names for that block via Ids
|
||||
// the first one matching with a group is chosen
|
||||
int[] oreDictIds = OreDictionary.getOreIDs(new ItemStack(block, 1, metadata));
|
||||
for (int oreId : oreDictIds) {
|
||||
String oreDictName = OreDictionary.getOreName(oreId);
|
||||
if (carvingGroupsByOre.containsKey(oreDictName))
|
||||
return carvingGroupsByOre.get(oreDictName);
|
||||
public ICarvingGroup getGroup(Block block, int metadata) {
|
||||
int[] ids = OreDictionary.getOreIDs(new ItemStack(block, metadata));
|
||||
if (ids.length > 0) {
|
||||
for (int id : ids) {
|
||||
return groups.getGroupByOre(OreDictionary.getOreName(id));
|
||||
}
|
||||
}
|
||||
|
||||
if ((res = carvingGroupsByVariation.get(key(block, metadata))) != null)
|
||||
return res;
|
||||
|
||||
return null;
|
||||
return groups.getGroup(block, metadata);
|
||||
}
|
||||
|
||||
public CarvingGroup getGroup(String name) {
|
||||
CarvingGroup group = carvingGroupsByName.get(name);
|
||||
if (group == null) {
|
||||
group = new CarvingGroup(name);
|
||||
carvingGroupsByName.put(name, group);
|
||||
}
|
||||
|
||||
return group;
|
||||
public ICarvingGroup getGroup(String name) {
|
||||
return groups.getGroupByName(name);
|
||||
}
|
||||
|
||||
public CarvingVariation addVariation(String name, Block block, int metadata, int order) {
|
||||
CarvingGroup group = getGroup(name);
|
||||
|
||||
CarvingGroup blockGroup = carvingGroupsByVariation.get(key(block, metadata));
|
||||
if (blockGroup != null || blockGroup == group)
|
||||
return null;
|
||||
|
||||
CarvingVariation variation = new CarvingVariation(block, metadata, order);
|
||||
group.addVariation(variation);
|
||||
carvingGroupsByVariation.put(key(block, metadata), group);
|
||||
|
||||
ICarvingGroup group = groups.getGroupByName(name);
|
||||
|
||||
if (group == null) {
|
||||
group = new CarvingGroup(name);
|
||||
groups.add(group);
|
||||
}
|
||||
|
||||
groups.addVariation(name, variation);
|
||||
|
||||
return variation;
|
||||
}
|
||||
|
||||
public void registerOre(String name, String oreName) {
|
||||
CarvingGroup group = getGroup(name);
|
||||
|
||||
carvingGroupsByOre.put(oreName, group);
|
||||
|
||||
group.setOreName(oreName);
|
||||
ICarvingGroup group = groups.getGroupByName(name);
|
||||
if (group != null) {
|
||||
group.setOreName(oreName);
|
||||
} else {
|
||||
throw new NullPointerException("Cannot register ore name for group " + name + ", as it does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setVariationSound(String name, String sound) {
|
||||
CarvingGroup group = getGroup(name);
|
||||
group.setSound(sound);
|
||||
ICarvingGroup group = groups.getGroupByName(name);
|
||||
if (group != null) {
|
||||
group.setSound(sound);
|
||||
} else {
|
||||
throw new NullPointerException("Cannot set sound for group " + name + ", as it does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
public String getVariationSound(Block block, int metadata) {
|
||||
@@ -152,18 +144,14 @@ public class Carving {
|
||||
}
|
||||
|
||||
public String getVariationSound(Item item, int metadata) {
|
||||
CarvingGroup blockGroup = carvingGroupsByVariation.get(key(item, metadata));
|
||||
if (blockGroup == null || blockGroup.getSound() == null)
|
||||
return Chisel.MOD_ID + ":chisel.fallback";
|
||||
|
||||
return blockGroup.getSound();
|
||||
ICarvingGroup group = groups.getGroup(Block.getBlockFromItem(item), metadata);
|
||||
String sound = group == null ? null : group.getSound();
|
||||
return sound == null ? Chisel.MOD_ID + ":chisel.fallback" : sound;
|
||||
}
|
||||
|
||||
public List<String> getSortedGroupNames() {
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (String s : carvingGroupsByName.keySet()) {
|
||||
names.add(s);
|
||||
}
|
||||
names.addAll(groups.getNames());
|
||||
Collections.sort(names);
|
||||
return names;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
package com.cricketcraft.chisel.carving;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class GroupList implements Set<ICarvingGroup> {
|
||||
|
||||
private class VariationWrapper {
|
||||
|
||||
private ICarvingVariation v;
|
||||
|
||||
private VariationWrapper(ICarvingVariation v) {
|
||||
this.v = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ICarvingVariation) {
|
||||
ICarvingVariation v2 = (ICarvingVariation) obj;
|
||||
return v.getBlock() == v2.getBlock() && (v.getBlockMeta() == v2.getBlockMeta() || v.getItemMeta() == v2.getItemMeta());
|
||||
} else if (obj instanceof VariationWrapper) {
|
||||
return equals(((VariationWrapper) obj).v);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return v.getBlock().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
private class VariationKey implements ICarvingVariation {
|
||||
|
||||
Pair<Block, Integer> data;
|
||||
|
||||
private VariationKey(Block block, int blockMeta) {
|
||||
data = Pair.of(block, blockMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ICarvingVariation o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock() {
|
||||
return data.getLeft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockMeta() {
|
||||
return data.getRight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemMeta() {
|
||||
return data.getRight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return data.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, ICarvingGroup> groups = Maps.newHashMap();
|
||||
private HashMap<VariationWrapper, ICarvingGroup> lookup = Maps.newHashMap();
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return groups.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return groups.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if (o instanceof ICarvingGroup) {
|
||||
return groups.containsKey(((ICarvingGroup) o).getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ICarvingGroup> iterator() {
|
||||
return groups.values().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return groups.values().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] arr) {
|
||||
return groups.values().toArray(arr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(ICarvingGroup group) {
|
||||
String key = group.getName();
|
||||
if (groups.containsKey(key)) {
|
||||
return false;
|
||||
}
|
||||
groups.put(key, group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
if (o instanceof ICarvingGroup) {
|
||||
return groups.remove(((ICarvingGroup) o).getName()) != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
for (Object o : c) {
|
||||
if (!(o instanceof ICarvingGroup)) {
|
||||
return false;
|
||||
}
|
||||
if (!groups.containsKey(((ICarvingGroup) o).getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends ICarvingGroup> c) {
|
||||
boolean ret = false;
|
||||
for (ICarvingGroup g : c) {
|
||||
ret |= add(g);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
boolean ret = false;
|
||||
for (Object o : c) {
|
||||
ret |= remove(o);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException(); // not using it, not gonna bother
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
groups.clear();
|
||||
}
|
||||
|
||||
public ICarvingGroup getGroup(Block block, int metadata) {
|
||||
return lookup.get(new VariationWrapper(new VariationKey(block, metadata)));
|
||||
}
|
||||
|
||||
public void addVariation(String name, ICarvingVariation variation) {
|
||||
ICarvingGroup g = groups.get(name);
|
||||
if (g == null) {
|
||||
throw new NullPointerException("No group exists for name " + name);
|
||||
}
|
||||
g.addVariation(variation);
|
||||
lookup.put(new VariationWrapper(variation), g);
|
||||
}
|
||||
|
||||
public ICarvingGroup getGroupByName(String groupName) {
|
||||
return groups.get(groupName);
|
||||
}
|
||||
|
||||
public ICarvingGroup getGroupByOre(String oreName) {
|
||||
for (ICarvingGroup group : groups.values()) {
|
||||
if (oreName.equals(group.getOreName())) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<? extends String> getNames() {
|
||||
return groups.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return groups.toString();
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,10 @@ public class Compatibility {
|
||||
|
||||
/* Mariculture */
|
||||
Block block = GameRegistry.findBlock("mariculture", "limestone");
|
||||
for (int i = 0; i < 16; i++) {
|
||||
addSupport("limestone", block, i, 99);
|
||||
if (block != null) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
addSupport("limestone", block, i, 99);
|
||||
}
|
||||
}
|
||||
|
||||
/* Geologica */
|
||||
|
||||
@@ -15,10 +15,9 @@ import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.carving.CarvingGroup;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
|
||||
public class RecipeHandlerChisel extends TemplateRecipeHandler {
|
||||
|
||||
@@ -108,7 +107,7 @@ public class RecipeHandlerChisel extends TemplateRecipeHandler {
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
if (outputId.equals("chisel2.chisel")) {
|
||||
for (String name : Carving.chisel.getSortedGroupNames()) {
|
||||
CarvingGroup g = Carving.chisel.getGroup(name);
|
||||
ICarvingGroup g = Carving.chisel.getGroup(name);
|
||||
if (!g.getVariations().isEmpty()) {
|
||||
addCached(getVariationStacks(g));
|
||||
}
|
||||
@@ -121,7 +120,7 @@ public class RecipeHandlerChisel extends TemplateRecipeHandler {
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result) {
|
||||
for (String name : Carving.chisel.getSortedGroupNames()) {
|
||||
CarvingGroup g = Carving.chisel.getGroup(name);
|
||||
ICarvingGroup g = Carving.chisel.getGroup(name);
|
||||
List<ItemStack> variations = getVariationStacks(g);
|
||||
for (ItemStack stack : variations) {
|
||||
if (NEIServerUtils.areStacksSameTypeCrafting(stack, result)) {
|
||||
@@ -134,7 +133,7 @@ public class RecipeHandlerChisel extends TemplateRecipeHandler {
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
for (String name : Carving.chisel.getSortedGroupNames()) {
|
||||
CarvingGroup g = Carving.chisel.getGroup(name);
|
||||
ICarvingGroup g = Carving.chisel.getGroup(name);
|
||||
List<ItemStack> variations = getVariationStacks(g);
|
||||
for (ItemStack stack : variations) {
|
||||
if (NEIServerUtils.areStacksSameTypeCrafting(stack, ingredient)) {
|
||||
@@ -163,7 +162,7 @@ public class RecipeHandlerChisel extends TemplateRecipeHandler {
|
||||
addCached(variations, null, null);
|
||||
}
|
||||
|
||||
private static List<ItemStack> getVariationStacks(CarvingGroup g) {
|
||||
private static List<ItemStack> getVariationStacks(ICarvingGroup g) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
for (ICarvingVariation v : g.getVariations()) {
|
||||
stacks.add(v.getStack());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.cricketcraft.chisel.item.chisel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -12,6 +14,7 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
import com.cricketcraft.chisel.network.PacketHandler;
|
||||
@@ -49,27 +52,33 @@ public final class ChiselController {
|
||||
z = event.z;
|
||||
Block block = event.world.getBlock(x, y, z);
|
||||
int metadata = event.world.getBlockMetadata(x, y, z);
|
||||
CarvingVariation[] variations = Carving.chisel.getVariations(block, metadata).toArray(new CarvingVariation[] {});
|
||||
List<ICarvingVariation> list = Carving.chisel.getVariations(block, metadata);
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
ICarvingVariation[] variations = list.toArray(new CarvingVariation[] {});
|
||||
|
||||
if (variations != null && chisel.canChiselBlock(event.world, x, y, z, block, metadata)) {
|
||||
if (chisel.canChiselBlock(event.world, x, y, z, block, metadata)) {
|
||||
ItemStack target = General.getChiselTarget(held);
|
||||
|
||||
if (target != null) {
|
||||
for (CarvingVariation v : variations) {
|
||||
for (ICarvingVariation v : variations) {
|
||||
if (v.getBlock() == Block.getBlockFromItem(target.getItem()) && v.getBlockMeta() == target.getItemDamage()) {
|
||||
setVariation(event.entityPlayer, event.world, x, y, z, v, target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < variations.length; i++) {
|
||||
CarvingVariation v = variations[i];
|
||||
ICarvingVariation v = variations[i];
|
||||
if (v.getBlock() == block && v.getBlockMeta() == metadata) {
|
||||
variations = ArrayUtils.remove(variations, i--);
|
||||
}
|
||||
}
|
||||
|
||||
int index = event.world.rand.nextInt(variations.length);
|
||||
CarvingVariation newVar = variations[index];
|
||||
ICarvingVariation newVar = variations[index];
|
||||
setVariation(event.entityPlayer, event.world, x, y, z, newVar, new ItemStack(newVar.getBlock(), 1, newVar.getItemMeta()));
|
||||
event.entityPlayer.inventory.currentItem = slot;
|
||||
}
|
||||
@@ -87,7 +96,7 @@ public final class ChiselController {
|
||||
/**
|
||||
* Assumes that the player is holding a chisel
|
||||
*/
|
||||
private void setVariation(EntityPlayer player, World world, int x, int y, int z, CarvingVariation v, ItemStack target) {
|
||||
private void setVariation(EntityPlayer player, World world, int x, int y, int z, ICarvingVariation v, ItemStack target) {
|
||||
PacketHandler.INSTANCE.sendTo(new MessageChiselSound(x, y, z, v), (EntityPlayerMP) player);
|
||||
world.setBlock(x, y, z, v.getBlock(), v.getBlockMeta(), 3);
|
||||
((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), target);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.cricketcraft.chisel.network.message;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
import com.cricketcraft.chisel.client.GeneralChiselClient;
|
||||
import com.cricketcraft.chisel.item.chisel.ItemChisel;
|
||||
@@ -21,7 +22,7 @@ public class MessageChiselSound extends MessageCoords {
|
||||
private int block;
|
||||
private byte meta;
|
||||
|
||||
public MessageChiselSound(int x, int y, int z, CarvingVariation v) {
|
||||
public MessageChiselSound(int x, int y, int z, ICarvingVariation v) {
|
||||
super(x, y, z);
|
||||
this.block = Block.getIdFromBlock(v.getBlock());
|
||||
this.meta = (byte) v.getBlockMeta();
|
||||
|
||||
Reference in new issue
Block a user