use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class RandomGearCommand method run.
private static int run(CommandContext<CommandSourceStack> context, Collection<ServerPlayer> players, ResourceLocation itemId, int tier) throws CommandSyntaxException {
Item item = ForgeRegistries.ITEMS.getValue(itemId);
if (!(item instanceof ICoreItem)) {
context.getSource().sendFailure(new TranslatableComponent("command.silentgear.randomGear.invalidItem"));
return 0;
}
for (ServerPlayer player : players) {
ItemStack stack = GearGenerator.create((ICoreItem) item, tier);
if (!stack.isEmpty()) {
context.getSource().sendSuccess(new TranslatableComponent("commands.give.success.single", 1, stack.getDisplayName(), player.getDisplayName()), true);
PlayerUtils.giveItem(player, stack.copy());
}
}
return 1;
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class SetDamageCommand method run.
private static int run(CommandContext<CommandSourceStack> context, int amount) throws CommandSyntaxException {
ServerPlayer playerMP = context.getSource().getPlayerOrException();
ItemStack stack = playerMP.getMainHandItem();
if (stack.isDamageableItem()) {
// amount of -1 indicates "max" value
int correctedAmount = amount < 0 ? getMaxDamage(stack) : amount;
int clamped = Mth.clamp(correctedAmount, 0, getMaxDamage(stack));
stack.setDamageValue(clamped);
if (stack.getItem() instanceof ICoreItem) {
GearData.recalculateStats(stack, playerMP);
}
return 1;
} else {
Component msg = TextUtil.translate("command", "set_damage.notDamageable", stack.getHoverName());
context.getSource().sendFailure(msg);
return 0;
}
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class ModGiftLootTables method accept.
@Override
public void accept(BiConsumer<ResourceLocation, LootTable.Builder> p_accept_1_) {
p_accept_1_.accept(ModItems.BLUEPRINT_PACKAGE.get().getDefaultLootTable(), LootTable.lootTable().withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.ROD_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.PICKAXE_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.SHOVEL_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.AXE_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.KNIFE_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.SWORD_BLUEPRINT).setWeight(11)).add(LootItem.lootTableItem(ModItems.KATANA_BLUEPRINT).setWeight(5)).add(LootItem.lootTableItem(ModItems.MACHETE_BLUEPRINT).setWeight(7)).add(LootItem.lootTableItem(ModItems.SPEAR_BLUEPRINT).setWeight(8))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.SHIELD_BLUEPRINT))));
for (Item item : Registration.getItems(item -> item instanceof ICoreItem)) {
p_accept_1_.accept(SilentGear.getId("random_gear/" + NameUtils.from(item).getPath()), LootTable.lootTable().withPool(LootPool.lootPool().add(LootItem.lootTableItem(item).setWeight(3).apply(SelectGearTierLootFunction.builder(1))).add(LootItem.lootTableItem(item).setWeight(5).apply(SelectGearTierLootFunction.builder(2))).add(LootItem.lootTableItem(item).setWeight(2).apply(SelectGearTierLootFunction.builder(3)))));
}
// FIXME
p_accept_1_.accept(SilentGear.getId("test/ldf_mallet"), LootTable.lootTable().withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.HAMMER).apply(SetPartsFunction.builder(ImmutableList.of(new LazyPartData(SilentGear.getId("main/diamond")), new LazyPartData(SilentGear.getId("main/diamond")), new LazyPartData(SilentGear.getId("main/emerald")), new LazyPartData(SilentGear.getId("rod/blaze")), new LazyPartData(SilentGear.getId("tip/redstone"))))).apply(() -> setName(new TextComponent("Loliberty Defense Force Mallet"))).apply(() -> setLore(ImmutableList.of(new TextComponent("Standard Issue"), new TextComponent("Protectors of Free Speech")))))));
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class QuickRepairRecipe method matches.
@Override
public boolean matches(CraftingContainer inv, Level worldIn) {
// Need 1 gear, 1 repair kit, and optional materials
ItemStack gear = ItemStack.EMPTY;
boolean foundKit = false;
float repairKitEfficiency = Config.Common.missingRepairKitEfficiency.get().floatValue();
List<ItemStack> materials = new ArrayList<>();
for (int i = 0; i < inv.getContainerSize(); ++i) {
ItemStack stack = inv.getItem(i);
if (!stack.isEmpty()) {
// noinspection ChainOfInstanceofChecks
if (stack.getItem() instanceof ICoreItem) {
if (!gear.isEmpty()) {
return false;
}
gear = stack;
} else if (stack.getItem() instanceof RepairKitItem) {
if (foundKit) {
return false;
}
foundKit = true;
repairKitEfficiency = getKitEfficiency(stack);
} else if (MaterialManager.from(stack) != null) {
materials.add(stack);
} else {
return false;
}
}
}
if (gear.isEmpty() || repairKitEfficiency < 0.1E-9)
return false;
for (ItemStack stack : materials) {
if (!ModRecipes.isRepairMaterial(gear, stack)) {
return false;
}
}
return true;
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class QuickRepairRecipe method getRemainingItems.
@Override
public NonNullList<ItemStack> getRemainingItems(CraftingContainer inv) {
NonNullList<ItemStack> list = NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY);
StackList stackList = StackList.from(inv);
ItemStack gear = stackList.uniqueMatch(s -> s.getItem() instanceof ICoreItem);
ItemStack repairKit = stackList.uniqueMatch(s -> s.getItem() instanceof RepairKitItem);
for (int i = 0; i < list.size(); ++i) {
ItemStack stack = inv.getItem(i);
if (stack.getItem() instanceof RepairKitItem) {
repairWithLooseMaterials(gear, repairKit, stackList.allMatches(mat -> ModRecipes.isRepairMaterial(gear, mat)));
RepairKitItem item = (RepairKitItem) stack.getItem();
ItemStack copy = stack.copy();
item.removeRepairMaterials(copy, item.getRepairMaterials(gear, copy, RepairContext.Type.QUICK));
list.set(i, copy);
} else if (stack.hasContainerItem()) {
list.set(i, stack.getContainerItem());
}
}
return list;
}
Aggregations