Add group removal support. Add player argument to canChiselBlock

This commit is contained in:
tterrag1098 committed 2015-01-23 16:09:40 -05:00
1 parent 2321c2e636
commit 8467b1cbb8
6 files changed
+29 -7

No files matched your search

@@ -58,19 +58,21 @@ public interface IChiselItem {
*
* @param world
* World object
* @param player
* {@link EntityPlayer The player} holding the chisel.
* @param x
* X coord of the block being chiseled
* @param y
* Y coord of the block being chiseled
* @param z
* Z coord of the block being chiseled
* Z coord of the block being chmatiseled
* @param block
* The {@link Block} being chiseled
* @param metadata
* The blocks' metadata
* @return True if the chiseling should take place. False otherwise.
*/
boolean canChiselBlock(World world, int x, int y, int z, Block block, int metadata);
boolean canChiselBlock(World world, EntityPlayer player, int x, int y, int z, Block block, int metadata);
/**
* Allows you to control if your item has chiseling modes.
@@ -40,6 +40,8 @@ public interface ICarvingRegistry {
void addVariation(String groupName, ICarvingVariation variation);
void addGroup(ICarvingGroup group);
ICarvingGroup removeGroup(String groupName);
void registerOre(String groupName, String oreName);
@@ -119,6 +119,12 @@ public class Carving implements ICarvingRegistry {
return groups.getGroupByName(name);
}
@Override
public ICarvingGroup removeGroup(String groupName) {
ICarvingGroup g = groups.getGroupByName(groupName);
return groups.remove(g) ? g : null;
}
@Override
public void addVariation(String groupName, Block block, int metadata, int order) {
if (block == null) {
@@ -3,6 +3,8 @@ package com.cricketcraft.chisel.carving;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
@@ -11,6 +13,8 @@ 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.HashBiMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
public class GroupList implements Set<ICarvingGroup> {
@@ -75,7 +79,7 @@ public class GroupList implements Set<ICarvingGroup> {
}
private HashMap<String, ICarvingGroup> groups = Maps.newHashMap();
private HashMap<VariationWrapper, ICarvingGroup> lookup = Maps.newHashMap();
private HashBiMap<VariationWrapper, ICarvingGroup> lookup = HashBiMap.create();
@Override
public int size() {
@@ -129,9 +133,17 @@ public class GroupList implements Set<ICarvingGroup> {
@Override
public boolean remove(Object o) {
if (o instanceof ICarvingGroup) {
Map<ICarvingGroup, VariationWrapper> reverse = lookup.inverse();
List<VariationWrapper> toRemove = Lists.newArrayList();
for (ICarvingGroup g : reverse.keySet()) {
if (g.getName().equals(((ICarvingGroup) o).getName())) {
toRemove.add(reverse.get(g));
}
}
for (VariationWrapper v : toRemove) {
lookup.remove(v);
}
return groups.remove(((ICarvingGroup) o).getName()) != null;
} else if (o instanceof ICarvingVariation) {
// TODO support carving variation removal
}
return false;
}
@@ -71,7 +71,7 @@ public final class ChiselController {
ICarvingVariation[] variations = list.toArray(new CarvingVariation[] {});
if (chisel.canChiselBlock(event.world, x, y, z, block, metadata)) {
if (chisel.canChiselBlock(event.world, event.entityPlayer, x, y, z, block, metadata)) {
ItemStack target = General.getChiselTarget(held);
IChiselMode mode = General.getChiselMode(held);
ForgeDirection sideHit = ForgeDirection.VALID_DIRECTIONS[event.face];
@@ -116,7 +116,7 @@ public class ItemChisel extends Item implements IChiselItem {
}
@Override
public boolean canChiselBlock(World world, int x, int y, int z, Block block, int metadata) {
public boolean canChiselBlock(World world, EntityPlayer player, int x, int y, int z, Block block, int metadata) {
return type == ChiselType.DIAMOND || Configurations.ironChiselCanLeftClick;
}