Fixed chisel not working with metadata
This commit is contained in:
parent
94d69f8ba5
commit
dfe689a480
2 changed files with 55 additions and 57 deletions
|
@ -39,7 +39,9 @@ public class ChiselHelper {
|
|||
}
|
||||
|
||||
public static ICarvingVariation makeVariation(IItemStack stack) {
|
||||
return new CarvingVariation(Block.getBlockFromItem(toStack(stack).getItem()));
|
||||
Block block = Block.getBlockFromItem(toStack(stack).getItem());
|
||||
IBlockState state = block.getStateFromMeta(toStack(stack).getItemDamage());
|
||||
return CarvingUtils.getDefaultVariationFor(state, 0);
|
||||
}
|
||||
|
||||
public static ICarvingGroup makeGroup(String name) {
|
||||
|
|
|
@ -1,230 +1,226 @@
|
|||
package modtweaker.mods.chisel.handlers;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.*;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import modtweaker.mods.chisel.ChiselHelper;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import team.chisel.api.carving.CarvingUtils;
|
||||
import team.chisel.api.carving.ICarvingGroup;
|
||||
import team.chisel.api.carving.ICarvingVariation;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
import team.chisel.api.carving.*;
|
||||
|
||||
|
||||
@ZenClass("mods.chisel.Groups")
|
||||
public class Groups {
|
||||
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void addVariation(String groupName, IItemStack stack) {
|
||||
ICarvingGroup group = ChiselHelper.getGroup(groupName);
|
||||
ICarvingVariation variation = ChiselHelper.makeVariation(stack);
|
||||
if (group == null) {
|
||||
if(group == null) {
|
||||
MineTweakerAPI.getLogger().logError("Cannot find group " + groupName);
|
||||
return;
|
||||
}
|
||||
if (variation == null) {
|
||||
if(variation == null) {
|
||||
MineTweakerAPI.getLogger().logError("Can't create variation from " + stack);
|
||||
return;
|
||||
}
|
||||
MineTweakerAPI.apply(new AddVariation(group, variation, stack.toString()));
|
||||
}
|
||||
|
||||
|
||||
static class AddVariation implements IUndoableAction {
|
||||
|
||||
|
||||
ICarvingGroup group;
|
||||
ICarvingVariation variation;
|
||||
String variationName;
|
||||
|
||||
|
||||
public AddVariation(ICarvingGroup group, ICarvingVariation variation, String variationName) {
|
||||
this.group = group;
|
||||
this.variation = variation;
|
||||
this.variationName = variationName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
CarvingUtils.getChiselRegistry().addVariation(group.getName(), variation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return group != null && variation != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding Variation: " + variationName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing Variation: " + variationName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
CarvingUtils.getChiselRegistry().removeVariation(variation.getBlockState(), group.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void removeVariation(IItemStack stack) {
|
||||
ICarvingVariation variation = ChiselHelper.getVariation(stack);
|
||||
if (variation == null) {
|
||||
if(variation == null) {
|
||||
MineTweakerAPI.getLogger().logError("Can't find variation from " + stack);
|
||||
return;
|
||||
}
|
||||
MineTweakerAPI.apply(new RemoveVariation(variation, stack.toString()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static class RemoveVariation implements IUndoableAction {
|
||||
|
||||
|
||||
ICarvingVariation variation;
|
||||
String variationName;
|
||||
ICarvingGroup group;
|
||||
|
||||
|
||||
public RemoveVariation(ICarvingVariation variation, String variationName) {
|
||||
this.variation = variation;
|
||||
this.variationName = variationName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
group = CarvingUtils.getChiselRegistry().getGroup(variation.getStack());
|
||||
CarvingUtils.getChiselRegistry().removeVariation(variation.getBlockState(), group.getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return group != null && variation != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing Variation: " + variationName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Adding Variation: " + variationName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
CarvingUtils.getChiselRegistry().addVariation(group.getName(), variation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void addGroup(String groupName) {
|
||||
ICarvingGroup group = ChiselHelper.getGroup(groupName);
|
||||
if (group != null) {
|
||||
if(group != null) {
|
||||
MineTweakerAPI.getLogger().logError("Group already exists " + groupName);
|
||||
return;
|
||||
}
|
||||
group = ChiselHelper.makeGroup(groupName);
|
||||
MineTweakerAPI.apply(new AddGroup(group));
|
||||
}
|
||||
|
||||
|
||||
static class AddGroup implements IUndoableAction {
|
||||
|
||||
|
||||
ICarvingGroup group;
|
||||
|
||||
|
||||
public AddGroup(ICarvingGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
CarvingUtils.getChiselRegistry().addGroup(group);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return group != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding Group: " + group.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing Group: " + group.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
CarvingUtils.getChiselRegistry().removeGroup(group.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void removeGroup(String groupName) {
|
||||
ICarvingGroup group = ChiselHelper.getGroup(groupName);
|
||||
if (group == null) {
|
||||
if(group == null) {
|
||||
MineTweakerAPI.getLogger().logError("Could not find group " + groupName);
|
||||
return;
|
||||
}
|
||||
MineTweakerAPI.apply(new RemoveGroup(group));
|
||||
}
|
||||
|
||||
|
||||
static class RemoveGroup implements IUndoableAction {
|
||||
|
||||
|
||||
ICarvingGroup group;
|
||||
|
||||
|
||||
public RemoveGroup(ICarvingGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
CarvingUtils.getChiselRegistry().removeGroup(group.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return group != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing Group: " + group.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Adding Group: " + group.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
CarvingUtils.getChiselRegistry().addGroup(group);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue