Compare commits

...

38 Commits

Author SHA1 Message Date
TheBrokenRail 5381263113 Auto-Publish
SorceryCraft/pipeline/head This commit looks good Details
2020-12-15 14:04:06 -05:00
TheBrokenRail 263466eed3 1.16.4
SorceryCraft/pipeline/head This commit looks good Details
2020-12-15 14:00:42 -05:00
TheBrokenRail 10bfbdb53d Update Loom
SorceryCraft/pipeline/head This commit looks good Details
2020-06-24 18:09:42 -04:00
TheBrokenRail 162df5c962 Port To 1.16.1
SorceryCraft/pipeline/head This commit looks good Details
2020-06-24 11:43:53 -04:00
TheBrokenRail 3f06723a1f 1.2.9
SorceryCraft/pipeline/head This commit looks good Details
Fix Dedicated Server Crash
2020-05-24 16:55:23 -04:00
TheBrokenRail 700b970a04 Fix Config
SorceryCraft/pipeline/head This commit looks good Details
2020-05-02 15:21:29 -04:00
TheBrokenRail 3bfe235d97 Fix HTML Publish
SorceryCraft/pipeline/head This commit looks good Details
2020-05-02 14:54:43 -04:00
TheBrokenRail 48fef73096 20w18a
SorceryCraft/pipeline/head There was a failure building this commit Details
2020-05-02 14:42:16 -04:00
TheBrokenRail 504a52597d 1.2.8
SorceryCraft/pipeline/head This commit looks good Details
Register Loot Table Function
2020-04-11 13:49:08 -04:00
TheBrokenRail 55808ca049 Fix Gradle
SorceryCraft/pipeline/head This commit looks good Details
2020-04-03 11:47:55 -04:00
TheBrokenRail e5aa71f751 20w14a
SorceryCraft/pipeline/head This commit looks good Details
2020-04-03 11:45:44 -04:00
TheBrokenRail 0664de5de5 Use @Unique
SorceryCraft/pipeline/head This commit looks good Details
2020-03-27 14:07:47 -04:00
TheBrokenRail 4d0e4b6411 20w13b
SorceryCraft/pipeline/head This commit looks good Details
2020-03-26 11:48:22 -04:00
TheBrokenRail 114c3a03d2 1.2.7
SorceryCraft/pipeline/head This commit looks good Details
Fix Cooling Spell Bug
2020-03-25 16:19:41 -04:00
TheBrokenRail 6b3445e1f6 Update Fabric API
SorceryCraft/pipeline/head This commit looks good Details
2020-03-25 15:04:33 -04:00
TheBrokenRail 14f254af3d Update Cloth Config
SorceryCraft/pipeline/head This commit looks good Details
2020-03-25 14:02:03 -04:00
TheBrokenRail 8a23afeed0 20w13a
SorceryCraft/pipeline/head This commit looks good Details
2020-03-25 13:58:00 -04:00
TheBrokenRail 8ca4986714 1.2.6
SorceryCraft/pipeline/head This commit looks good Details
Fix Potential Client-Server De-sync Bug
2020-03-24 15:31:35 -04:00
TheBrokenRail fb3ba1411f Remove Unused Import
SorceryCraft/pipeline/head This commit looks good Details
2020-03-24 13:12:12 -04:00
TheBrokenRail 3b91e3daf8 1.2.5
SorceryCraft/pipeline/head This commit looks good Details
Fix Casting Table Bug
2020-03-24 13:05:03 -04:00
TheBrokenRail acf08c7fa6 1.2.4
SorceryCraft/pipeline/head This commit looks good Details
Optimize Packets
Allow Command Blocks to use ```/spell``` Command
Namespace Statistics
2020-03-24 09:38:29 -04:00
TheBrokenRail 5552fe5cd8 Optimize Packets
Allow Command Blocks to use /spell Command
2020-03-24 09:35:42 -04:00
TheBrokenRail d381beff16 Namespace Statistics
SorceryCraft/pipeline/head This commit looks good Details
2020-03-23 15:13:17 -04:00
TheBrokenRail ff50bd3851 Update CurseForge Script
SorceryCraft/pipeline/head This commit looks good Details
2020-03-22 15:48:13 -04:00
TheBrokenRail 76f316f7bd 1.2.3
SorceryCraft/pipeline/head This commit looks good Details
Tweak Cooling Spell
Tweak Versioning
2020-03-22 15:30:46 -04:00
TheBrokenRail df3c1dcffd Add Annotations
SorceryCraft/pipeline/head This commit looks good Details
2020-03-21 15:30:05 -04:00
TheBrokenRail d2d33c6159 1.2.2
SorceryCraft/pipeline/head This commit looks good Details
Allow /spell command to work with multiple players
2020-03-21 13:25:28 -04:00
TheBrokenRail f40e44e366 1.2.1
SorceryCraft/pipeline/head This commit looks good Details
Fix Launching Without ModMenu
2020-03-21 11:49:58 -04:00
TheBrokenRail 4ebae792ac 1.2
SorceryCraft/pipeline/head This commit looks good Details
Update API (More Consistent Package Names)
Fix Bug When Casting Spell
2020-03-20 22:05:52 -04:00
TheBrokenRail 3fe89d2d95 1.1.21
SorceryCraft/pipeline/head This commit looks good Details
Update Mappings
Tweak Teleport and Flame Spells
2020-03-19 23:06:38 -04:00
TheBrokenRail b44ca31175 1.1.20
SorceryCraft/pipeline/head This commit looks good Details
Update to 20w12a
2020-03-18 17:21:39 -04:00
TheBrokenRail 9d1cad6223 1.1.19
SorceryCraft/pipeline/head This commit looks good Details
Update API Docs
Allow Setting Custom Display name for Spell
2020-03-18 11:56:25 -04:00
TheBrokenRail 373f0ad8d3 1.1.18
SorceryCraft/pipeline/head This commit looks good Details
Fix Crash When Using Dedicated Server
2020-03-17 21:30:59 -04:00
TheBrokenRail 1c033d5a0d 1.1.17
SorceryCraft/pipeline/head This commit looks good Details
Update Mappings
Add Spell-related Advancements
2020-03-17 20:42:02 -04:00
TheBrokenRail 1dbbd55376 Add JavaDoc Link
SorceryCraft/pipeline/head This commit looks good Details
2020-03-17 14:34:42 -04:00
TheBrokenRail 019c588add 1.1.16
SorceryCraft/pipeline/head This commit looks good Details
Consistent Gradle Project Name
2020-03-17 14:25:35 -04:00
TheBrokenRail 5e24602ca8 1.1.15
SorceryCraft/pipeline/head This commit looks good Details
Build JavaDoc Jar
2020-03-17 14:08:55 -04:00
TheBrokenRail ee78088250 1.1.14
SorceryCraft/pipeline/head This commit looks good Details
Update Config Lang
2020-03-17 13:36:53 -04:00
45 changed files with 962 additions and 307 deletions

4
.gitignore vendored
View File

@ -22,4 +22,6 @@ bin/
# fabric
run/
run/
remappedSrc/

69
API.md
View File

@ -4,17 +4,18 @@
1. Add Dependency to Gradle
```gradle
repositories {
maven { url 'https://jitpack.io' }
maven { url 'https://maven.thebrokenrail.com' }
}
dependencies {
modImplementation 'com.thebrokenrail:sorcerycraft:1.1.+'
modImplementation 'com.thebrokenrail:sorcerycraft:VERSION'
// VERSION = "<Mod Version>+<MC Version>", for example "1.2.4+20w12a"
}
```
2. Add Dependency to ```fabric.mod.json```
```json
{
"depends": {
"sorcerycraft": "1.1.x"
"sorcerycraft": "1.2.x"
}
}
```
@ -24,33 +25,65 @@
public ExampleSpell(Identifier id, int level) {
super(id, level);
}
@Override
public void execute(Entity target, Entity source, Entity attacker) {
// OPTIONAL
// Called when ExampleSpell hits an entity
// Not required to override
// Override this if you want the spell to affect entities
}
@Override
public void execute(World world, BlockHitResult hitResult) {
// OPTIONAL
// Called when ExampleSpell hits a block
// Not required to override
// Override this if you want the spell to affect blocks
}
@Override
public int getXPCost() {
// REQUIRED
// Return the amount of levels required to make ExampleSpell in a Casting Table
switch (getLevel()) {
case 0: {
return 4;
}
case 1: {
return 8;
}
}
return -1;
}
@Override
public ItemStack getItemCost() {
// REQUIRED
// Return the item(s) required to make ExampleSpell in a Casting Table
// Return ItemStack.EMPTY if an item is not required
switch (getLevel()) {
case 0: {
return new ItemStack(Items.SUGAR_CANE);
}
case 1: {
return new ItemStack(Items.BOOK);
}
}
return ItemStack.EMPTY;
}
@Override
public int getMaxLevel() {
// REQUIRED
// Return ExampleSpell's maximum level
return 2;
}
@Override
public Text getTranslation() {
// OPTIONAL
// Return a custom display name for ExampleSpell
// Override this only if you want a custom display name
return new LiteralText("Example " + (getLevel() + 1));
}
}
```
@ -60,7 +93,7 @@
public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class);
}
```
5. Add Spell Translation
5. Add Spell Translation (skip this if you have overridden ```Spell.getTranslation()``)
```json
{
"spell.modid.example_spell": "Example"
@ -68,5 +101,15 @@
```
## Useful Methods
- ```Spell.getLevel()```
- ```Spell.getID()```
- ```(non-static) Spell.getLevel()```
- ```(non-static) Spell.getID()```
- ```(static) SpellRegistry.register()```
## API Stability
APIs are only guaranteed to be stable in the ```com.thebrokenrail.sorcerycraft.api``` package, it is unrecommended to rely on any SorceryCraft classes outside of this package.
## Spell Levels
Spell levels are 0-indexed, if you have a level 1 Example Spell, ```Spell.getLevel()``` wil return 0, and if it is level 2 ```Spell.getLevel()``` wil return 1, ```Spell.getMaxSpell()``` should be the maximum-acceptable value of ```Spell.getLevel() + 1```, so if Example Spell has levels 1-2, ```Spell.getMaxLevel()``` should return 2.
## JavaDoc
[View JavaDoc](https://jenkins.thebrokenrail.com/job/SorceryCraft/job/master/JavaDoc/)

View File

@ -1,5 +1,67 @@
# Changelog
**1.2.9**
* Fix Dedicated Server Crash
**1.2.8**
* Register Loot Table Function
**1.2.7**
* Fix Cooling Spell Bug
**1.2.6**
* Fix Potential Client-Server De-sync Bug
**1.2.5**
* Fix Casting Table Bug
**1.2.4**
* Optimize Packets
* Allow Command Blocks to use ```/spell``` Command
* Namespace Statistics
**1.2.3**
* Tweak Cooling Spell
* Tweak Versioning
**1.2.2**
* Allow ```/spell``` command to work with multiple players
**1.2.1**
* Fix Launching Without ModMenu
**1.2**
* Update Mappings
* Update API (More Consistent Package Names)
* Fix Bug When Casting Spell
**1.1.21**
* Update Mappings
* Tweak Teleport and Flame Spells
**1.1.20**
* Update to 20w12a
**1.1.19**
* Update API Docs
* Allow Setting Custom Display name for Spell
**1.1.18**
* Fix Crash When Using Dedicated Server
**1.1.17**
* Update Mappings
* Add Spell-related Advancements
**1.1.16**
* Consistent Gradle Project Name
**1.1.15**
* Build JavaDoc Jar
**1.1.14**
* Update Config Lang
**1.1.13**
* Update Mappings
* Improve ```/spell``` command

23
Jenkinsfile vendored
View File

@ -7,11 +7,32 @@ pipeline {
stages {
stage('Build') {
steps {
sh './gradlew build'
sh './gradlew build javadoc'
}
post {
success {
archiveArtifacts artifacts: 'build/libs/*', fingerprint: true
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: false,
reportDir: 'build/docs/javadoc',
reportFiles: 'index.html',
reportName: 'JavaDoc'
]
}
}
}
stage('Publish') {
when {
expression {
return sh(returnStdout: true, script: 'git tag --contains').trim().length() > 0
}
}
steps {
withCredentials([string(credentialsId: 'curseforge_key', variable: 'CURSEFORGE_KEY')]) {
sh './gradlew -Pcurseforge.api_key="${CURSEFORGE_KEY}" curseforge publish'
}
}
}

View File

@ -57,7 +57,7 @@ You can apply Spells to blank or existing spells in the Casting Table. Doing so
| Dissolve | 1 | Removes target's status effects. |
| Levitate | 2 | Gives target the Levitation effect. |
| Steadfast | 1 | Prevents the spell from failing. This spell does nothing on its own. |
| Teleport | 2 | Teleports the target to a random location. |
| Teleport | 3 | Teleports the target to a random location. |
| Inward | 1 | Causes the spell to target the caster. If the spell fails instead of rebounding, it will just do nothing. This spell does nothing on its own. |
| Cooling | 1 | Extinguish the target if they are on fire. |
| Lightning | 1 | Strikes the target with lightning. |

View File

@ -1,6 +1,7 @@
plugins {
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'maven-publish'
}
compileJava {
@ -9,7 +10,8 @@ compileJava {
}
archivesBaseName = project.archives_base_name
version = project.mod_version as Object
def mod_version = project.mod_version as Object
version = "${mod_version}+${project.minecraft_version}"
group = project.maven_group as Object
minecraft {
@ -24,7 +26,7 @@ repositories {
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
@ -36,11 +38,12 @@ dependencies {
}
processResources {
inputs.property 'version', version
inputs.property 'version', project.version
inputs.property 'name', rootProject.name
from(sourceSets.main.resources.srcDirs) {
include 'fabric.mod.json'
expand 'version': version
expand 'version': project.version, 'name': rootProject.name
}
from(sourceSets.main.resources.srcDirs) {
@ -63,10 +66,37 @@ task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
jar {
from "LICENSE"
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId archivesBaseName
artifact(remapJar) {
builtBy remapJar
}
}
}
repositories {
maven {
url '/data/maven'
}
}
}
if (project.hasProperty('curseforge.api_key')) {
curseforge {
apiKey = project.getProperty('curseforge.api_key')
@ -77,7 +107,7 @@ if (project.hasProperty('curseforge.api_key')) {
addGameVersion project.simple_minecraft_version
addGameVersion 'Fabric'
mainArtifact(remapJar) {
displayName = "SorceryCraft v${version} for ${project.minecraft_version}"
displayName = "SorceryCraft v${mod_version} for ${project.minecraft_version}"
}
afterEvaluate {
uploadTask.dependsOn('remapJar')

View File

@ -3,20 +3,20 @@ org.gradle.jvmargs = -Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version = 20w11a
minecraft_version = 1.16.4
curseforge_id = 365308
simple_minecraft_version = 1.16-Snapshot
yarn_mappings = 20w11a+build.11
fabric_loader_version = 0.7.8+build.187
simple_minecraft_version = 1.16.4
yarn_build = 7
fabric_loader_version = 0.10.8
# Mod Properties
mod_version = 1.1.13
mod_version = 1.2.9
maven_group = com.thebrokenrail
archives_base_name = sorcerycraft
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_api_version = 0.5.3+build.308-1.16
cloth_config_version = 3.0.2-unstable.202003090708
auto_config_version = 1.2.4
mod_menu_version = 1.10.2+build.1
fabric_api_version = 0.28.1+1.16
cloth_config_version = 4.8.3
auto_config_version = 3.3.1
mod_menu_version = 1.14.13+build.19

View File

@ -8,3 +8,5 @@ pluginManagement {
gradlePluginPortal()
}
}
rootProject.name = 'SorceryCraft'

View File

@ -13,7 +13,7 @@ import java.lang.annotation.Target;
public class ModConfig implements ConfigData {
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
@interface UsePercentage {
public @interface UsePercentage {
double min();
double max();

View File

@ -1,41 +1,32 @@
package com.thebrokenrail.sorcerycraft;
import com.thebrokenrail.sorcerycraft.advancement.CreateSpellCriterion;
import com.thebrokenrail.sorcerycraft.advancement.DiscoverAllSpellsCriterion;
import com.thebrokenrail.sorcerycraft.block.CastingTableBlock;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen;
import com.thebrokenrail.sorcerycraft.client.entity.SpellEntityRenderer;
import com.thebrokenrail.sorcerycraft.command.SpellCommand;
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
import com.thebrokenrail.sorcerycraft.item.SpellItem;
import com.thebrokenrail.sorcerycraft.mixin.CriteriaRegistryHook;
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
import com.thebrokenrail.sorcerycraft.spell.util.RandomSpellLootTableFunction;
import com.thebrokenrail.sorcerycraft.spell.registry.Spells;
import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.gui.registry.GuiRegistry;
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
import me.sargunvohra.mcmods.autoconfig1u.util.Utils;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl;
import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.ProjectileDispenserBehavior;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.Projectile;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
@ -43,30 +34,33 @@ import net.minecraft.item.ItemStack;
import net.minecraft.loot.BinomialLootTableRange;
import net.minecraft.loot.LootTables;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.LootFunctionType;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.StatFormatter;
import net.minecraft.stat.Stats;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Position;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.Collections;
import java.util.Objects;
public class SorceryCraft implements ModInitializer, ClientModInitializer {
public class SorceryCraft implements ModInitializer {
public static final String NAMESPACE = "sorcerycraft";
public static SpellItem SPELL_ITEM;
public static CastingTableBlock CASTING_TABLE_BLOCK;
public static BlockItem CASTING_TABLE_BLOCK_ITEM;
public static ItemGroup ITEM_GROUP;
public static EntityType<SpellEntity> SPELL_ENTITY;
public static final Identifier[] LOOT_TABLES = new Identifier[]{
LootTables.SIMPLE_DUNGEON_CHEST,
LootTables.END_CITY_TREASURE_CHEST,
@ -77,10 +71,16 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
LootTables.JUNGLE_TEMPLE_CHEST,
LootTables.STRONGHOLD_LIBRARY_CHEST,
LootTables.PILLAGER_OUTPOST_CHEST,
LootTables.WOODLAND_MANSION_CHEST
LootTables.WOODLAND_MANSION_CHEST,
LootTables.BURIED_TREASURE_CHEST,
LootTables.FISHING_TREASURE_GAMEPLAY
};
public static Identifier STAT_INTERACT_WITH_CASTING_TABLE;
public static Identifier STAT_CAST_SPELL;
public static Identifier INTERACT_WITH_CASTING_TABLE_STAT;
public static Identifier CAST_SPELL_STAT;
public static DiscoverAllSpellsCriterion DISCOVER_ALL_SPELLS_CRITERION;
public static CreateSpellCriterion CREATE_SPELL_CRITERION;
public static ModConfig getConfig() {
return AutoConfig.getConfigHolder(ModConfig.class).getConfig();
@ -97,14 +97,10 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
@Override
public void onInitialize() {
//noinspection InstantiationOfUtilityClass
new Spells();
AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ModConfig.class);
guiRegistry.registerAnnotationProvider((s, field, config, defaults, guiRegistryAccess) -> {
ModConfig.UsePercentage bounds = field.getAnnotation(ModConfig.UsePercentage.class);
return Collections.singletonList(ConfigEntryBuilder.create().startIntSlider(s, MathHelper.ceil(Utils.getUnsafely(field, config, 0.0) * 100), MathHelper.ceil(bounds.min() * 100), MathHelper.ceil(bounds.max() * 100)).setDefaultValue(() -> MathHelper.ceil((double) Utils.getUnsafely(field, defaults) * 100)).setSaveConsumer((newValue) -> Utils.setUnsafely(field, config, newValue / 100d)).setTextGetter(integer -> String.format("%d%%", integer)).build());
}, field -> field.getType() == Double.TYPE || field.getType() == Double.class, ModConfig.UsePercentage.class);
ITEM_GROUP = FabricItemGroupBuilder.create(
new Identifier(NAMESPACE, "spells"))
@ -115,7 +111,7 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
CASTING_TABLE_BLOCK_ITEM = new BlockItem(CASTING_TABLE_BLOCK, new Item.Settings().group(ITEM_GROUP));
SPELL_ITEM = new SpellItem();
SPELL_ENTITY = FabricEntityTypeBuilder.create(EntityCategory.MISC, (EntityType.EntityFactory<SpellEntity>) SpellEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build();
SPELL_ENTITY = FabricEntityTypeBuilder.create(SpawnGroup.MISC, (EntityType.EntityFactory<SpellEntity>) SpellEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build();
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "spell"), SPELL_ITEM);
Registry.register(Registry.BLOCK, new Identifier(NAMESPACE, "casting_table"), CASTING_TABLE_BLOCK);
@ -131,22 +127,22 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
CommandRegistry.INSTANCE.register(false, SpellCommand::register);
ServerSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "select_spell"), SelectSpellC2SPacket::handle);
ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "update_known_spells"), UpdateKnownSpellsS2CPacket::handle);
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (isSelectedLootTable(id)) {
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
.withRolls(new BinomialLootTableRange(2, 0.5f))
.withEntry(ItemEntry.builder(SPELL_ITEM))
.withFunction(new RandomSpellLootTableFunction.Builder());
.rolls(new BinomialLootTableRange(2, 0.5f))
.withEntry(ItemEntry.builder(SPELL_ITEM).build())
.withFunction(new RandomSpellLootTableFunction.Builder().build());
supplier.withPool(poolBuilder);
supplier.withPool(poolBuilder.build());
}
});
Registry.register(Registry.LOOT_FUNCTION_TYPE, new Identifier(NAMESPACE, "random_spell"), new LootFunctionType(new RandomSpellLootTableFunction.Factory()));
DispenserBlock.registerBehavior(SorceryCraft.SPELL_ITEM, new ProjectileDispenserBehavior() {
@Override
protected Projectile createProjectile(World position, Position stack, ItemStack itemStack) {
protected ProjectileEntity createProjectile(World position, Position stack, ItemStack itemStack) {
SpellEntity entity = new SpellEntity(position, stack.getX(), stack.getY(), stack.getZ());
entity.setItem(itemStack);
return entity;
@ -158,13 +154,16 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
}
});
STAT_INTERACT_WITH_CASTING_TABLE = registerStat("interact_with_casting_table");
STAT_CAST_SPELL = registerStat("cast_spell");
INTERACT_WITH_CASTING_TABLE_STAT = registerStat("interact_with_casting_table");
CAST_SPELL_STAT = registerStat("cast_spell");
DISCOVER_ALL_SPELLS_CRITERION = CriteriaRegistryHook.callRegister(new DiscoverAllSpellsCriterion());
CREATE_SPELL_CRITERION = CriteriaRegistryHook.callRegister(new CreateSpellCriterion());
}
private Identifier registerStat(String name) {
Identifier statID = new Identifier(NAMESPACE, name);
Registry.register(Registry.CUSTOM_STAT, name, statID);
Registry.register(Registry.CUSTOM_STAT, statID, statID);
Stats.CUSTOM.getOrCreateStat(statID, StatFormatter.DEFAULT);
return statID;
}
@ -182,13 +181,4 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
public static void playSpellSound(PlayerEntity player) {
player.playSound(SPELL_SOUND_EFFECT, SoundCategory.PLAYERS, 1.0f, 1.0f);
}
@Override
public void onInitializeClient() {
EntityRendererRegistry.INSTANCE.register(SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher));
ScreenProviderRegistry.INSTANCE.<CastingTableScreenHandler>registerFactory(new Identifier(NAMESPACE, "casting_table"), (container) -> {
assert MinecraftClient.getInstance().player != null;
return new CastingTableScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText("block." + SorceryCraft.NAMESPACE + ".casting_table"));
});
}
}

View File

@ -0,0 +1,37 @@
package com.thebrokenrail.sorcerycraft.advancement;
import com.google.gson.JsonObject;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class CreateSpellCriterion extends AbstractCriterion<CreateSpellCriterion.Conditions> {
private static final Identifier ID = new Identifier(SorceryCraft.NAMESPACE, "create_spell");
public CreateSpellCriterion() {
}
@Override
protected Conditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new CreateSpellCriterion.Conditions(playerPredicate);
}
@Override
public Identifier getId() {
return ID;
}
public void trigger(ServerPlayerEntity player) {
test(player, (conditions) -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions(EntityPredicate.Extended player) {
super(ID, player);
}
}
}

View File

@ -0,0 +1,54 @@
package com.thebrokenrail.sorcerycraft.advancement;
import com.google.gson.JsonObject;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import java.util.Map;
public class DiscoverAllSpellsCriterion extends AbstractCriterion<DiscoverAllSpellsCriterion.Conditions> {
private static final Identifier ID = new Identifier(SorceryCraft.NAMESPACE, "discover_all_spells");
public DiscoverAllSpellsCriterion() {
}
@Override
public Identifier getId() {
return ID;
}
@Override
protected DiscoverAllSpellsCriterion.Conditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new DiscoverAllSpellsCriterion.Conditions(playerPredicate);
}
public void trigger(ServerPlayerEntity player) {
test(player, (conditions) -> {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
Spell[] maxSpells = SpellRegistry.getMaxSpells();
boolean match = true;
for (Spell spell : maxSpells) {
if (!spells.containsKey(spell.getID()) || spells.get(spell.getID()) < (spell.getLevel() - 1)) {
match = false;
break;
}
}
return match;
});
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions(EntityPredicate.Extended player) {
super(ID, player);
}
}
}

View File

@ -2,6 +2,7 @@ package com.thebrokenrail.sorcerycraft.block;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.spell.util.SpellServerPlayerEntity;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.block.Block;
@ -29,13 +30,18 @@ public class CastingTableBlock extends Block {
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient()) {
ContainerProviderRegistry.INSTANCE.openContainer(new Identifier(SorceryCraft.NAMESPACE, "casting_table"), player, (buf) -> buf.writeBlockPos(pos));
player.incrementStat(SorceryCraft.STAT_INTERACT_WITH_CASTING_TABLE);
player.incrementStat(SorceryCraft.INTERACT_WITH_CASTING_TABLE_STAT);
}
return ActionResult.SUCCESS;
}
@Override
public NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) {
return new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> new CastingTableScreenHandler(i, playerInventory, ScreenHandlerContext.create(world, pos)), new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table"));
return new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> {
if (!playerEntity.getEntityWorld().isClient()) {
((SpellServerPlayerEntity) playerEntity).sync();
}
return new CastingTableScreenHandler(i, playerInventory, ScreenHandlerContext.create(world, pos));
}, new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table"));
}
}

View File

@ -5,8 +5,12 @@ import com.thebrokenrail.sorcerycraft.SorceryCraft;
import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;
@SuppressWarnings("unused")
@Environment(EnvType.CLIENT)
public class ModMenu implements ModMenuApi {
@Override
public String getModId() {

View File

@ -0,0 +1,46 @@
package com.thebrokenrail.sorcerycraft.client;
import com.thebrokenrail.sorcerycraft.ModConfig;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.client.entity.SpellEntityRenderer;
import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.gui.registry.GuiRegistry;
import me.sargunvohra.mcmods.autoconfig1u.util.Utils;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import java.util.Collections;
@SuppressWarnings("unused")
@Environment(EnvType.CLIENT)
public class SorceryCraftClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ModConfig.class);
guiRegistry.registerAnnotationProvider((s, field, config, defaults, guiRegistryAccess) -> {
ModConfig.UsePercentage bounds = field.getAnnotation(ModConfig.UsePercentage.class);
return Collections.singletonList(ConfigEntryBuilder.create().startIntSlider(new TranslatableText(s), MathHelper.ceil(Utils.getUnsafely(field, config, 0.0) * 100), MathHelper.ceil(bounds.min() * 100), MathHelper.ceil(bounds.max() * 100)).setDefaultValue(() -> MathHelper.ceil((double) Utils.getUnsafely(field, defaults) * 100)).setSaveConsumer((newValue) -> Utils.setUnsafely(field, config, newValue / 100d)).setTextGetter(integer -> new LiteralText(String.format("%d%%", integer))).build());
}, field -> field.getType() == Double.TYPE || field.getType() == Double.class, ModConfig.UsePercentage.class);
EntityRendererRegistry.INSTANCE.register(SorceryCraft.SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher));
ScreenProviderRegistry.INSTANCE.<CastingTableScreenHandler>registerFactory(new Identifier(SorceryCraft.NAMESPACE, "casting_table"), (container) -> {
assert MinecraftClient.getInstance().player != null;
return new CastingTableScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText("block." + SorceryCraft.NAMESPACE + ".casting_table"));
});
ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(SorceryCraft.NAMESPACE, "update_known_spells"), UpdateKnownSpellsS2CPacket::handle);
}
}

View File

@ -5,14 +5,15 @@ import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
@ -21,9 +22,9 @@ import net.minecraft.util.math.MathHelper;
@Environment(EnvType.CLIENT)
public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler> {
private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png");
private int selectedIndex;
private int indexStartOffset;
private boolean scrolling;
private int selectedIndex = 0;
private int indexStartOffset = 0;
private boolean scrolling = false;
public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) {
super(container, inventory, title);
@ -31,47 +32,52 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
}
@Override
protected void drawForeground(int mouseX, int mouseY) {
protected void drawForeground(MatrixStack matrixStack, int i, int j) {
int titleY = backgroundHeight - 94;
textRenderer.draw(title.asFormattedString(), (float) (49 + this.backgroundWidth / 2 - textRenderer.getStringWidth(title.asFormattedString()) / 2), 6.0F, 4210752);
textRenderer.draw(playerInventory.getDisplayName().asFormattedString(), 107.0F, (float) titleY, 4210752);
String spells = new TranslatableText("container." + SorceryCraft.NAMESPACE + ".spells").getString();
textRenderer.draw(spells, (float) (5 - textRenderer.getStringWidth(spells) / 2 + 48), 6.0F, 4210752);
renderXPCost();
textRenderer.draw(matrixStack, title, (float) (49 + this.backgroundWidth / 2 - textRenderer.getWidth(title) / 2), 6.0F, 4210752);
textRenderer.draw(matrixStack, playerInventory.getDisplayName(), 107.0F, (float) titleY, 4210752);
Text spells = new TranslatableText("container." + SorceryCraft.NAMESPACE + ".spells");
textRenderer.draw(matrixStack, spells, (float) (5 - textRenderer.getWidth(spells) / 2 + 48), 6.0F, 4210752);
renderXPCost(matrixStack);
}
public void resetIndex() {
selectedIndex = 0;
indexStartOffset = 0;
}
@Override
protected void drawBackground(float delta, int mouseX, int mouseY) {
protected void drawBackground(MatrixStack matrixStack, float delta, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
assert client != null;
client.getTextureManager().bindTexture(TEXTURE);
int i = (width - backgroundWidth) / 2;
int j = (height - backgroundHeight) / 2;
drawTexture(i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512);
drawTexture(matrixStack, i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512);
}
@Override
public void render(int mouseX, int mouseY, float delta) {
renderBackground();
super.render(mouseX, mouseY, delta);
drawMouseoverTooltip(mouseX, mouseY);
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) {
renderBackground(matrixStack);
super.render(matrixStack, mouseX, mouseY, delta);
drawMouseoverTooltip(matrixStack, mouseX, mouseY);
renderScrollbar();
renderScrollbar(matrixStack);
renderItems();
for (WidgetButtonPage button : buttons) {
if (button.isHovered()) {
button.renderToolTip(mouseX, mouseY);
button.renderToolTip(matrixStack, mouseX, mouseY);
}
button.visible = button.index < handler.getRecipes().length;
if (button.visible) {
Spell spell = handler.getRecipes()[button.getIndex() + indexStartOffset];
button.setMessage(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel(), true).getString());
button.setMessage(SpellHelper.getTranslatedSpell(spell.getID(), spell.getLevel()));
}
}
}
private void renderScrollbar() {
private void renderScrollbar(MatrixStack matrixStack) {
Spell[] spells = handler.getRecipes();
assert client != null;
client.getTextureManager().bindTexture(TEXTURE);
@ -81,9 +87,9 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
if (k > 0) {
int modifier = (int) (((float) indexStartOffset / k) * (1 + 139 - 27));
drawTexture(i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
drawTexture(matrixStack, i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
} else {
drawTexture(i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
drawTexture(matrixStack, i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
}
}
@ -99,7 +105,7 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
itemRenderer.zOffset = 100.0F;
int y = k + 2;
itemRenderer.renderGuiItem(itemStack, i + 5 + 68, y);
itemRenderer.renderInGuiWithOverrides(itemStack, i + 5 + 68, y);
itemRenderer.renderGuiItemOverlay(textRenderer, itemStack, i + 5 + 68, y);
itemRenderer.zOffset = 0.0F;
k += 20;
@ -107,21 +113,21 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
}
}
private void renderXPCost() {
private void renderXPCost(MatrixStack matrixStack) {
if (handler.getRecipes().length > 0) {
int cost = handler.getRecipes()[selectedIndex].getXPCost();
int color = 8453920;
assert client != null;
assert client.player != null;
String string = new TranslatableText("container.repair.cost", cost).getString();
Text string = new TranslatableText("container.repair.cost", cost);
if (!handler.canTakeResult(playerInventory.player)) {
color = 16736352;
}
int x2 = backgroundWidth - 8;
int x1 = x2 - textRenderer.getStringWidth(string);
fill(x1, 65, x2, 77, 1325400064);
textRenderer.drawWithShadow(string, (float) x1, 67.0F, color);
int x1 = x2 - textRenderer.getWidth(string);
fill(matrixStack, x1, 65, x2, 77, 1325400064);
textRenderer.drawWithShadow(matrixStack, string, (float) x1, 67.0F, color);
}
}
@ -194,37 +200,32 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
}
@Environment(EnvType.CLIENT)
private class WidgetButtonPage extends ButtonWidget {
public class WidgetButtonPage extends ButtonWidget {
final int index;
public WidgetButtonPage(int i, int j, int k, PressAction pressAction) {
super(i, j, 89, 20, "", pressAction);
super(i, j, 89, 20, new LiteralText(""), pressAction);
index = k;
visible = false;
}
@Override
public void render(int mouseX, int mouseY, float delta) {
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) {
active = (index + CastingTableScreen.this.indexStartOffset) != CastingTableScreen.this.selectedIndex;
super.render(mouseX, mouseY, delta);
super.render(matrixStack, mouseX, mouseY, delta);
}
public int getIndex() {
return this.index;
}
public void renderToolTip(int mouseX, int mouseY) {
public void renderToolTip(MatrixStack matrixStack, int mouseX, int mouseY) {
if (hovered && handler.getRecipes().length > index + indexStartOffset && mouseX > this.x + 65) {
ItemStack itemStack = handler.getRecipes()[index + indexStartOffset].getItemCost();
if (!itemStack.isEmpty()) {
renderTooltip(itemStack, mouseX, mouseY);
renderTooltip(matrixStack, itemStack, mouseX, mouseY);
}
}
}
@Override
public void drawCenteredString(TextRenderer textRenderer, String str, int centerX, int y, int color) {
drawString(textRenderer, str, x + 5, y, color);
}
}
}

View File

@ -13,8 +13,8 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import net.minecraft.server.command.CommandSource;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import net.minecraft.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;

View File

@ -5,19 +5,20 @@ 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.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
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.server.network.ServerPlayerEntity;
import net.minecraft.text.Texts;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -26,120 +27,147 @@ public class SpellCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("spell")
.requires(source -> source.hasPermissionLevel(4))
.requires(source -> source.hasPermissionLevel(2))
.then(CommandManager.literal("list")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.argument("player", EntityArgumentType.players())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
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;
int i = 0;
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
for (PlayerEntity player : players) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellHelper.getTranslatedSpell(spell.getKey(), spell.getValue()))), false);
i++;
}
return i;
})
)
)
.then(CommandManager.literal("forget")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.argument("player", EntityArgumentType.players())
.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);
int i = 0;
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
for (PlayerEntity player : players) {
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(), SpellHelper.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true);
i++;
}
spellPlayer.setDiscoveredSpells(new HashMap<>());
}
spellPlayer.setDiscoveredSpells(new HashMap<>());
return 1;
return i;
})
.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);
int i = 0;
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
for (PlayerEntity player : players) {
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(), SpellHelper.getTranslatedSpellChat(spell, spells.get(spell))), true);
spells.remove(spell);
i++;
}
spellPlayer.setDiscoveredSpells(spells);
}
spellPlayer.setDiscoveredSpells(spells);
return 1;
return i;
})
)
)
)
.then(CommandManager.literal("discover")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.argument("player", EntityArgumentType.players())
.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());
int i = 0;
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
for (PlayerEntity player : players) {
Map<Identifier, Integer> spellMap = new HashMap<>();
Spell[] maxSpells = SpellRegistry.getMaxSpells();
for (Spell spell : maxSpells) {
spellMap.put(spell.getID(), spell.getLevel());
i++;
}
SpellHelper.learnSpells(player, spellMap);
}
SpellTag.learnSpells(player, spellMap);
return 1;
return i;
})
.then(CommandManager.argument("spell", SpellArgumentType.spell())
.then(CommandManager.argument("level", IntegerArgumentType.integer())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
Map<Identifier, Integer> spellMap = new HashMap<>();
spellMap.put(spell, level);
SpellTag.learnSpells(player, spellMap);
return 1;
int i = 0;
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
for (PlayerEntity player : players) {
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
Map<Identifier, Integer> spellMap = new HashMap<>();
spellMap.put(spell, level);
i++;
SpellHelper.learnSpells(player, spellMap);
}
return i;
})
)
)
)
)
.then(CommandManager.literal("apply")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.argument("player", EntityArgumentType.players())
.then(CommandManager.argument("spell", SpellArgumentType.spell())
.then(CommandManager.argument("level", IntegerArgumentType.integer())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
int i = 0;
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
for (PlayerEntity player : players) {
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
ItemStack stack = player.getMainHandStack();
ItemStack stack = player.getMainHandStack();
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
}
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
spellMap.put(spell, level);
i++;
SpellHelper.setSpells(stack, spellMap);
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellHelper.getTranslatedSpell(spell, level)), true);
}
Map<Identifier, Integer> spellMap = SpellTag.getSpells(stack);
spellMap.put(spell, level);
SpellTag.setSpells(stack, spellMap);
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellTag.getTranslatedSpell(spell, level, true)), true);
return 1;
return i;
})
)
)
)
)
.then(CommandManager.literal("remove")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.argument("player", EntityArgumentType.players())
.then(CommandManager.argument("spell", SpellArgumentType.spell())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
int i = 0;
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
for (PlayerEntity player : players) {
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
ItemStack stack = player.getMainHandStack();
ItemStack stack = player.getMainHandStack();
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
}
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
if (spellMap.containsKey(spell)) {
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellHelper.getTranslatedSpell(spell, spellMap.get(spell))), true);
spellMap.remove(spell);
i++;
}
SpellHelper.setSpells(stack, spellMap);
}
Map<Identifier, Integer> spellMap = SpellTag.getSpells(stack);
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);
return 1;
return i;
})
)
)

View File

@ -2,14 +2,14 @@ package com.thebrokenrail.sorcerycraft.entity;
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.SpellTag;
import com.thebrokenrail.sorcerycraft.spell.registry.Spells;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.thrown.ThrownItemEntity;
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
import net.minecraft.item.Item;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
@SuppressWarnings("unused")
public class SpellEntity extends ThrownItemEntity {
public SpellEntity(EntityType<SpellEntity> entityType, World world) {
super(entityType, world);
@ -41,14 +42,19 @@ public class SpellEntity extends ThrownItemEntity {
super(SorceryCraft.SPELL_ENTITY, x, y, z, world);
}
public SpellEntity(World world) {
super(SorceryCraft.SPELL_ENTITY, world);
}
private boolean didSpellSucceed(Map<Identifier, Integer> spells) {
return Math.random() > SorceryCraft.getConfig().failureChance || spells.containsKey(Spells.STEADFAST_SPELL);
}
@Override
protected void onCollision(HitResult hitResult) {
super.onCollision(hitResult);
if (!getEntityWorld().isClient()) {
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
if (!spells.containsKey(Spells.INWARD_SPELL)) {
boolean success = didSpellSucceed(spells);
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
@ -80,7 +86,7 @@ public class SpellEntity extends ThrownItemEntity {
public void tick() {
super.tick();
if (!getEntityWorld().isClient()) {
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
if (spells.containsKey(Spells.INWARD_SPELL)) {
if (getOwner() != null) {
boolean success = didSpellSucceed(spells);

View File

@ -3,18 +3,19 @@ package com.thebrokenrail.sorcerycraft.gui;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.BasicInventory;
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -27,14 +28,14 @@ import java.util.function.BiConsumer;
public class CastingTableScreenHandler extends ScreenHandler {
private final Inventory inventory;
private final Inventory result;
private final Spell[] spells;
private Spell[] spells = new Spell[0];
private final ScreenHandlerContext context;
private int index = 0;
public CastingTableScreenHandler(int syncId, PlayerInventory playerInventory, ScreenHandlerContext blockContext) {
super(ScreenHandlerType.STONECUTTER, syncId);
inventory = new BasicInventory(2) {
inventory = new SimpleInventory(2) {
public void markDirty() {
super.markDirty();
CastingTableScreenHandler.this.onContentChanged(this);
@ -43,21 +44,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
context = blockContext;
result = new CraftingResultInventory();
if (playerInventory.player.isCreative() ? SorceryCraft.getConfig().limitCastingTable.creative : SorceryCraft.getConfig().limitCastingTable.survival) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) playerInventory.player;
Map<Identifier, Integer> spellsMap = spellPlayer.getDiscoveredSpells();
List<Spell> spellsArray = new ArrayList<>();
Spell[] allSpells = SpellRegistry.getSpells();
for (Spell spell : allSpells) {
if (spellsMap.containsKey(spell.getID()) && spellsMap.get(spell.getID()) >= spell.getLevel()) {
spellsArray.add(spell);
}
}
spells = spellsArray.toArray(new Spell[0]);
} else {
spells = SpellRegistry.getSpells();
}
setSpells(playerInventory.player);
addSlot(new Slot(inventory, 0, 136, 37) {
@Override
@ -66,7 +53,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
}
@Override
public int getMaxStackAmount() {
public int getMaxItemCount() {
return 1;
}
@ -97,10 +84,15 @@ public class CastingTableScreenHandler extends ScreenHandler {
player.addExperienceLevels(-spells[index].getXPCost());
}
context.run((BiConsumer<World, BlockPos>) SorceryCraft::playSpellSound);
context.run((world, blockPos) -> {
SorceryCraft.playSpellSound(world, blockPos);
if (!world.isClient()) {
SorceryCraft.CREATE_SPELL_CRITERION.trigger((ServerPlayerEntity) player);
}
});
CastingTableScreenHandler.this.inventory.setInvStack(0, ItemStack.EMPTY);
CastingTableScreenHandler.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount());
CastingTableScreenHandler.this.inventory.setStack(0, ItemStack.EMPTY);
CastingTableScreenHandler.this.inventory.removeStack(1, spells[index].getItemCost().getCount());
return stack;
}
});
@ -117,6 +109,30 @@ public class CastingTableScreenHandler extends ScreenHandler {
}
}
private void resetIndex() {
index = 0;
onContentChanged(inventory);
}
public void setSpells(PlayerEntity player) {
if (player.isCreative() ? SorceryCraft.getConfig().limitCastingTable.creative : SorceryCraft.getConfig().limitCastingTable.survival) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spellsMap = spellPlayer.getDiscoveredSpells();
List<Spell> spellsArray = new ArrayList<>();
Spell[] allSpells = SpellRegistry.getSpells();
for (Spell spell : allSpells) {
if (spellsMap.containsKey(spell.getID()) && spellsMap.get(spell.getID()) >= spell.getLevel()) {
spellsArray.add(spell);
}
}
spells = spellsArray.toArray(new Spell[0]);
} else {
spells = SpellRegistry.getSpells();
}
resetIndex();
}
public boolean canTakeResult(PlayerEntity playerEntity) {
return playerEntity.isCreative() || playerEntity.experienceLevel >= spells[index].getXPCost();
}
@ -125,7 +141,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
this.index = index;
onContentChanged(inventory);
if (inventory.getInvStack(0).isEmpty() && inventory.getInvStack(1).isEmpty()) {
if (inventory.getStack(0).isEmpty() && inventory.getStack(1).isEmpty()) {
ItemStack spellItem = new ItemStack(SorceryCraft.SPELL_ITEM);
autoFill(0, spellItem, true);
ItemStack paymentItem = getRecipes()[index].getItemCost();
@ -182,22 +198,22 @@ public class CastingTableScreenHandler extends ScreenHandler {
@Override
public void onContentChanged(Inventory inventory) {
super.onContentChanged(inventory);
ItemStack item = inventory.getInvStack(0);
ItemStack cost = inventory.getInvStack(1);
ItemStack item = inventory.getStack(0);
ItemStack cost = inventory.getStack(1);
if (inventory == this.inventory) {
if (spells.length > 0 &&
!item.isEmpty() &&
cost.getItem() == spells[index].getItemCost().getItem() &&
cost.getCount() >= spells[index].getItemCost().getCount()) {
ItemStack resultItem = item.copy();
Map<Identifier, Integer> resultSpells = SpellTag.getSpells(resultItem);
Map<Identifier, Integer> resultSpells = SpellHelper.getSpells(resultItem);
if (!resultSpells.containsKey(spells[index].getID()) || resultSpells.get(spells[index].getID()) <= spells[index].getLevel()) {
resultSpells.put(spells[index].getID(), spells[index].getLevel());
}
SpellTag.setSpells(resultItem, resultSpells);
result.setInvStack(2, resultItem);
SpellHelper.setSpells(resultItem, resultSpells);
result.setStack(2, resultItem);
} else {
result.setInvStack(2, ItemStack.EMPTY);
result.setStack(2, ItemStack.EMPTY);
}
}
}
@ -207,14 +223,14 @@ public class CastingTableScreenHandler extends ScreenHandler {
for (int i = 3; i < 39; ++i) {
ItemStack itemStack = slots.get(i).getStack();
if (!itemStack.isEmpty() && itemCompatible(stack, itemStack)) {
ItemStack invSlot = inventory.getInvStack(slot);
ItemStack invSlot = inventory.getStack(slot);
int count = invSlot.isEmpty() ? 0 : invSlot.getCount();
int requiredCount = Math.min((onlyOne ? 1 : stack.getMaxCount()) - count, itemStack.getCount());
ItemStack modifiedItem = itemStack.copy();
int totalCount = count + requiredCount;
itemStack.decrement(requiredCount);
modifiedItem.setCount(totalCount);
inventory.setInvStack(slot, modifiedItem);
inventory.setStack(slot, modifiedItem);
if (totalCount >= stack.getMaxCount() || onlyOne) {
break;
}

View File

@ -3,21 +3,22 @@ package com.thebrokenrail.sorcerycraft.item;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;
import java.util.HashMap;
@ -36,7 +37,7 @@ public class SpellItem extends Item {
if (!world.isClient()) {
SorceryCraft.playSpellSound(playerEntity);
playerEntity.incrementStat(SorceryCraft.STAT_CAST_SPELL);
playerEntity.incrementStat(SorceryCraft.CAST_SPELL_STAT);
SpellEntity entity = new SpellEntity(world, playerEntity);
entity.setItem(itemStack);
@ -52,16 +53,22 @@ public class SpellItem extends Item {
}
@Override
public boolean hasEnchantmentGlint(ItemStack stack) {
Map<Identifier, Integer> spells = SpellTag.getSpells(stack);
return spells.size() > 0 || super.hasEnchantmentGlint(stack);
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) {
use(user.getEntityWorld(), user, hand);
return ActionResult.SUCCESS;
}
@Override
public boolean hasGlint(ItemStack stack) {
Map<Identifier, Integer> spells = SpellHelper.getSpells(stack);
return spells.size() > 0 || super.hasGlint(stack);
}
@Override
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
Map<Identifier, Integer> spells = SpellTag.getSpells(itemStack);
Map<Identifier, Integer> spells = SpellHelper.getSpells(itemStack);
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
tooltip.add(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue(), true));
tooltip.add(SpellHelper.getTranslatedSpell(entry.getKey(), entry.getValue()));
}
}
@ -74,7 +81,7 @@ public class SpellItem extends Item {
ItemStack item = new ItemStack(this);
Map<Identifier, Integer> spell = new HashMap<>();
spell.put(value.getID(), value.getLevel());
SpellTag.setSpells(item, spell);
SpellHelper.setSpells(item, spell);
stacks.add(item);
}
}
@ -90,9 +97,9 @@ public class SpellItem extends Item {
super.inventoryTick(stack, world, entity, slot, selected);
if (!world.isClient() && entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
Map<Identifier, Integer> itemSpells = SpellTag.getSpells(player.inventory.getInvStack(slot));
Map<Identifier, Integer> itemSpells = SpellHelper.getSpells(player.inventory.getStack(slot));
SpellTag.learnSpells(player, itemSpells);
SpellHelper.learnSpells(player, itemSpells);
}
}
}

View File

@ -0,0 +1,14 @@
package com.thebrokenrail.sorcerycraft.mixin;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.advancement.criterion.Criterion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(Criteria.class)
public interface CriteriaRegistryHook {
@Invoker("register")
static <T extends Criterion<?>> T callRegister(T criterion) {
return criterion;
}
}

View File

@ -0,0 +1,24 @@
package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@SuppressWarnings("ConstantConditions")
@Mixin(AbstractButtonWidget.class)
public class MixinAbstractButtonWidget {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/AbstractButtonWidget;drawCenteredText(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V"), method = "renderButton")
public void drawCenteredText(MatrixStack matrices, TextRenderer textRenderer, Text text, int centerX, int y, int color) {
if ((Object) this instanceof CastingTableScreen.WidgetButtonPage) {
DrawableHelper.drawStringWithShadow(matrices, textRenderer, text.getString(), ((CastingTableScreen.WidgetButtonPage) (Object) this).x + 5, y, color);
} else {
DrawableHelper.drawCenteredText(matrices, textRenderer, text, centerX, y, color);
}
}
}

View File

@ -2,6 +2,8 @@ package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
@ -14,6 +16,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings("unused")
@Environment(EnvType.CLIENT)
@Mixin(ClientPlayNetworkHandler.class)
public class MixinClientPlayNetworkHandler {
@Shadow

View File

@ -0,0 +1,30 @@
package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Map;
@SuppressWarnings("unused")
@Mixin(ClientPlayerEntity.class)
@Environment(EnvType.CLIENT)
public class MixinClientPlayerEntity extends MixinPlayerEntity {
@Shadow
@Final
protected MinecraftClient client;
@Override
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
super.setDiscoveredSpells(spells);
if (client.currentScreen instanceof CastingTableScreen) {
((CastingTableScreen) client.currentScreen).resetIndex();
}
}
}

View File

@ -1,11 +1,15 @@
package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -16,26 +20,32 @@ import java.util.Map;
@SuppressWarnings("unused")
@Mixin(PlayerEntity.class)
public class MixinPlayerEntity implements SpellPlayerEntity {
// Namespace Fields
private Map<Identifier, Integer> sorceryCraftDiscoveredSpells = new HashMap<>();
@Shadow
public ScreenHandler currentScreenHandler;
@Unique
private Map<Identifier, Integer> discoveredSpells = new HashMap<>();
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
sorceryCraftDiscoveredSpells = SpellTag.getSpells(tag);
discoveredSpells = SpellHelper.getSpells(tag);
}
@Inject(at = @At("HEAD"), method = "writeCustomDataToTag")
public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) {
tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(sorceryCraftDiscoveredSpells));
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(discoveredSpells));
}
@Override
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
this.sorceryCraftDiscoveredSpells = spells;
discoveredSpells = spells;
if (currentScreenHandler instanceof CastingTableScreenHandler) {
//noinspection ConstantConditions
((CastingTableScreenHandler) currentScreenHandler).setSpells((PlayerEntity) (Object) this);
}
}
@Override
public Map<Identifier, Integer> getDiscoveredSpells() {
return sorceryCraftDiscoveredSpells;
return discoveredSpells;
}
}

View File

@ -1,18 +1,25 @@
package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import com.thebrokenrail.sorcerycraft.spell.util.SpellServerPlayerEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@SuppressWarnings("unused")
@Mixin(ServerPlayerEntity.class)
public abstract class MixinServerPlayerEntity implements SpellPlayerEntity {
public abstract class MixinServerPlayerEntity extends MixinPlayerEntity implements SpellServerPlayerEntity {
@Inject(at = @At("HEAD"), method = "copyFrom")
public void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
SpellPlayerEntity oldSpellPlayer = (SpellPlayerEntity) oldPlayer;
@ -21,10 +28,18 @@ public abstract class MixinServerPlayerEntity implements SpellPlayerEntity {
newSpellPlayer.setDiscoveredSpells(oldSpellPlayer.getDiscoveredSpells());
}
@Inject(at = @At("HEAD"), method = "playerTick")
public void playerTick(CallbackInfo info) {
@Override
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
super.setDiscoveredSpells(spells);
if (currentScreenHandler instanceof CastingTableScreenHandler) {
sync();
}
}
@Override
public void sync() {
CompoundTag tag = new CompoundTag();
tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(getDiscoveredSpells()));
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(getDiscoveredSpells()));
//noinspection ConstantConditions
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
}

View File

@ -3,12 +3,14 @@ package com.thebrokenrail.sorcerycraft.packet;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
public class SelectSpellC2SPacket {
public static void handle(PacketContext context, PacketByteBuf bytes) {
@ -20,6 +22,7 @@ public class SelectSpellC2SPacket {
}
}
@Environment(EnvType.CLIENT)
public static void send(MinecraftClient minecraft, int index) {
PacketByteBuf bytes = new PacketByteBuf(Unpooled.buffer());
bytes.writeInt(index);

View File

@ -2,21 +2,24 @@ package com.thebrokenrail.sorcerycraft.packet;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
public class UpdateKnownSpellsS2CPacket {
@Environment(EnvType.CLIENT)
public static void handle(PacketContext context, PacketByteBuf bytes) {
CompoundTag tag = bytes.readCompoundTag();
if (context.getPlayer() != null) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer();
spellPlayer.setDiscoveredSpells(SpellTag.getSpells(tag));
spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag));
}
}

View File

@ -4,6 +4,7 @@ import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
@ -23,12 +24,15 @@ public class CoolingSpell extends Spell {
@Override
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
BlockPos blockPos = hitResult.getBlockPos();
if (world.getBlockState(blockPos).matches(BlockTags.FIRE)) {
if (world.getBlockState(blockPos).isIn(BlockTags.FIRE)) {
world.removeBlock(blockPos, false);
}
if (world.getBlockState(blockPos).contains(Properties.LIT) && world.getBlockState(blockPos).get(Properties.LIT)) {
world.setBlockState(blockPos, world.getBlockState(blockPos).with(Properties.LIT, false));
}
BlockPos sideBlockPos = blockPos.offset(hitResult.getSide());
if (world.getBlockState(sideBlockPos).matches(BlockTags.FIRE)) {
if (world.getBlockState(sideBlockPos).isIn(BlockTags.FIRE)) {
world.removeBlock(sideBlockPos, false);
}
}

View File

@ -1,17 +1,13 @@
package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.TntBlock;
import net.minecraft.entity.Entity;
import net.minecraft.item.FlintAndSteelItem;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.AutomaticItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class FlameSpell extends Spell {
@ -21,25 +17,15 @@ public class FlameSpell extends Spell {
@Override
public void execute(World world, Entity source, Entity attacker, Entity target) {
target.setFireTicks(400 + (getLevel() * 200));
if (attacker instanceof LivingEntity) {
((LivingEntity) attacker).onAttacking(target);
}
target.setOnFireFor(8 + (getLevel() * 4));
}
@Override
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
BlockPos blockPos = hitResult.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);
BlockPos sideBlockPos = hitResult.getBlockPos().offset(hitResult.getSide());
BlockState sideBlockState = world.getBlockState(sideBlockPos);
if (blockState.getBlock() instanceof TntBlock) {
TntBlock.primeTnt(world, blockPos);
world.removeBlock(blockPos, false);
} else if (FlintAndSteelItem.canIgnite(sideBlockState, world, sideBlockPos)) {
world.setBlockState(sideBlockPos, AbstractFireBlock.getState(world, sideBlockPos));
} else if (FlintAndSteelItem.isIgnitable(blockState)) {
world.setBlockState(blockPos, blockState.with(Properties.LIT, true));
}
Items.FLINT_AND_STEEL.useOnBlock(new AutomaticItemPlacementContext(world, hitResult.getBlockPos(), hitResult.getSide().getOpposite(), new ItemStack(Items.FLINT_AND_STEEL), hitResult.getSide()));
}
@Override

View File

@ -2,6 +2,7 @@ package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
@ -29,11 +30,13 @@ public class LightningSpell extends Spell {
private void strike(World world, Vec3d pos, Entity attacker) {
ServerWorld serverWorld = (ServerWorld) world;
LightningEntity lightningEntity = new LightningEntity(world, pos.getX(), pos.getY(), pos.getZ(), false);
LightningEntity lightningEntity = EntityType.LIGHTNING_BOLT.create(world);
assert lightningEntity != null;
lightningEntity.updatePosition(pos.x, pos.y, pos.z);
if (attacker instanceof ServerPlayerEntity) {
lightningEntity.setChanneller((ServerPlayerEntity) attacker);
lightningEntity.setChanneler((ServerPlayerEntity) attacker);
}
serverWorld.addLightning(lightningEntity);
serverWorld.spawnEntity(lightningEntity);
}
@Override

View File

@ -17,7 +17,7 @@ public class TeleportSpell extends Spell {
}
private int getMaxTeleport(World world) {
return world.getDimension().isNether() ? 128 : 256;
return world.getRegistryKey() != World.OVERWORLD ? 128 : 256;
}
@Override
@ -57,6 +57,9 @@ public class TeleportSpell extends Spell {
case 1: {
return 18;
}
case 2: {
return 24;
}
}
return -1;
}
@ -70,12 +73,15 @@ public class TeleportSpell extends Spell {
case 1: {
return new ItemStack(Items.CHORUS_FRUIT);
}
case 2: {
return new ItemStack(Items.CHORUS_FLOWER);
}
}
return ItemStack.EMPTY;
}
@Override
public int getMaxLevel() {
return 2;
return 3;
}
}

View File

@ -1,11 +1,17 @@
package com.thebrokenrail.sorcerycraft.spell.api;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
/**
* Spell Implementation Base Class
*/
public abstract class Spell {
private final Identifier id;
private final int level;
@ -70,4 +76,26 @@ public abstract class Spell {
* @return The Spell's Max Level
*/
public abstract int getMaxLevel();
/**
* Default Implementation for Spell.getTranslation()
* @param id Spell ID
* @param level Spell Level
* @return Translated Display Name
*/
public static MutableText getDefaultTranslation(Identifier id, int level) {
MutableText text = new TranslatableText("spell." + id.getNamespace() + '.' + id.getPath());
if (level != 0 || SpellRegistry.getMaxLevel(id) != 1) {
text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1)));
}
return text;
}
/**
* Get Translated Display Name
* @return Translated Display Name
*/
public MutableText getTranslation() {
return getDefaultTranslation(getID(), getLevel());
}
}

View File

@ -1,4 +1,4 @@
package com.thebrokenrail.sorcerycraft.spell.registry;
package com.thebrokenrail.sorcerycraft.spell.api.registry;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.util.Identifier;
@ -9,13 +9,28 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Spell Implementation Registry
*/
public class SpellRegistry {
private static final Map<Identifier, Class<?>> spells = new HashMap<>();
/**
* Get Spell Implementation
* @param entry Map Entry
* @return Spell Implementation
*/
public static Spell getSpell(Map.Entry<Identifier, Integer> entry) {
return getSpell(entry.getKey(), entry.getValue());
}
/**
* Get Spell Implementation
* @param id Spell ID
* @param level Spell Level
* @return Spell Implementation
*/
public static Spell getSpell(Identifier id, int level) {
if (!spells.containsKey(id)) {
return null;
@ -28,6 +43,11 @@ public class SpellRegistry {
}
}
/**
* Get Max Level of a Spell
* @param id Spell ID
* @return Max Level
*/
public static int getMaxLevel(Identifier id) {
Spell tempSpell = getSpell(id, 0);
if (tempSpell == null) {
@ -36,6 +56,10 @@ public class SpellRegistry {
return tempSpell.getMaxLevel();
}
/**
* Get All Spell Implementations
* @return List of Spell Implementations
*/
public static Spell[] getSpells() {
List<Spell> out = new ArrayList<>();
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
@ -53,6 +77,10 @@ public class SpellRegistry {
return out.toArray(new Spell[0]);
}
/**
* Get All Max Level Spell Implementations
* @return List of Spell Implementations
*/
public static Spell[] getMaxSpells() {
List<Spell> out = new ArrayList<>();
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
@ -76,6 +104,10 @@ public class SpellRegistry {
return id;
}
/**
* Gat All Spell IDs
* @return List of Spell IDs
*/
public static Identifier[] getSpellsID() {
return spells.keySet().toArray(new Identifier[0]);
}

View File

@ -1,4 +1,4 @@
package com.thebrokenrail.sorcerycraft.spell.registry;
package com.thebrokenrail.sorcerycraft.spell.api.registry;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.CoolingSpell;
@ -13,6 +13,9 @@ import com.thebrokenrail.sorcerycraft.spell.SteadfastSpell;
import com.thebrokenrail.sorcerycraft.spell.TeleportSpell;
import net.minecraft.util.Identifier;
/**
* All Builtin Spells
*/
@SuppressWarnings("unused")
public class Spells {
public static final Identifier HEAL_SPELL;

View File

@ -1,13 +1,18 @@
package com.thebrokenrail.sorcerycraft.spell.util;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.condition.LootCondition;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.function.ConditionalLootFunction;
import net.minecraft.loot.function.LootFunction;
import net.minecraft.loot.function.LootFunctionType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.Map;
@ -21,14 +26,30 @@ public class RandomSpellLootTableFunction extends ConditionalLootFunction {
while (!(context.getRandom().nextDouble() > chance)) {
Spell[] spells = SpellRegistry.getSpells();
int index = context.getRandom().nextInt(spells.length);
Map<Identifier, Integer> spell = SpellTag.getSpells(stack);
Map<Identifier, Integer> spell = SpellHelper.getSpells(stack);
spell.put(spells[index].getID(), spells[index].getLevel());
SpellTag.setSpells(stack, spell);
SpellHelper.setSpells(stack, spell);
chance = chance * 0.25d;
}
return stack;
}
@Override
public LootFunctionType getType() {
return Registry.LOOT_FUNCTION_TYPE.get(new Identifier(SorceryCraft.NAMESPACE, "random_spell"));
}
public static class Factory extends ConditionalLootFunction.Serializer<RandomSpellLootTableFunction> {
public Factory() {
super();
}
@Override
public RandomSpellLootTableFunction fromJson(JsonObject json, JsonDeserializationContext context, LootCondition[] conditions) {
return (RandomSpellLootTableFunction) new com.thebrokenrail.sorcerycraft.spell.util.RandomSpellLootTableFunction.Builder().build();
}
}
public static class Builder extends ConditionalLootFunction.Builder<RandomSpellLootTableFunction.Builder> {
@Override
protected RandomSpellLootTableFunction.Builder getThisBuilder() {

View File

@ -2,23 +2,28 @@ package com.thebrokenrail.sorcerycraft.spell.util;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.MessageType;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.world.World;
import java.util.HashMap;
import java.util.Map;
public class SpellTag {
public class SpellHelper {
public static final String SPELL_TAG = "Spells";
public static void setSpells(ItemStack itemStack, Map<Identifier, Integer> map) {
@ -82,17 +87,20 @@ public class SpellTag {
return map;
}
public static Text getTranslatedSpell(Identifier id, int level, boolean allowNumber) {
Text text = new TranslatableText("spell." + id.getNamespace() + '.' + id.getPath());
text.formatted(Formatting.GRAY);
if ((level != 0 || SpellRegistry.getMaxLevel(id) != 1) && allowNumber) {
text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1)));
public static Text getTranslatedSpell(Identifier id, int level) {
Spell spell = SpellRegistry.getSpell(id, level);
MutableText text;
if (spell != null) {
text = spell.getTranslation();
} else {
text = Spell.getDefaultTranslation(id, level);
}
text.formatted(Formatting.GRAY);
return text;
}
public static Text getTranslatedSpellChat(Identifier id, int level) {
return new LiteralText("[").append(SpellTag.getTranslatedSpell(id, level, true).getString()).append("]").formatted(Formatting.GREEN);
return new LiteralText("[").append(SpellHelper.getTranslatedSpell(id, level).getString()).append("]").formatted(Formatting.GREEN);
}
public static void learnSpells(PlayerEntity player, Map<Identifier, Integer> itemSpells) {
@ -116,7 +124,7 @@ public class SpellTag {
playerSpells.put(spell.getID(), spell.getLevel());
assert world.getServer() != null;
Text text = getTranslatedSpellChat(spell.getID(), spell.getLevel());
world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".discovered_spell", player.getDisplayName(), text));
world.getServer().getPlayerManager().sendToAll(new GameMessageS2CPacket(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".discovered_spell", player.getDisplayName(), text), MessageType.CHAT, Util.NIL_UUID));
}
}
}
@ -124,6 +132,7 @@ public class SpellTag {
if (changed) {
SorceryCraft.playSpellSound(player);
spellPlayer.setDiscoveredSpells(playerSpells);
SorceryCraft.DISCOVER_ALL_SPELLS_CRITERION.trigger((ServerPlayerEntity) player);
}
}
}

View File

@ -0,0 +1,5 @@
package com.thebrokenrail.sorcerycraft.spell.util;
public interface SpellServerPlayerEntity extends SpellPlayerEntity {
void sync();
}

View File

@ -16,9 +16,15 @@
"stat.sorcerycraft.cast_spell": "Spells Cast",
"text.autoconfig.sorcerycraft.title": "SorceryCraft Config",
"text.autoconfig.sorcerycraft.option.failureChance": "Spell Failure Chance",
"text.autoconfig.sorcerycraft.option.limitCastingTable": "Limit Casting Table to discovered spells",
"text.autoconfig.sorcerycraft.option.limitCastingTable": "Limit Casting Table To Discovered Spells",
"text.autoconfig.sorcerycraft.option.limitCastingTable.creative": "Creative Mode",
"text.autoconfig.sorcerycraft.option.limitCastingTable.survival": "Survival Mode",
"advancements.sorcerycraft.adventure.discover_spell.title": "Witchcraft!",
"advancements.sorcerycraft.adventure.discover_spell.description": "Discover a spell",
"advancements.sorcerycraft.adventure.create_spell.title": "Spellbinding!",
"advancements.sorcerycraft.adventure.create_spell.description": "Cast a spell using a Casting Table",
"advancements.sorcerycraft.adventure.discover_all_spells.title": "Master of Magic!",
"advancements.sorcerycraft.adventure.discover_all_spells.description": "Discover all spells",
"spell.sorcerycraft.damage_spell": "Damage",
"spell.sorcerycraft.heal_spell": "Heal",
"spell.sorcerycraft.dissolve_spell": "Dissolve",

View File

@ -0,0 +1,23 @@
{
"parent": "sorcerycraft:adventure/discover_spell",
"display": {
"icon": {
"item": "sorcerycraft:casting_table"
},
"title": {
"translate": "advancements.sorcerycraft.adventure.create_spell.title"
},
"description": {
"translate": "advancements.sorcerycraft.adventure.create_spell.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"sorcerycraft:casting_table": {
"trigger": "sorcerycraft:create_spell"
}
}
}

View File

@ -0,0 +1,27 @@
{
"parent": "sorcerycraft:adventure/create_spell",
"display": {
"icon": {
"item": "sorcerycraft:spell",
"nbt": "{Spells: [{id: \"sorcerycraft:damage_spell\", level: 0}]}"
},
"title": {
"translate": "advancements.sorcerycraft.adventure.discover_all_spells.title"
},
"description": {
"translate": "advancements.sorcerycraft.adventure.discover_all_spells.description"
},
"frame": "challenge",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"sorcerycraft:spell": {
"trigger": "sorcerycraft:discover_all_spells"
}
},
"rewards": {
"experience": 100
}
}

View File

@ -0,0 +1,36 @@
{
"parent": "minecraft:adventure/root",
"display": {
"icon": {
"item": "sorcerycraft:spell"
},
"title": {
"translate": "advancements.sorcerycraft.adventure.discover_spell.title"
},
"description": {
"translate": "advancements.sorcerycraft.adventure.discover_spell.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"sorcerycraft:spell": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "sorcerycraft:spell"
}
]
}
}
},
"rewards": {
"recipes": [
"sorcerycraft:spell",
"sorcerycraft:casting_table"
]
}
}

View File

@ -2,7 +2,7 @@
"schemaVersion": 1,
"id": "sorcerycraft",
"version": "${version}",
"name": "SorceryCraft",
"name": "${name}",
"description": "Cast Spells in Minecraft!",
"authors": [
"TheBrokenRail"
@ -20,7 +20,7 @@
"com.thebrokenrail.sorcerycraft.SorceryCraft"
],
"client": [
"com.thebrokenrail.sorcerycraft.SorceryCraft"
"com.thebrokenrail.sorcerycraft.client.SorceryCraftClient"
],
"modmenu": [
"com.thebrokenrail.sorcerycraft.client.ModMenu"
@ -33,5 +33,11 @@
"fabricloader": ">=0.7.4",
"fabric": "*",
"minecraft": "1.16.x"
},
"custom": {
"modupdater": {
"strategy": "curseforge",
"projectID": 365308
}
}
}

View File

@ -3,9 +3,12 @@
"package": "com.thebrokenrail.sorcerycraft.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinClientPlayNetworkHandler"
"MixinClientPlayerEntity",
"MixinClientPlayNetworkHandler",
"MixinAbstractButtonWidget"
],
"mixins": [
"CriteriaRegistryHook",
"MixinPlayerEntity",
"MixinServerPlayerEntity"
],