Compare commits

...

44 Commits

Author SHA1 Message Date
5381263113 Auto-Publish
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-12-15 14:04:06 -05:00
263466eed3 1.16.4
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-12-15 14:00:42 -05:00
10bfbdb53d Update Loom
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-06-24 18:09:42 -04:00
162df5c962 Port To 1.16.1
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-06-24 11:43:53 -04:00
3f06723a1f 1.2.9
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Fix Dedicated Server Crash
2020-05-24 16:55:23 -04:00
700b970a04 Fix Config
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-05-02 15:21:29 -04:00
3bfe235d97 Fix HTML Publish
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-05-02 14:54:43 -04:00
48fef73096 20w18a
Some checks failed
SorceryCraft/pipeline/head There was a failure building this commit
2020-05-02 14:42:16 -04:00
504a52597d 1.2.8
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Register Loot Table Function
2020-04-11 13:49:08 -04:00
55808ca049 Fix Gradle
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-04-03 11:47:55 -04:00
e5aa71f751 20w14a
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-04-03 11:45:44 -04:00
0664de5de5 Use @Unique
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-27 14:07:47 -04:00
4d0e4b6411 20w13b
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-26 11:48:22 -04:00
114c3a03d2 1.2.7
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Fix Cooling Spell Bug
2020-03-25 16:19:41 -04:00
6b3445e1f6 Update Fabric API
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-25 15:04:33 -04:00
14f254af3d Update Cloth Config
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-25 14:02:03 -04:00
8a23afeed0 20w13a
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-25 13:58:00 -04:00
8ca4986714 1.2.6
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Fix Potential Client-Server De-sync Bug
2020-03-24 15:31:35 -04:00
fb3ba1411f Remove Unused Import
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-24 13:12:12 -04:00
3b91e3daf8 1.2.5
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Fix Casting Table Bug
2020-03-24 13:05:03 -04:00
acf08c7fa6 1.2.4
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Optimize Packets
Allow Command Blocks to use ```/spell``` Command
Namespace Statistics
2020-03-24 09:38:29 -04:00
5552fe5cd8 Optimize Packets
Allow Command Blocks to use /spell Command
2020-03-24 09:35:42 -04:00
d381beff16 Namespace Statistics
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-23 15:13:17 -04:00
ff50bd3851 Update CurseForge Script
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-22 15:48:13 -04:00
76f316f7bd 1.2.3
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Tweak Cooling Spell
Tweak Versioning
2020-03-22 15:30:46 -04:00
df3c1dcffd Add Annotations
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-21 15:30:05 -04:00
d2d33c6159 1.2.2
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Allow /spell command to work with multiple players
2020-03-21 13:25:28 -04:00
f40e44e366 1.2.1
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Fix Launching Without ModMenu
2020-03-21 11:49:58 -04:00
4ebae792ac 1.2
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update API (More Consistent Package Names)
Fix Bug When Casting Spell
2020-03-20 22:05:52 -04:00
3fe89d2d95 1.1.21
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update Mappings
Tweak Teleport and Flame Spells
2020-03-19 23:06:38 -04:00
b44ca31175 1.1.20
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update to 20w12a
2020-03-18 17:21:39 -04:00
9d1cad6223 1.1.19
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update API Docs
Allow Setting Custom Display name for Spell
2020-03-18 11:56:25 -04:00
373f0ad8d3 1.1.18
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Fix Crash When Using Dedicated Server
2020-03-17 21:30:59 -04:00
1c033d5a0d 1.1.17
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update Mappings
Add Spell-related Advancements
2020-03-17 20:42:02 -04:00
1dbbd55376 Add JavaDoc Link
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-17 14:34:42 -04:00
019c588add 1.1.16
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Consistent Gradle Project Name
2020-03-17 14:25:35 -04:00
5e24602ca8 1.1.15
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Build JavaDoc Jar
2020-03-17 14:08:55 -04:00
ee78088250 1.1.14
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update Config Lang
2020-03-17 13:36:53 -04:00
c592b9e9af 1.1.13
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update Mappings
Improve /spell command
2020-03-17 13:26:10 -04:00
db54bdf2ad Fix Mod Menu Version
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-16 15:07:18 -04:00
a3be3712d4 1.1.12
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update Mappings
Add Config Screen
Clarify Terms
2020-03-16 11:21:06 -04:00
998e514cd9 Minor changes
All checks were successful
SorceryCraft/pipeline/head This commit looks good
2020-03-14 18:11:28 -04:00
4bc4821543 1.1.11
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update Mappings
Add Lightning Spell
2020-03-13 18:05:12 -04:00
5a4cd89d68 1.1.10
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update to 20w11a
Enhance Flame Spell
2020-03-11 17:34:52 -04:00
50 changed files with 1214 additions and 324 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: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,43 +25,75 @@
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));
}
}
```
4. Register the Spell in your ModInitializer
4. Register the spell in your ModInitializer
```java
public class ExampleMod implements ModInitializer {
public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class);
}
```
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,4 +1,83 @@
### Changelog
# 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
**1.1.12**
* Update Mappings
* Add Config Screen
* Clarify Terms
**1.1.11**
* Update Mappings
* Add Lightning Spell
**1.1.10**
* Update to 20w11a
* Enhance Flame Spell
**1.1.9**
* Fix Scrolling Bug

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

@ -1,13 +1,13 @@
# SorceryCraft
Cast Spells in Minecraft!
This mod supports the Minecraft 1.16 snapshots.
This mod currently supports the Minecraft 1.16 snapshots.
## What are Spells?
Spells are found throughout the world in chests. When you pick up a Spell you will learn it, one you learn a Spell you can apply it to a blank or existing Spell in the Casting Table. You can cast Spells by right-clicking. There is also a 30% chance the spell will rebound and hit you instead, unless the "Steadfast" Spell is applied.
Spells are found throughout the world in chests. When you pick up a Spell you will "discover" it, once you "discover" a spell you can apply it to a blank or existing spell in the Casting Table. You can cast spells by right-clicking. There is also a 30% chance (by default) that the spell will rebound and hit you instead, unless the "Steadfast" spell is applied.
## What's a Casting Table?
You can apply Spells to blank or existing Spells in the Casting Table. Doing so will require a certain amount of levels, and sometimes may require an item.
You can apply Spells to blank or existing spells in the Casting Table. Doing so will require a certain amount of levels, and may require an item.
## Crafting
#### Blank Spell
@ -56,28 +56,35 @@ You can apply Spells to blank or existing Spells in the Casting Table. Doing so
| Heal | 2 | Heals target. |
| Dissolve | 1 | Removes target's status effects. |
| Levitate | 2 | Gives target the Levitation effect. |
| Steadfast | 1 | Prevents Spell from failing. This does nothing on its own. |
| Teleport | 2 | Teleports target to random location. |
| Inward | 1 | Causes the Spell to target the caster. If the Spell fails instead of rebounding, it will just do nothing. This does nothing on its own. |
| Steadfast | 1 | Prevents the spell from failing. This spell does nothing on its own. |
| 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. |
## ```/spell``` Command
This command requires OP permissions.
#### ```/spell clear <player>```
#### ```/spell forget <player>```
This command clears all known spells from the given player.
#### ```/spell forget <player> <spell-id>```
This command clears the specified spell from the given player.
#### ```/spell list <player>```
This lists all the spells the given player knows.
#### ```/spell learn <player> <spell-id> <level>```
This teaches the specified spell to the specified player.
#### ```/spell discover <player>```
This adds all spells to the specified player's discovered spells list.
#### ```/spell add <player> <spell-id> <level>```
This adds the specified spell to the item in the player's main hand.
#### ```/spell discover <player> <spell-id> <level>```
This adds the specified spell to the specified player's discovered spells list.
#### ```/spell apply <player> <spell-id> <level>```
This adds the specified spell to the item in the specified player's main hand.
#### ```/spell remove <player> <spell-id>```
This removes the specified spell from the item in the player's main hand.
This removes the specified spell from the item in the specified player's main hand.
## API
[View API](API.md)

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,25 +10,40 @@ 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 {
}
repositories {
jcenter()
maven {
url "https://dl.bintray.com/shedaniel/autoconfig1u/"
}
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
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}"
modImplementation "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
include "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
modImplementation "me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}"
include "me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}"
modImplementation "io.github.prospector:modmenu:${project.mod_menu_version}"
}
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) {
@ -50,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')
@ -64,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,17 +3,20 @@ org.gradle.jvmargs = -Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version = 20w10a
minecraft_version = 1.16.4
curseforge_id = 365308
simple_minecraft_version = 1.16-Snapshot
yarn_mappings = 20w10a+build.20
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.9
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_version = 0.5.1+build.305-1.16
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

@ -0,0 +1,32 @@
package com.thebrokenrail.sorcerycraft;
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Config(name = SorceryCraft.NAMESPACE)
public class ModConfig implements ConfigData {
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface UsePercentage {
double min();
double max();
}
@UsePercentage(min = 0, max = 1)
public double failureChance = 0.3;
@ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
public LimitCastingTable limitCastingTable = new LimitCastingTable();
public static class LimitCastingTable {
public boolean creative = false;
public boolean survival = true;
}
}

View File

@ -1,36 +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.block.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.client.block.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 net.fabricmc.api.ClientModInitializer;
import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
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;
@ -38,12 +34,12 @@ 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;
@ -53,13 +49,18 @@ import net.minecraft.world.World;
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,
@ -70,11 +71,20 @@ 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 final double SPELL_FAILURE_CHANCE = 0.3d;
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();
}
private boolean isSelectedLootTable(Identifier lootTable) {
for (Identifier id : LOOT_TABLES) {
@ -87,8 +97,11 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
@Override
public void onInitialize() {
//noinspection InstantiationOfUtilityClass
new Spells();
AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
ITEM_GROUP = FabricItemGroupBuilder.create(
new Identifier(NAMESPACE, "spells"))
.icon(() -> new ItemStack(SPELL_ITEM))
@ -98,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);
@ -108,28 +121,28 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (syncId, identifier, player, buf) -> {
final World world = player.world;
final BlockPos pos = buf.readBlockPos();
return Objects.requireNonNull(world.getBlockState(pos).createContainerFactory(player.world, pos)).createMenu(syncId, player.inventory, player);
return Objects.requireNonNull(world.getBlockState(pos).createScreenHandlerFactory(player.world, pos)).createMenu(syncId, player.inventory, player);
});
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;
@ -141,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;
}
@ -165,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

@ -1,14 +1,16 @@
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;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.BlockContext;
import net.minecraft.screen.NameableScreenHandlerFactory;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
@ -28,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 NameableScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) {
return new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> new CastingTableScreenHandler(i, playerInventory, BlockContext.create(world, pos)), new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table"));
public NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) {
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

@ -0,0 +1,24 @@
package com.thebrokenrail.sorcerycraft.client;
import com.thebrokenrail.sorcerycraft.ModConfig;
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() {
return SorceryCraft.NAMESPACE;
}
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return (ConfigScreenFactory<Screen>) screen -> AutoConfig.getConfigScreen(ModConfig.class, screen).get();
}
}

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

@ -1,29 +1,30 @@
package com.thebrokenrail.sorcerycraft.client.block;
package com.thebrokenrail.sorcerycraft.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.block.CastingTableScreenHandler;
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.ScreenWithHandler;
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;
import net.minecraft.util.math.MathHelper;
@Environment(EnvType.CLIENT)
public class CastingTableScreen extends ScreenWithHandler<CastingTableScreenHandler> {
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 ScreenWithHandler<CastingTableScreenHand
}
@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;
blit(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 ScreenWithHandler<CastingTableScreenHand
if (k > 0) {
int modifier = (int) (((float) indexStartOffset / k) * (1 + 139 - 27));
blit(i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
drawTexture(matrixStack, i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
} else {
blit(i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
drawTexture(matrixStack, i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
}
}
@ -99,7 +105,7 @@ public class CastingTableScreen extends ScreenWithHandler<CastingTableScreenHand
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 ScreenWithHandler<CastingTableScreenHand
}
}
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);
}
}
@ -132,7 +138,7 @@ public class CastingTableScreen extends ScreenWithHandler<CastingTableScreenHand
@Override
public boolean mouseScrolled(double d, double e, double amount) {
int i = handler.getRecipes().length;
if (this.canScroll(i)) {
if (canScroll(i)) {
int j = i - 7;
indexStartOffset = (int) ((double) indexStartOffset - amount);
indexStartOffset = MathHelper.clamp(indexStartOffset, 0, j);
@ -194,37 +200,32 @@ public class CastingTableScreen extends ScreenWithHandler<CastingTableScreenHand
}
@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

@ -4,17 +4,21 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.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;
@ -23,94 +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");
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName()), false);
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spells = spellPlayer.getSorceryCraftSpells();
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
ctx.getSource().sendFeedback(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue(), true).formatted(Formatting.YELLOW), false);
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 0;
return i;
})
)
)
.then(CommandManager.literal("clear")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.literal("forget")
.then(CommandManager.argument("player", EntityArgumentType.players())
.executes(ctx -> {
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
spellPlayer.setSorceryCraftSpells(new HashMap<>());
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.cleared_spells", player.getDisplayName()), true);
return 1;
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<>());
}
return i;
})
.then(CommandManager.argument("spell", SpellArgumentType.spell())
.executes(ctx -> {
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);
}
return i;
})
)
)
)
.then(CommandManager.literal("learn")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.literal("discover")
.then(CommandManager.argument("player", EntityArgumentType.players())
.executes(ctx -> {
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);
}
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("add")
.then(CommandManager.argument("player", EntityArgumentType.player())
.then(CommandManager.literal("apply")
.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.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);
spellMap.remove(spell);
SpellTag.setSpells(stack, spellMap);
ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.spell.removed_spell", SpellTag.getTranslatedSpell(spell, 0, false)), true);
return 1;
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.SPELL_FAILURE_CHANCE || spells.containsKey(Spells.STEADFAST_SPELL);
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

@ -1,20 +1,21 @@
package com.thebrokenrail.sorcerycraft.block;
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.BlockContext;
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 final BlockContext context;
private Spell[] spells = new Spell[0];
private final ScreenHandlerContext context;
private int index = 0;
public CastingTableScreenHandler(int syncId, PlayerInventory playerInventory, BlockContext blockContext) {
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()) {
spells = SpellRegistry.getSpells();
} else {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) playerInventory.player;
Map<Identifier, Integer> spellsMap = spellPlayer.getSorceryCraftSpells();
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]);
}
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;
}
@ -229,7 +245,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
@Override
public boolean canUse(PlayerEntity player) {
return true;
return context.run((world, blockPos) -> world.getBlockState(blockPos).getBlock().equals(SorceryCraft.CASTING_TABLE_BLOCK) && player.squaredDistanceTo((double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.5D, (double) blockPos.getZ() + 0.5D) <= 64.0D, true);
}
public Spell[] getRecipes() {

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;
@ -33,10 +34,10 @@ public class SpellItem extends Item {
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
ItemStack itemStack = playerEntity.getStackInHand(hand);
SorceryCraft.playSpellSound(playerEntity);
if (!world.isClient()) {
playerEntity.incrementStat(SorceryCraft.STAT_CAST_SPELL);
SorceryCraft.playSpellSound(playerEntity);
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,13 +16,14 @@ 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
private ClientWorld world;
@Inject(method = "onEntitySpawn", at = @At(value = "TAIL"))
public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo callbackInfo) {
public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo info) {
EntityType<?> entityType = packet.getEntityTypeId();
Entity entity = null;

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,25 +20,32 @@ import java.util.Map;
@SuppressWarnings("unused")
@Mixin(PlayerEntity.class)
public class MixinPlayerEntity implements SpellPlayerEntity {
private Map<Identifier, Integer> sorceryCraftSpells = 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) {
sorceryCraftSpells = 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(sorceryCraftSpells));
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(discoveredSpells));
}
@Override
public void setSorceryCraftSpells(Map<Identifier, Integer> spells) {
this.sorceryCraftSpells = spells;
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
discoveredSpells = spells;
if (currentScreenHandler instanceof CastingTableScreenHandler) {
//noinspection ConstantConditions
((CastingTableScreenHandler) currentScreenHandler).setSpells((PlayerEntity) (Object) this);
}
}
@Override
public Map<Identifier, Integer> getSorceryCraftSpells() {
return sorceryCraftSpells;
public Map<Identifier, Integer> getDiscoveredSpells() {
return discoveredSpells;
}
}

View File

@ -1,30 +1,45 @@
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 ci) {
public void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
SpellPlayerEntity oldSpellPlayer = (SpellPlayerEntity) oldPlayer;
SpellPlayerEntity newSpellPlayer = this;
newSpellPlayer.setSorceryCraftSpells(oldSpellPlayer.getSorceryCraftSpells());
newSpellPlayer.setDiscoveredSpells(oldSpellPlayer.getDiscoveredSpells());
}
@Inject(at = @At("HEAD"), method = "playerTick")
public void playerTick(CallbackInfo ignored) {
@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(getSorceryCraftSpells()));
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(getDiscoveredSpells()));
//noinspection ConstantConditions
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
}

View File

@ -1,14 +1,16 @@
package com.thebrokenrail.sorcerycraft.packet;
import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.block.CastingTableScreenHandler;
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.setSorceryCraftSpells(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,19 +24,22 @@ 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);
}
}
@Override
public int getXPCost() {
return 13;
return 10;
}
@Override

View File

@ -25,10 +25,10 @@ public class DamageSpell extends Spell {
public int getXPCost() {
switch (getLevel()) {
case 0: {
return 5;
return 4;
}
case 1: {
return 10;
return 8;
}
}
return -1;

View File

@ -22,7 +22,7 @@ public class DissolveSpell extends Spell {
@Override
public int getXPCost() {
return 12;
return 8;
}
@Override

View File

@ -1,13 +1,13 @@
package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.AutomaticItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
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 {
@ -17,15 +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().offset(hitResult.getSide());
if (world.isAir(blockPos)) {
world.setBlockState(blockPos, AbstractFireBlock.getState(world, blockPos));
}
Items.FLINT_AND_STEEL.useOnBlock(new AutomaticItemPlacementContext(world, hitResult.getBlockPos(), hitResult.getSide().getOpposite(), new ItemStack(Items.FLINT_AND_STEEL), hitResult.getSide()));
}
@Override
@ -35,7 +35,7 @@ public class FlameSpell extends Spell {
return 8;
}
case 1: {
return 16;
return 12;
}
}
return -1;

View File

@ -25,10 +25,10 @@ public class HealSpell extends Spell {
public int getXPCost() {
switch (getLevel()) {
case 0: {
return 5;
return 4;
}
case 1: {
return 10;
return 8;
}
}
return -1;

View File

@ -29,7 +29,7 @@ public class LevitateSpell extends Spell {
return 12;
}
case 1: {
return 21;
return 24;
}
}
return -1;

View File

@ -0,0 +1,56 @@
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;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class LightningSpell extends Spell {
public LightningSpell(Identifier id, int level) {
super(id, level);
}
@Override
public void execute(World world, Entity source, Entity attacker, Entity target) {
strike(world, target.getPos(), attacker);
}
@Override
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
strike(world, hitResult.getPos(), attacker);
}
private void strike(World world, Vec3d pos, Entity attacker) {
ServerWorld serverWorld = (ServerWorld) world;
LightningEntity lightningEntity = EntityType.LIGHTNING_BOLT.create(world);
assert lightningEntity != null;
lightningEntity.updatePosition(pos.x, pos.y, pos.z);
if (attacker instanceof ServerPlayerEntity) {
lightningEntity.setChanneler((ServerPlayerEntity) attacker);
}
serverWorld.spawnEntity(lightningEntity);
}
@Override
public int getXPCost() {
return 18;
}
@Override
public ItemStack getItemCost() {
return new ItemStack(Items.END_ROD);
}
@Override
public int getMaxLevel() {
return 1;
}
}

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;
@ -16,7 +22,7 @@ public abstract class Spell {
}
/**
* Get the ID of this Spell
* Get the ID of this spell
* @return The Spell ID
*/
public Identifier getID() {
@ -24,18 +30,18 @@ public abstract class Spell {
}
/**
* Get the level of this Spell
* @return The Spell Level
* Get the level of this spell
* @return The Spell's Level
*/
public int getLevel() {
return level;
}
/**
* Execute this Spell on an Entity
* Execute this spell on an Entity
* @param world World
* @param source A SpellEntity
* @param attacker The Entity that cast this Spell
* @param attacker The Entity that cast this spell
* @param target The Target
*/
public void execute(World world, Entity source, Entity attacker, Entity target) {
@ -43,10 +49,10 @@ public abstract class Spell {
}
/**
* Cast this Spell on a block
* Execute this spell on a block
* @param world World
* @param source A SpellEntity
* @param attacker The Entity that cast this Spell
* @param attacker The Entity that cast this spell
* @param hitResult The block's HitResult
*/
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
@ -54,20 +60,42 @@ public abstract class Spell {
}
/**
* Get the amount of levels required to make this Spell in a Casting Table
* Get the amount of levels required to make this spell in a Casting Table
* @return The XP cost
*/
public abstract int getXPCost();
/**
* Get the item(s) required to make ExampleSpell in a Casting Table, or ItemStack.EMPTY if an item is not required
* Get the item(s) required to make this spell in a Casting Table, or ItemStack.EMPTY if an item is not required
* @return The item cost
*/
public abstract ItemStack getItemCost();
/**
* Get the maximum level of this Spell
* @return The Max Level
* Get the maximum level of this spell
* @return The Spell's Max Level
*/
public abstract int getMaxLevel();
/**
* 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,22 @@ 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()) {
int maxLevel = getMaxLevel(entry.getKey());
if (maxLevel == -1) {
continue;
}
out.add(getSpell(entry.getKey(), maxLevel - 1));
}
return out.toArray(new Spell[0]);
}
/**
* Register a Spell
* @param id The Spell ID
@ -64,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;
@ -8,10 +8,14 @@ import com.thebrokenrail.sorcerycraft.spell.FlameSpell;
import com.thebrokenrail.sorcerycraft.spell.HealSpell;
import com.thebrokenrail.sorcerycraft.spell.InwardSpell;
import com.thebrokenrail.sorcerycraft.spell.LevitateSpell;
import com.thebrokenrail.sorcerycraft.spell.LightningSpell;
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;
@ -23,6 +27,7 @@ public class Spells {
public static final Identifier TELEPORT_SPELL;
public static final Identifier INWARD_SPELL;
public static final Identifier COOLING_SPELL;
public static final Identifier LIGHTNING_SPELL;
static {
HEAL_SPELL = SpellRegistry.register(new Identifier(SorceryCraft.NAMESPACE, "heal_spell"), HealSpell.class);
@ -34,5 +39,6 @@ public class Spells {
TELEPORT_SPELL = SpellRegistry.register(new Identifier(SorceryCraft.NAMESPACE, "teleport_spell"), TeleportSpell.class);
INWARD_SPELL = SpellRegistry.register(new Identifier(SorceryCraft.NAMESPACE, "inward_spell"), InwardSpell.class);
COOLING_SPELL = SpellRegistry.register(new Identifier(SorceryCraft.NAMESPACE, "cooling_spell"), CoolingSpell.class);
LIGHTNING_SPELL = SpellRegistry.register(new Identifier(SorceryCraft.NAMESPACE, "lightning_spell"), LightningSpell.class);
}
}

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,20 +87,27 @@ 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(SpellHelper.getTranslatedSpell(id, level).getString()).append("]").formatted(Formatting.GREEN);
}
public static void learnSpells(PlayerEntity player, Map<Identifier, Integer> itemSpells) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
World world = player.getEntityWorld();
Map<Identifier, Integer> playerSpells = spellPlayer.getSorceryCraftSpells();
Map<Identifier, Integer> playerSpells = spellPlayer.getDiscoveredSpells();
boolean changed = false;
@ -111,15 +123,16 @@ public class SpellTag {
playerSpells.put(spell.getID(), spell.getLevel());
assert world.getServer() != null;
Text text = new LiteralText("[").append(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel(), true).getString()).append("]").formatted(Formatting.GREEN);
world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".new_spell", player.getDisplayName(), text));
Text text = getTranslatedSpellChat(spell.getID(), spell.getLevel());
world.getServer().getPlayerManager().sendToAll(new GameMessageS2CPacket(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".discovered_spell", player.getDisplayName(), text), MessageType.CHAT, Util.NIL_UUID));
}
}
}
if (changed) {
SorceryCraft.playSpellSound(player);
spellPlayer.setSorceryCraftSpells(playerSpells);
spellPlayer.setDiscoveredSpells(playerSpells);
SorceryCraft.DISCOVER_ALL_SPELLS_CRITERION.trigger((ServerPlayerEntity) player);
}
}
}

View File

@ -5,7 +5,7 @@ import net.minecraft.util.Identifier;
import java.util.Map;
public interface SpellPlayerEntity {
void setSorceryCraftSpells(Map<Identifier, Integer> spells);
void setDiscoveredSpells(Map<Identifier, Integer> spells);
Map<Identifier, Integer> getSorceryCraftSpells();
Map<Identifier, Integer> getDiscoveredSpells();
}

View File

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

View File

@ -4,16 +4,27 @@
"itemGroup.sorcerycraft.spells": "SorceryCraft",
"container.sorcerycraft.casting_table": "Casting Table",
"container.sorcerycraft.spells": "Spells",
"chat.sorcerycraft.new_spell": "%s has learned the spell %s",
"chat.sorcerycraft.discovered_spell": "%s has discovered the spell %s",
"entity.sorcerycraft.spell": "Spell",
"command.sorcerycraft.spell.cleared_spells": "All spells cleared from %s",
"command.sorcerycraft.spell.listing_spells": "%s knows the following spells:",
"command.sorcerycraft.spell.forgotten_spell": "%s has forgotten the spell %s",
"command.sorcerycraft.spell.listing_spells": "%s has discovered the following spells: %s",
"command.sorcerycraft.spell.unknown_spell": "Unknown spell: %s",
"command.sorcerycraft.spell.not_holding_spell": "%s is not holding a Spell",
"command.sorcerycraft.spell.not_holding_spell": "%s is not holding a spell",
"command.sorcerycraft.spell.applied_spell": "Applied Spell %s",
"command.sorcerycraft.spell.removed_spell": "Removed Spell %s",
"stat.sorcerycraft.interact_with_casting_table": "Interactions with Casting Table",
"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.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",
@ -22,5 +33,6 @@
"spell.sorcerycraft.levitate_spell": "Levitate",
"spell.sorcerycraft.teleport_spell": "Teleport",
"spell.sorcerycraft.inward_spell": "Inward",
"spell.sorcerycraft.cooling_spell": "Cooling"
"spell.sorcerycraft.cooling_spell": "Cooling",
"spell.sorcerycraft.lightning_spell": "Lightning"
}

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,10 @@
"com.thebrokenrail.sorcerycraft.SorceryCraft"
],
"client": [
"com.thebrokenrail.sorcerycraft.SorceryCraft"
"com.thebrokenrail.sorcerycraft.client.SorceryCraftClient"
],
"modmenu": [
"com.thebrokenrail.sorcerycraft.client.ModMenu"
]
},
"mixins": [
@ -30,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"
],