use of net.silentchaos512.gems.api.tool.part.ToolPartMain in project SilentGems by SilentChaos512.
the class TileMaterialGrader method isItemValidForSlot.
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
if (index == SLOT_INPUT) {
if (StackHelper.isEmpty(stack)) {
return false;
}
ToolPart part = ToolPartRegistry.fromStack(stack);
EnumMaterialGrade grade = EnumMaterialGrade.fromStack(stack);
if (part != null && part instanceof ToolPartMain && grade == EnumMaterialGrade.NONE) {
return true;
}
return false;
}
return false;
}
use of net.silentchaos512.gems.api.tool.part.ToolPartMain in project SilentGems by SilentChaos512.
the class ArmorHelper method decorate.
private static ItemStack decorate(ItemStack armor, ItemStack material, EnumDecoPos pos) {
if (StackHelper.isEmpty(armor))
return StackHelper.empty();
if (StackHelper.isEmpty(material))
return armor;
ToolPart part = ToolPartRegistry.fromStack(material);
if (part == null)
return null;
// Only main parts (like gems) work
if (!(part instanceof ToolPartMain))
return armor;
ItemStack result = StackHelper.safeCopy(armor);
switch(pos) {
case WEST:
setTagPart(result, NBT_DECO_WEST, part, EnumMaterialGrade.fromStack(material));
break;
case NORTH:
setTagPart(result, NBT_DECO_NORTH, part, EnumMaterialGrade.fromStack(material));
break;
case EAST:
setTagPart(result, NBT_DECO_EAST, part, EnumMaterialGrade.fromStack(material));
break;
case SOUTH:
setTagPart(result, NBT_DECO_SOUTH, part, EnumMaterialGrade.fromStack(material));
break;
default:
SilentGems.instance.logHelper.warning("ArmorHelper.decorate: invalid deco pos " + pos);
break;
}
return result;
}
use of net.silentchaos512.gems.api.tool.part.ToolPartMain in project SilentGems by SilentChaos512.
the class TileMaterialGrader method update.
@Override
public void update() {
if (world.isRemote)
return;
ItemStack input = getStackInSlot(SLOT_INPUT);
ToolPart part = ToolPartRegistry.fromStack(input);
// Is input (if anything) a grade-able part?
if (part != null && part instanceof ToolPartMain && EnumMaterialGrade.fromStack(input) == EnumMaterialGrade.NONE) {
// Analyze, if we have enough energy.
if (chaosStored >= CHAOS_PER_TICK) {
// Analyzing material.
if (progress < ANALYZE_TIME) {
chaosStored -= CHAOS_PER_TICK;
++progress;
requireClientSync = true;
}
// Grade material if any output slot is free.
int outputSlot = getFreeOutputSlot();
if (progress >= ANALYZE_TIME && outputSlot > 0) {
progress = 0;
// Take one from input stack.
ItemStack stack = StackHelper.safeCopy(input);
StackHelper.setCount(stack, 1);
StackHelper.shrink(input, 1);
// Assign random grade.
EnumMaterialGrade.selectRandom(SilentGems.random).setGradeOnStack(stack);
// Set to output slot, clear input slot if needed.
setInventorySlotContents(outputSlot, stack);
if (StackHelper.getCount(input) <= 0) {
setInventorySlotContents(SLOT_INPUT, StackHelper.empty());
}
requireClientSync = true;
}
}
} else {
progress = 0;
}
// Send update to client?
if (requireClientSync) {
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
requireClientSync = false;
}
}
Aggregations