1.1.13
All checks were successful
SorceryCraft/pipeline/head This commit looks good

Update Mappings
Improve /spell command
This commit is contained in:
TheBrokenRail 2020-03-17 13:22:49 -04:00
parent db54bdf2ad
commit c592b9e9af
10 changed files with 89 additions and 34 deletions

4
API.md
View File

@ -7,7 +7,7 @@
maven { url 'https://jitpack.io' }
}
dependencies {
modImplementation 'com.thebrokenrail:sorcerycraft:VERSION'
modImplementation 'com.thebrokenrail:sorcerycraft:1.1.+'
}
```
2. Add Dependency to ```fabric.mod.json```
@ -54,7 +54,7 @@
}
}
```
4. Register the Spell in your ModInitializer
4. Register the spell in your ModInitializer
```java
public class ExampleMod implements ModInitializer {
public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class);

View File

@ -1,5 +1,9 @@
# Changelog
**1.1.13**
* Update Mappings
* Improve ```/spell``` command
**1.1.12**
* Update Mappings
* Add Config Screen

View File

@ -65,12 +65,18 @@ You can apply Spells to blank or existing spells in the Casting Table. Doing so
## ```/spell``` Command
This command requires OP permissions.
#### ```/spell clear <player>```
#### ```/spell forget <player>```
This command clears all known spells from the given player.
#### ```/spell forget <player> <spell-id>```
This command clears the specified spell from the given player.
#### ```/spell list <player>```
This lists all the spells the given player knows.
#### ```/spell discover <player>```
This adds all spells to the specified player's discovered spells list.
#### ```/spell discover <player> <spell-id> <level>```
This adds the specified spell to the specified player's discovered spells list.

View File

@ -6,11 +6,11 @@ org.gradle.jvmargs = -Xmx1G
minecraft_version = 20w11a
curseforge_id = 365308
simple_minecraft_version = 1.16-Snapshot
yarn_mappings = 20w11a+build.7
yarn_mappings = 20w11a+build.11
fabric_loader_version = 0.7.8+build.187
# Mod Properties
mod_version = 1.1.12
mod_version = 1.1.13
maven_group = com.thebrokenrail
archives_base_name = sorcerycraft

View File

@ -47,7 +47,7 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
client.getTextureManager().bindTexture(TEXTURE);
int i = (width - backgroundWidth) / 2;
int j = (height - backgroundHeight) / 2;
blit(i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512);
drawTexture(i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512);
}
@Override
@ -81,9 +81,9 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
if (k > 0) {
int modifier = (int) (((float) indexStartOffset / k) * (1 + 139 - 27));
blit(i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
drawTexture(i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
} else {
blit(i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
drawTexture(i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
}
}

View File

@ -4,6 +4,8 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import net.minecraft.command.arguments.EntityArgumentType;
@ -11,6 +13,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Texts;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
@ -28,29 +31,53 @@ public class SpellCommand {
.then(CommandManager.argument("player", EntityArgumentType.player())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName()), false);
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
ctx.getSource().sendFeedback(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue(), true).formatted(Formatting.YELLOW), false);
}
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellTag.getTranslatedSpell(spell.getKey(), spell.getValue(), true))), false);
return 0;
})
)
)
.then(CommandManager.literal("clear")
.then(CommandManager.literal("forget")
.then(CommandManager.argument("player", EntityArgumentType.player())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellTag.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true);
}
spellPlayer.setDiscoveredSpells(new HashMap<>());
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.cleared_spells", player.getDisplayName()), true);
return 1;
})
.then(CommandManager.argument("spell", SpellArgumentType.spell())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
if (spells.containsKey(spell)) {
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellTag.getTranslatedSpellChat(spell, spells.get(spell))), true);
spells.remove(spell);
}
spellPlayer.setDiscoveredSpells(spells);
return 1;
})
)
)
)
.then(CommandManager.literal("discover")
.then(CommandManager.argument("player", EntityArgumentType.player())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
Map<Identifier, Integer> spellMap = new HashMap<>();
Spell[] maxSpells = SpellRegistry.getMaxSpells();
for (Spell spell : maxSpells) {
spellMap.put(spell.getID(), spell.getLevel());
}
SpellTag.learnSpells(player, spellMap);
return 1;
})
.then(CommandManager.argument("spell", SpellArgumentType.spell())
.then(CommandManager.argument("level", IntegerArgumentType.integer())
.executes(ctx -> {
@ -85,7 +112,7 @@ public class SpellCommand {
spellMap.put(spell, level);
SpellTag.setSpells(stack, spellMap);
ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.spell.applied_spell", SpellTag.getTranslatedSpell(spell, level, true)), true);
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellTag.getTranslatedSpell(spell, level, true)), true);
return 1;
})
)
@ -106,10 +133,12 @@ public class SpellCommand {
}
Map<Identifier, Integer> spellMap = SpellTag.getSpells(stack);
spellMap.remove(spell);
if (spellMap.containsKey(spell)) {
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellTag.getTranslatedSpell(spell, spellMap.get(spell), true)), true);
spellMap.remove(spell);
}
SpellTag.setSpells(stack, spellMap);
ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.spell.removed_spell", SpellTag.getTranslatedSpell(spell, 0, false)), true);
return 1;
})
)

View File

@ -16,7 +16,7 @@ public abstract class Spell {
}
/**
* Get the ID of this Spell
* Get the ID of this spell
* @return The Spell ID
*/
public Identifier getID() {
@ -24,18 +24,18 @@ public abstract class Spell {
}
/**
* Get the level of this Spell
* @return The Spell Level
* Get the level of this spell
* @return The Spell's Level
*/
public int getLevel() {
return level;
}
/**
* Execute this Spell on an Entity
* Execute this spell on an Entity
* @param world World
* @param source A SpellEntity
* @param attacker The Entity that cast this Spell
* @param attacker The Entity that cast this spell
* @param target The Target
*/
public void execute(World world, Entity source, Entity attacker, Entity target) {
@ -43,10 +43,10 @@ public abstract class Spell {
}
/**
* Cast this Spell on a block
* Execute this spell on a block
* @param world World
* @param source A SpellEntity
* @param attacker The Entity that cast this Spell
* @param attacker The Entity that cast this spell
* @param hitResult The block's HitResult
*/
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
@ -54,20 +54,20 @@ public abstract class Spell {
}
/**
* Get the amount of levels required to make this Spell in a Casting Table
* Get the amount of levels required to make this spell in a Casting Table
* @return The XP cost
*/
public abstract int getXPCost();
/**
* Get the item(s) required to make ExampleSpell in a Casting Table, or ItemStack.EMPTY if an item is not required
* Get the item(s) required to make this spell in a Casting Table, or ItemStack.EMPTY if an item is not required
* @return The item cost
*/
public abstract ItemStack getItemCost();
/**
* Get the maximum level of this Spell
* @return The Max Level
* Get the maximum level of this spell
* @return The Spell's Max Level
*/
public abstract int getMaxLevel();
}

View File

@ -53,6 +53,18 @@ public class SpellRegistry {
return out.toArray(new Spell[0]);
}
public static Spell[] getMaxSpells() {
List<Spell> out = new ArrayList<>();
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
int maxLevel = getMaxLevel(entry.getKey());
if (maxLevel == -1) {
continue;
}
out.add(getSpell(entry.getKey(), maxLevel - 1));
}
return out.toArray(new Spell[0]);
}
/**
* Register a Spell
* @param id The Spell ID

View File

@ -91,6 +91,10 @@ public class SpellTag {
return text;
}
public static Text getTranslatedSpellChat(Identifier id, int level) {
return new LiteralText("[").append(SpellTag.getTranslatedSpell(id, level, true).getString()).append("]").formatted(Formatting.GREEN);
}
public static void learnSpells(PlayerEntity player, Map<Identifier, Integer> itemSpells) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
World world = player.getEntityWorld();
@ -111,8 +115,8 @@ public class SpellTag {
playerSpells.put(spell.getID(), spell.getLevel());
assert world.getServer() != null;
Text text = new LiteralText("[").append(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel(), true).getString()).append("]").formatted(Formatting.GREEN);
world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".new_spell", player.getDisplayName(), text));
Text text = getTranslatedSpellChat(spell.getID(), spell.getLevel());
world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".discovered_spell", player.getDisplayName(), text));
}
}
}

View File

@ -4,10 +4,10 @@
"itemGroup.sorcerycraft.spells": "SorceryCraft",
"container.sorcerycraft.casting_table": "Casting Table",
"container.sorcerycraft.spells": "Spells",
"chat.sorcerycraft.new_spell": "%s has discovered the spell %s",
"chat.sorcerycraft.discovered_spell": "%s has discovered the spell %s",
"entity.sorcerycraft.spell": "Spell",
"command.sorcerycraft.spell.cleared_spells": "All discovered spells cleared from %s",
"command.sorcerycraft.spell.listing_spells": "%s has discovered the following spells:",
"command.sorcerycraft.spell.forgotten_spell": "%s has forgotten the spell %s",
"command.sorcerycraft.spell.listing_spells": "%s has discovered the following spells: %s",
"command.sorcerycraft.spell.unknown_spell": "Unknown spell: %s",
"command.sorcerycraft.spell.not_holding_spell": "%s is not holding a spell",
"command.sorcerycraft.spell.applied_spell": "Applied Spell %s",