Skip to content

Commit

Permalink
refactor to SkillCheck, add mod menu support
Browse files Browse the repository at this point in the history
  • Loading branch information
LemmaEOF committed May 8, 2019
1 parent 7984be3 commit 550e45c
Show file tree
Hide file tree
Showing 42 changed files with 280 additions and 217 deletions.
14 changes: 11 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ apply plugin: net.fabricmc.loom.LoomGradlePlugin
sourceCompatibility = 1.8
targetCompatibility = 1.8

archivesBaseName = "skillworks"
archivesBaseName = "skillcheck"
group = "io.github.cottonmc"
version = "0.1.1+1.14"

minecraft {
refmapName = 'mixins.skillworks.refmap.json'
refmapName = 'mixins.skillcheck.refmap.json'
}

repositories {
Expand All @@ -39,6 +39,9 @@ repositories {
maven {
url 'http://server.bbkr.space:8081/artifactory/libs-snapshot'
}
maven {
url = "https://minecraft.curseforge.com/api/maven"
}
}

dependencies {
Expand All @@ -47,8 +50,13 @@ dependencies {
modCompile "net.fabricmc:fabric-loader:0.4.4+build.138"
modCompile "net.fabricmc:fabric:0.2.7+build.127"

modCompile "io.github.prospector.modmenu:ModMenu:1.5.1-81"
modCompile "io.github.cottonmc:cotton:0.6.1+1.14-SNAPSHOT"
modCompile 'com.github.raphydaphy:crochet:a203643485'
include "io.github.cottonmc:cotton:0.6.1+1.14-SNAPSHOT"
modCompile "com.github.raphydaphy:crochet:a203643485"
include "com.github.raphydaphy:crochet:a203643485"
modCompile "cloth-config:ClothConfig:0.2.1.14"
include "cloth-config:ClothConfig:0.2.1.14"
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package io.github.cottonmc.skillworks;
package io.github.cottonmc.skillcheck;

import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;

public class CharacterSheetItem extends Item {

public CharacterSheetItem() {
super(new Item.Settings().itemGroup(Skillworks.SKILLWORKS_GROUP).stackSize(1));
super(new Item.Settings().itemGroup(SkillCheck.SKILLCHECK_GROUP).stackSize(1));
}

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
if (world.isClient) return new TypedActionResult<>(ActionResult.PASS, player.getStackInHand(hand));
ContainerProviderRegistry.INSTANCE.openContainer(Skillworks.CHARACTER_SHEET_CONTAINER, player, buf -> buf.writeBlockPos(player.getBlockPos()));
ContainerProviderRegistry.INSTANCE.openContainer(SkillCheck.CHARACTER_SHEET_CONTAINER, player, buf -> buf.writeBlockPos(player.getBlockPos()));
return new TypedActionResult<>(ActionResult.SUCCESS, player.getStackInHand(hand));
}

@Override
public Rarity getRarity(ItemStack stack) {
return Rarity.UNCOMMON;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.cottonmc.skillworks;
package io.github.cottonmc.skillcheck;

import io.github.cottonmc.skillworks.api.traits.ClassManager;
import io.github.cottonmc.skillcheck.api.traits.ClassManager;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
Expand All @@ -24,7 +24,7 @@ public class ClassScrollItem extends Item {
Identifier trait;

public ClassScrollItem(Identifier trait) {
super(new Item.Settings().itemGroup(Skillworks.SKILLWORKS_GROUP).stackSize(1));
super(new Item.Settings().itemGroup(SkillCheck.SKILLCHECK_GROUP).stackSize(1));
this.trait = trait;
}

Expand All @@ -33,7 +33,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand h
ClassManager.levelUp(player, trait);
if (!player.isCreative()) player.getStackInHand(hand).subtractAmount(1);
player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1.0f, 1.0f);
player.addChatMessage(new TranslatableTextComponent("msg.skillworks.levelup", getTraitName()), true);
player.addChatMessage(new TranslatableTextComponent("msg.skillcheck.levelup", getTraitName()), true);
return new TypedActionResult<>(ActionResult.SUCCESS, player.getStackInHand(hand));
}

Expand All @@ -49,7 +49,7 @@ public void buildTooltip(ItemStack stack, World world, List<TextComponent> toolt
} else {
flavor = stack.getTag().getInt("FlavorText");
}
tooltips.add(new TranslatableTextComponent("tooltip.skillworks.scroll.flavor_"+flavor, getTraitName()).applyFormat(TextFormat.GRAY, TextFormat.ITALIC));
tooltips.add(new TranslatableTextComponent("tooltip.skillcheck.scroll.flavor_"+flavor, getTraitName()).applyFormat(TextFormat.GRAY, TextFormat.ITALIC));
}

String getTraitName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.github.cottonmc.skillworks;
package io.github.cottonmc.skillcheck;

import com.mojang.brigadier.arguments.StringArgumentType;
import io.github.cottonmc.cotton.config.ConfigManager;
import io.github.cottonmc.skillworks.api.traits.ClassManager;
import io.github.cottonmc.skillworks.container.CharacterSheetContainer;
import io.github.cottonmc.skillworks.events.PlayerAttackEvent;
import io.github.cottonmc.skillworks.events.PlayerStealEvent;
import io.github.cottonmc.skillworks.api.dice.Dice;
import io.github.cottonmc.skillworks.api.dice.DiceResult;
import io.github.cottonmc.skillworks.util.SkillworksConfig;
import io.github.cottonmc.skillworks.util.SkillworksNetworking;
import io.github.cottonmc.skillcheck.api.traits.ClassManager;
import io.github.cottonmc.skillcheck.container.CharacterSheetContainer;
import io.github.cottonmc.skillcheck.events.PlayerAttackEvent;
import io.github.cottonmc.skillcheck.events.PlayerStealEvent;
import io.github.cottonmc.skillcheck.api.dice.Dice;
import io.github.cottonmc.skillcheck.api.dice.RollResult;
import io.github.cottonmc.skillcheck.util.SkillCheckConfig;
import io.github.cottonmc.skillcheck.util.SkillCheckNetworking;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
Expand All @@ -18,7 +18,6 @@
import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.fabric.api.tag.TagRegistry;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
Expand All @@ -29,12 +28,12 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class Skillworks implements ModInitializer {
public static SkillworksConfig config;
public static final String MOD_ID = "skillworks";
public class SkillCheck implements ModInitializer {
public static SkillCheckConfig config;
public static final String MOD_ID = "skillcheck";

public static Item CHARACTER_SHEET;
public static final ItemGroup SKILLWORKS_GROUP = FabricItemGroupBuilder.build(new Identifier("skillworks:skillworks_group"), () -> new ItemStack(CHARACTER_SHEET));
public static final ItemGroup SKILLCHECK_GROUP = FabricItemGroupBuilder.build(new Identifier(MOD_ID, "skillcheck_group"), () -> new ItemStack(CHARACTER_SHEET));

public static final Tag<Block> SLIPPERY_BLOCKS = TagRegistry.block(new Identifier(MOD_ID, "slippery"));

Expand All @@ -54,19 +53,12 @@ public static Item register(String name, Item item) {
return item;
}

public static Block register(String name, Block block) {
Registry.register(Registry.BLOCK, new Identifier(MOD_ID, name), block);
BlockItem item = new BlockItem(block, new Item.Settings().itemGroup(SKILLWORKS_GROUP));
register(name, item);
return block;
}

@Override
public void onInitialize() {
SkillworksNetworking.init();
SkillCheckNetworking.init();
//to prevent forward reference issue
CHARACTER_SHEET = register("character_sheet", new CharacterSheetItem());
config = ConfigManager.loadConfig(SkillworksConfig.class);
config = ConfigManager.loadConfig(SkillCheckConfig.class);
AttackEntityCallback.EVENT.register(PlayerAttackEvent.onPlayerAttack);
UseEntityCallback.EVENT.register(PlayerStealEvent.onPlayerInteract);

Expand All @@ -78,15 +70,15 @@ public void onInitialize() {
.then(CommandManager.argument("formula", StringArgumentType.word())
.executes(context -> {
String formula = context.getArgument("formula", String.class);
DiceResult result;
RollResult result;
try {
result = Dice.roll(formula);
} catch (IllegalArgumentException e) {
context.getSource().sendError(new StringTextComponent(e.getMessage()));
return -1;
}
if (result.isCritFail()) context.getSource().sendFeedback(new TranslatableTextComponent("msg.skillworks.roll.fail", result.getFormattedNaturals()), false);
else context.getSource().sendFeedback(new TranslatableTextComponent("msg.skillworks.roll.result", result.getTotal(), result.getFormattedNaturals()), false);
if (result.isCritFail()) context.getSource().sendFeedback(new TranslatableTextComponent("msg.skillcheck.roll.fail", result.getFormattedNaturals()), false);
else context.getSource().sendFeedback(new TranslatableTextComponent("msg.skillcheck.roll.result", result.getTotal(), result.getFormattedNaturals()), false);
return 1;
})))));
}
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/io/github/cottonmc/skillcheck/SkillCheckClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.github.cottonmc.skillcheck;

import io.github.cottonmc.skillcheck.container.CharacterSheetScreen;
import io.github.prospector.modmenu.api.ModMenuApi;
import me.shedaniel.cloth.api.ConfigScreenBuilder;
import me.shedaniel.cloth.gui.ClothConfigScreen;
import me.shedaniel.cloth.gui.entries.BooleanListEntry;
import me.shedaniel.cloth.gui.entries.IntegerSliderEntry;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Screen;

import java.util.function.Function;

public class SkillCheckClient implements ClientModInitializer, ModMenuApi {

@Override
public void onInitializeClient() {
ScreenProviderRegistry.INSTANCE.registerFactory(SkillCheck.CHARACTER_SHEET_CONTAINER, (syncId, id, player, buf) -> new CharacterSheetScreen(syncId, player));
}

@Override
public String getModId() {
return SkillCheck.MOD_ID;
}

@Override
public Function<Screen, ? extends Screen> getConfigScreenFactory() {
return (prevScreen) -> {
ClothConfigScreen.Builder builder = new ClothConfigScreen.Builder(MinecraftClient.getInstance().currentScreen, "SkillCheck Config", null);
builder.addCategories("General Settings", "Dice Roll Requirements");
ConfigScreenBuilder.CategoryBuilder gameplay = builder.getCategory("General Settings");
gameplay.addOption(new BooleanListEntry("Disable class requirements", SkillCheck.config.disableClasses, "text.cloth-config.reset_value", () -> false, null));
gameplay.addOption(new BooleanListEntry("Invert slippery tag", SkillCheck.config.invertSlipperyTag, "text.cloth-config.reset_value", () -> false, null));
gameplay.addOption(new BooleanListEntry("Show dice rolls in chat", SkillCheck.config.showDiceRolls, "text.cloth-config.reset_value", () -> false, null));
gameplay.addOption(new BooleanListEntry("Enable critical failures", SkillCheck.config.haveCriticalFailures, "text.cloth-config.reset_value", () -> true, null));
ConfigScreenBuilder.CategoryBuilder dice = builder.getCategory("Dice Roll Requirements");
dice.addOption(new IntegerSliderEntry("Arrow catch (1d20+thief)", 1, 26, SkillCheck.config.arrowCatchRoll, "text.cloth-config.reset_value", () -> 15, null));
dice.addOption(new IntegerSliderEntry("Armor theft (1d20+thief)", 1, 26, SkillCheck.config.stealArmorRoll, "text.cloth-config.reset_value", () -> 8, null));
dice.addOption(new IntegerSliderEntry("Silent armor theft (1d20+thief)", 1, 26, SkillCheck.config.silentStealArmorRoll, "text.cloth-config.reset_value", () -> 12, null));
dice.addOption(new IntegerSliderEntry("Enemy weaken (1d20+brawler)", 1, 31, SkillCheck.config.weakenEnemyRoll, "text.cloth-config.reset_value", () -> 12, null));
return builder.build();
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.cottonmc.skillworks;
package io.github.cottonmc.skillcheck;

import com.raphydaphy.crochet.data.PlayerData;
import net.minecraft.client.item.TooltipContext;
Expand All @@ -17,20 +17,20 @@

public class TraitPrestigeItem extends Item {
public TraitPrestigeItem() {
super(new Item.Settings().itemGroup(Skillworks.SKILLWORKS_GROUP));
super(new Item.Settings().itemGroup(SkillCheck.SKILLCHECK_GROUP));
}

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
PlayerData.get(player, Skillworks.MOD_ID).remove("Classes");
PlayerData.get(player, SkillCheck.MOD_ID).remove("Classes");
PlayerData.markDirty(player);
player.addChatMessage(new TranslatableTextComponent("msg.skillworks.prestige"), true);
player.addChatMessage(new TranslatableTextComponent("msg.skillcheck.prestige"), true);
return new TypedActionResult<>(ActionResult.SUCCESS, player.getStackInHand(hand));
}

@Override
public void buildTooltip(ItemStack stack, World world, List<TextComponent> tooltips, TooltipContext ctx) {
tooltips.add(new TranslatableTextComponent("tooltip.skillworks.prestige.0").applyFormat(TextFormat.GRAY));
tooltips.add(new TranslatableTextComponent("tooltip.skillworks.prestige.1").applyFormat(TextFormat.GRAY));
tooltips.add(new TranslatableTextComponent("tooltip.skillcheck.prestige.0").applyFormat(TextFormat.GRAY));
tooltips.add(new TranslatableTextComponent("tooltip.skillcheck.prestige.1").applyFormat(TextFormat.GRAY));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.cottonmc.skillworks.api.dice;
package io.github.cottonmc.skillcheck.api.dice;

import java.util.Random;
import java.util.regex.Matcher;
Expand All @@ -8,10 +8,18 @@ public class Dice {

public static final Pattern PATTERN = Pattern.compile("(?<count>\\d+)\\s*d(?<sides>\\d+)\\s*(?:\\+(?<bonus>\\d+(?!d)))?");

public static DiceResult roll(String formula) {
/**
* Roll a set of dice to
* @param formula A D&D-style dice-roll formula, ex. 1d20+8.
* Only about 50% implemented currently.
* Rolling multiple dice types at once and using modifiers other than adding are not supported.
* @see <a href="https://en.wikipedia.org/wiki/Dice_notation">Dice notation</a>
* @return a RollResult of what was calculated.
*/
public static RollResult roll(String formula) {
Random rand = new Random();
Matcher matcher = PATTERN.matcher(formula);
DiceResult res = new DiceResult();
RollResult res = new RollResult();
while (matcher.find()) {
int rolls = Integer.parseInt(matcher.group("count"));
if (rolls < 1) throw new IllegalArgumentException("Must roll at least one die!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package io.github.cottonmc.skillworks.api.dice;
package io.github.cottonmc.skillcheck.api.dice;

import io.github.cottonmc.skillworks.Skillworks;
import io.github.cottonmc.skillcheck.SkillCheck;

import java.util.ArrayList;
import java.util.List;

public class DiceResult {
/**
* The result of a dice roll.
* Stores the total sum of the rolls, the natural rolls, and whether there was any critical failure.
*/
public class RollResult {
private int total;
private List<Integer> naturals;
private boolean critFail;

public DiceResult() {
public RollResult() {
this(0, new ArrayList<>(), false);
}

public DiceResult(int total, List<Integer> naturals, boolean critFail) {
public RollResult(int total, List<Integer> naturals, boolean critFail) {
this.total = total;
this.naturals = naturals;
this.critFail = critFail;
Expand All @@ -37,7 +41,7 @@ public void addNatural(int amount) {
}

public boolean isCritFail() {
if (!Skillworks.config.haveCriticalFailures) return false;
if (!SkillCheck.config.haveCriticalFailures) return false;
return critFail;
}

Expand Down
Loading

0 comments on commit 550e45c

Please sign in to comment.