Compare commits
No commits in common. "master" and "1.1.9" have entirely different histories.
4
.gitignore
vendored
4
.gitignore
vendored
@ -22,6 +22,4 @@ bin/
|
||||
|
||||
# fabric
|
||||
|
||||
run/
|
||||
|
||||
remappedSrc/
|
||||
run/
|
69
API.md
69
API.md
@ -4,18 +4,17 @@
|
||||
1. Add Dependency to Gradle
|
||||
```gradle
|
||||
repositories {
|
||||
maven { url 'https://maven.thebrokenrail.com' }
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
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.2.x"
|
||||
"sorcerycraft": "1.1.x"
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -25,75 +24,43 @@
|
||||
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
|
||||
// Override this if you want the spell to affect entities
|
||||
// Not required to override
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(World world, BlockHitResult hitResult) {
|
||||
// OPTIONAL
|
||||
// Called when ExampleSpell hits a block
|
||||
// Override this if you want the spell to affect blocks
|
||||
// Not required to override
|
||||
}
|
||||
|
||||
|
||||
@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 (skip this if you have overridden ```Spell.getTranslation()``)
|
||||
5. Add Spell Translation
|
||||
```json
|
||||
{
|
||||
"spell.modid.example_spell": "Example"
|
||||
@ -101,15 +68,5 @@
|
||||
```
|
||||
|
||||
## Useful Methods
|
||||
- ```(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/)
|
||||
- ```Spell.getLevel()```
|
||||
- ```Spell.getID()```
|
81
CHANGELOG.md
81
CHANGELOG.md
@ -1,83 +1,4 @@
|
||||
# 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
|
||||
### Changelog
|
||||
|
||||
**1.1.9**
|
||||
* Fix Scrolling Bug
|
||||
|
23
Jenkinsfile
vendored
23
Jenkinsfile
vendored
@ -7,32 +7,11 @@ pipeline {
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh './gradlew build javadoc'
|
||||
sh './gradlew build'
|
||||
}
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
31
README.md
31
README.md
@ -1,13 +1,13 @@
|
||||
# SorceryCraft
|
||||
Cast Spells in Minecraft!
|
||||
|
||||
This mod currently supports the Minecraft 1.16 snapshots.
|
||||
This mod 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 "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.
|
||||
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.
|
||||
|
||||
## 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 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 sometimes may require an item.
|
||||
|
||||
## Crafting
|
||||
#### Blank Spell
|
||||
@ -56,35 +56,28 @@ 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 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. |
|
||||
| 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. |
|
||||
| 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 forget <player>```
|
||||
#### ```/spell clear <player>```
|
||||
This command clears all known spells from the given player.
|
||||
|
||||
#### ```/spell forget <player> <spell-id>```
|
||||
This command clears the specified spell from the given player.
|
||||
|
||||
#### ```/spell list <player>```
|
||||
This lists all the spells the given player knows.
|
||||
|
||||
#### ```/spell discover <player>```
|
||||
This adds all spells to the specified player's discovered spells list.
|
||||
#### ```/spell learn <player> <spell-id> <level>```
|
||||
This teaches the specified spell to the specified player.
|
||||
|
||||
#### ```/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 add <player> <spell-id> <level>```
|
||||
This adds the specified spell to the item in the player's main hand.
|
||||
|
||||
#### ```/spell remove <player> <spell-id>```
|
||||
This removes the specified spell from the item in the specified player's main hand.
|
||||
This removes the specified spell from the item in the player's main hand.
|
||||
|
||||
## API
|
||||
[View API](API.md)
|
||||
|
59
build.gradle
59
build.gradle
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.4-SNAPSHOT'
|
||||
id 'fabric-loom' version '0.2.7-SNAPSHOT'
|
||||
id 'com.matthewprenger.cursegradle' version '1.4.0'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
compileJava {
|
||||
@ -10,40 +9,25 @@ compileJava {
|
||||
}
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
def mod_version = project.mod_version as Object
|
||||
version = "${mod_version}+${project.minecraft_version}"
|
||||
version = project.mod_version as Object
|
||||
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.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}"
|
||||
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}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property 'version', project.version
|
||||
inputs.property 'name', rootProject.name
|
||||
inputs.property 'version', version
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'fabric.mod.json'
|
||||
expand 'version': project.version, 'name': rootProject.name
|
||||
expand 'version': version
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
@ -66,37 +50,10 @@ 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')
|
||||
@ -107,7 +64,7 @@ if (project.hasProperty('curseforge.api_key')) {
|
||||
addGameVersion project.simple_minecraft_version
|
||||
addGameVersion 'Fabric'
|
||||
mainArtifact(remapJar) {
|
||||
displayName = "SorceryCraft v${mod_version} for ${project.minecraft_version}"
|
||||
displayName = "SorceryCraft v${version} for ${project.minecraft_version}"
|
||||
}
|
||||
afterEvaluate {
|
||||
uploadTask.dependsOn('remapJar')
|
||||
|
@ -3,20 +3,17 @@ org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version = 1.16.4
|
||||
minecraft_version = 20w10a
|
||||
curseforge_id = 365308
|
||||
simple_minecraft_version = 1.16.4
|
||||
yarn_build = 7
|
||||
fabric_loader_version = 0.10.8
|
||||
simple_minecraft_version = 1.16-Snapshot
|
||||
yarn_mappings = 20w10a+build.20
|
||||
loader_version = 0.7.8+build.187
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.2.9
|
||||
mod_version = 1.1.9
|
||||
maven_group = com.thebrokenrail
|
||||
archives_base_name = sorcerycraft
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_api_version = 0.28.1+1.16
|
||||
cloth_config_version = 4.8.3
|
||||
auto_config_version = 3.3.1
|
||||
mod_menu_version = 1.14.13+build.19
|
||||
fabric_version = 0.5.1+build.305-1.16
|
||||
|
@ -8,5 +8,3 @@ pluginManagement {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = 'SorceryCraft'
|
||||
|
@ -1,32 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,32 +1,36 @@
|
||||
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.api.registry.Spells;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
|
||||
import com.thebrokenrail.sorcerycraft.spell.registry.Spells;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
|
||||
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
|
||||
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
|
||||
import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder;
|
||||
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
|
||||
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
|
||||
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
||||
import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl;
|
||||
import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.dispenser.ProjectileDispenserBehavior;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.EntityCategory;
|
||||
import net.minecraft.entity.EntityDimensions;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.entity.projectile.Projectile;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
@ -34,12 +38,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;
|
||||
@ -49,18 +53,13 @@ import net.minecraft.world.World;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SorceryCraft implements ModInitializer {
|
||||
public class SorceryCraft implements ModInitializer, ClientModInitializer {
|
||||
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,
|
||||
@ -71,20 +70,11 @@ public class SorceryCraft implements ModInitializer {
|
||||
LootTables.JUNGLE_TEMPLE_CHEST,
|
||||
LootTables.STRONGHOLD_LIBRARY_CHEST,
|
||||
LootTables.PILLAGER_OUTPOST_CHEST,
|
||||
LootTables.WOODLAND_MANSION_CHEST,
|
||||
LootTables.BURIED_TREASURE_CHEST,
|
||||
LootTables.FISHING_TREASURE_GAMEPLAY
|
||||
LootTables.WOODLAND_MANSION_CHEST
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
public static final double SPELL_FAILURE_CHANCE = 0.3d;
|
||||
public static Identifier STAT_INTERACT_WITH_CASTING_TABLE;
|
||||
public static Identifier STAT_CAST_SPELL;
|
||||
|
||||
private boolean isSelectedLootTable(Identifier lootTable) {
|
||||
for (Identifier id : LOOT_TABLES) {
|
||||
@ -97,11 +87,8 @@ public class SorceryCraft implements ModInitializer {
|
||||
|
||||
@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))
|
||||
@ -111,7 +98,7 @@ public class SorceryCraft implements ModInitializer {
|
||||
CASTING_TABLE_BLOCK_ITEM = new BlockItem(CASTING_TABLE_BLOCK, new Item.Settings().group(ITEM_GROUP));
|
||||
SPELL_ITEM = new SpellItem();
|
||||
|
||||
SPELL_ENTITY = FabricEntityTypeBuilder.create(SpawnGroup.MISC, (EntityType.EntityFactory<SpellEntity>) SpellEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build();
|
||||
SPELL_ENTITY = FabricEntityTypeBuilder.create(EntityCategory.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);
|
||||
@ -121,28 +108,28 @@ public class SorceryCraft implements ModInitializer {
|
||||
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).createScreenHandlerFactory(player.world, pos)).createMenu(syncId, player.inventory, player);
|
||||
return Objects.requireNonNull(world.getBlockState(pos).createContainerFactory(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()
|
||||
.rolls(new BinomialLootTableRange(2, 0.5f))
|
||||
.withEntry(ItemEntry.builder(SPELL_ITEM).build())
|
||||
.withFunction(new RandomSpellLootTableFunction.Builder().build());
|
||||
.withRolls(new BinomialLootTableRange(2, 0.5f))
|
||||
.withEntry(ItemEntry.builder(SPELL_ITEM))
|
||||
.withFunction(new RandomSpellLootTableFunction.Builder());
|
||||
|
||||
supplier.withPool(poolBuilder.build());
|
||||
supplier.withPool(poolBuilder);
|
||||
}
|
||||
});
|
||||
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 ProjectileEntity createProjectile(World position, Position stack, ItemStack itemStack) {
|
||||
protected Projectile createProjectile(World position, Position stack, ItemStack itemStack) {
|
||||
SpellEntity entity = new SpellEntity(position, stack.getX(), stack.getY(), stack.getZ());
|
||||
entity.setItem(itemStack);
|
||||
return entity;
|
||||
@ -154,16 +141,13 @@ public class SorceryCraft implements ModInitializer {
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
STAT_INTERACT_WITH_CASTING_TABLE = registerStat("interact_with_casting_table");
|
||||
STAT_CAST_SPELL = registerStat("cast_spell");
|
||||
}
|
||||
|
||||
private Identifier registerStat(String name) {
|
||||
Identifier statID = new Identifier(NAMESPACE, name);
|
||||
Registry.register(Registry.CUSTOM_STAT, statID, statID);
|
||||
Registry.register(Registry.CUSTOM_STAT, name, statID);
|
||||
Stats.CUSTOM.getOrCreateStat(statID, StatFormatter.DEFAULT);
|
||||
return statID;
|
||||
}
|
||||
@ -181,4 +165,13 @@ public class SorceryCraft implements ModInitializer {
|
||||
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"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,14 @@
|
||||
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.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandlerContext;
|
||||
import net.minecraft.screen.BlockContext;
|
||||
import net.minecraft.screen.NameableScreenHandlerFactory;
|
||||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@ -30,18 +28,13 @@ 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.INTERACT_WITH_CASTING_TABLE_STAT);
|
||||
player.incrementStat(SorceryCraft.STAT_INTERACT_WITH_CASTING_TABLE);
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
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"));
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,20 @@
|
||||
package com.thebrokenrail.sorcerycraft.gui;
|
||||
package com.thebrokenrail.sorcerycraft.block;
|
||||
|
||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
||||
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
||||
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;
|
||||
@ -28,14 +27,14 @@ import java.util.function.BiConsumer;
|
||||
public class CastingTableScreenHandler extends ScreenHandler {
|
||||
private final Inventory inventory;
|
||||
private final Inventory result;
|
||||
private Spell[] spells = new Spell[0];
|
||||
private final ScreenHandlerContext context;
|
||||
private final Spell[] spells;
|
||||
private final BlockContext context;
|
||||
private int index = 0;
|
||||
|
||||
public CastingTableScreenHandler(int syncId, PlayerInventory playerInventory, ScreenHandlerContext blockContext) {
|
||||
public CastingTableScreenHandler(int syncId, PlayerInventory playerInventory, BlockContext blockContext) {
|
||||
super(ScreenHandlerType.STONECUTTER, syncId);
|
||||
|
||||
inventory = new SimpleInventory(2) {
|
||||
inventory = new BasicInventory(2) {
|
||||
public void markDirty() {
|
||||
super.markDirty();
|
||||
CastingTableScreenHandler.this.onContentChanged(this);
|
||||
@ -44,7 +43,21 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
context = blockContext;
|
||||
result = new CraftingResultInventory();
|
||||
|
||||
setSpells(playerInventory.player);
|
||||
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]);
|
||||
}
|
||||
|
||||
addSlot(new Slot(inventory, 0, 136, 37) {
|
||||
@Override
|
||||
@ -53,7 +66,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemCount() {
|
||||
public int getMaxStackAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -84,15 +97,10 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
player.addExperienceLevels(-spells[index].getXPCost());
|
||||
}
|
||||
|
||||
context.run((world, blockPos) -> {
|
||||
SorceryCraft.playSpellSound(world, blockPos);
|
||||
if (!world.isClient()) {
|
||||
SorceryCraft.CREATE_SPELL_CRITERION.trigger((ServerPlayerEntity) player);
|
||||
}
|
||||
});
|
||||
context.run((BiConsumer<World, BlockPos>) SorceryCraft::playSpellSound);
|
||||
|
||||
CastingTableScreenHandler.this.inventory.setStack(0, ItemStack.EMPTY);
|
||||
CastingTableScreenHandler.this.inventory.removeStack(1, spells[index].getItemCost().getCount());
|
||||
CastingTableScreenHandler.this.inventory.setInvStack(0, ItemStack.EMPTY);
|
||||
CastingTableScreenHandler.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount());
|
||||
return stack;
|
||||
}
|
||||
});
|
||||
@ -109,30 +117,6 @@ 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();
|
||||
}
|
||||
@ -141,7 +125,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
this.index = index;
|
||||
onContentChanged(inventory);
|
||||
|
||||
if (inventory.getStack(0).isEmpty() && inventory.getStack(1).isEmpty()) {
|
||||
if (inventory.getInvStack(0).isEmpty() && inventory.getInvStack(1).isEmpty()) {
|
||||
ItemStack spellItem = new ItemStack(SorceryCraft.SPELL_ITEM);
|
||||
autoFill(0, spellItem, true);
|
||||
ItemStack paymentItem = getRecipes()[index].getItemCost();
|
||||
@ -198,22 +182,22 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
@Override
|
||||
public void onContentChanged(Inventory inventory) {
|
||||
super.onContentChanged(inventory);
|
||||
ItemStack item = inventory.getStack(0);
|
||||
ItemStack cost = inventory.getStack(1);
|
||||
ItemStack item = inventory.getInvStack(0);
|
||||
ItemStack cost = inventory.getInvStack(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 = SpellHelper.getSpells(resultItem);
|
||||
Map<Identifier, Integer> resultSpells = SpellTag.getSpells(resultItem);
|
||||
if (!resultSpells.containsKey(spells[index].getID()) || resultSpells.get(spells[index].getID()) <= spells[index].getLevel()) {
|
||||
resultSpells.put(spells[index].getID(), spells[index].getLevel());
|
||||
}
|
||||
SpellHelper.setSpells(resultItem, resultSpells);
|
||||
result.setStack(2, resultItem);
|
||||
SpellTag.setSpells(resultItem, resultSpells);
|
||||
result.setInvStack(2, resultItem);
|
||||
} else {
|
||||
result.setStack(2, ItemStack.EMPTY);
|
||||
result.setInvStack(2, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,14 +207,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.getStack(slot);
|
||||
ItemStack invSlot = inventory.getInvStack(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.setStack(slot, modifiedItem);
|
||||
inventory.setInvStack(slot, modifiedItem);
|
||||
if (totalCount >= stack.getMaxCount() || onlyOne) {
|
||||
break;
|
||||
}
|
||||
@ -245,7 +229,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Spell[] getRecipes() {
|
@ -1,24 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,30 +1,29 @@
|
||||
package com.thebrokenrail.sorcerycraft.client.gui;
|
||||
package com.thebrokenrail.sorcerycraft.client.block;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
|
||||
import com.thebrokenrail.sorcerycraft.block.CastingTableScreenHandler;
|
||||
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.ingame.ScreenWithHandler;
|
||||
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 HandledScreen<CastingTableScreenHandler> {
|
||||
public class CastingTableScreen extends ScreenWithHandler<CastingTableScreenHandler> {
|
||||
private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png");
|
||||
private int selectedIndex = 0;
|
||||
private int indexStartOffset = 0;
|
||||
private boolean scrolling = false;
|
||||
private int selectedIndex;
|
||||
private int indexStartOffset;
|
||||
private boolean scrolling;
|
||||
|
||||
public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) {
|
||||
super(container, inventory, title);
|
||||
@ -32,52 +31,47 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawForeground(MatrixStack matrixStack, int i, int j) {
|
||||
protected void drawForeground(int mouseX, int mouseY) {
|
||||
int titleY = backgroundHeight - 94;
|
||||
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;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(MatrixStack matrixStack, float delta, int mouseX, int mouseY) {
|
||||
protected void drawBackground(float delta, int mouseX, int mouseY) {
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
assert client != null;
|
||||
client.getTextureManager().bindTexture(TEXTURE);
|
||||
int i = (width - backgroundWidth) / 2;
|
||||
int j = (height - backgroundHeight) / 2;
|
||||
drawTexture(matrixStack, i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512);
|
||||
blit(i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) {
|
||||
renderBackground(matrixStack);
|
||||
super.render(matrixStack, mouseX, mouseY, delta);
|
||||
drawMouseoverTooltip(matrixStack, mouseX, mouseY);
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
renderBackground();
|
||||
super.render(mouseX, mouseY, delta);
|
||||
drawMouseoverTooltip(mouseX, mouseY);
|
||||
|
||||
renderScrollbar(matrixStack);
|
||||
renderScrollbar();
|
||||
renderItems();
|
||||
|
||||
for (WidgetButtonPage button : buttons) {
|
||||
if (button.isHovered()) {
|
||||
button.renderToolTip(matrixStack, mouseX, mouseY);
|
||||
button.renderToolTip(mouseX, mouseY);
|
||||
}
|
||||
button.visible = button.index < handler.getRecipes().length;
|
||||
if (button.visible) {
|
||||
Spell spell = handler.getRecipes()[button.getIndex() + indexStartOffset];
|
||||
button.setMessage(SpellHelper.getTranslatedSpell(spell.getID(), spell.getLevel()));
|
||||
button.setMessage(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel(), true).getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void renderScrollbar(MatrixStack matrixStack) {
|
||||
private void renderScrollbar() {
|
||||
Spell[] spells = handler.getRecipes();
|
||||
assert client != null;
|
||||
client.getTextureManager().bindTexture(TEXTURE);
|
||||
@ -87,9 +81,9 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
|
||||
|
||||
if (k > 0) {
|
||||
int modifier = (int) (((float) indexStartOffset / k) * (1 + 139 - 27));
|
||||
drawTexture(matrixStack, i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
|
||||
blit(i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
|
||||
} else {
|
||||
drawTexture(matrixStack, i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
|
||||
blit(i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +99,7 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
|
||||
itemRenderer.zOffset = 100.0F;
|
||||
int y = k + 2;
|
||||
|
||||
itemRenderer.renderInGuiWithOverrides(itemStack, i + 5 + 68, y);
|
||||
itemRenderer.renderGuiItem(itemStack, i + 5 + 68, y);
|
||||
itemRenderer.renderGuiItemOverlay(textRenderer, itemStack, i + 5 + 68, y);
|
||||
itemRenderer.zOffset = 0.0F;
|
||||
k += 20;
|
||||
@ -113,21 +107,21 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
|
||||
}
|
||||
}
|
||||
|
||||
private void renderXPCost(MatrixStack matrixStack) {
|
||||
private void renderXPCost() {
|
||||
if (handler.getRecipes().length > 0) {
|
||||
int cost = handler.getRecipes()[selectedIndex].getXPCost();
|
||||
int color = 8453920;
|
||||
assert client != null;
|
||||
assert client.player != null;
|
||||
Text string = new TranslatableText("container.repair.cost", cost);
|
||||
String string = new TranslatableText("container.repair.cost", cost).getString();
|
||||
if (!handler.canTakeResult(playerInventory.player)) {
|
||||
color = 16736352;
|
||||
}
|
||||
|
||||
int x2 = backgroundWidth - 8;
|
||||
int x1 = x2 - textRenderer.getWidth(string);
|
||||
fill(matrixStack, x1, 65, x2, 77, 1325400064);
|
||||
textRenderer.drawWithShadow(matrixStack, string, (float) x1, 67.0F, color);
|
||||
int x1 = x2 - textRenderer.getStringWidth(string);
|
||||
fill(x1, 65, x2, 77, 1325400064);
|
||||
textRenderer.drawWithShadow(string, (float) x1, 67.0F, color);
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +132,7 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
|
||||
@Override
|
||||
public boolean mouseScrolled(double d, double e, double amount) {
|
||||
int i = handler.getRecipes().length;
|
||||
if (canScroll(i)) {
|
||||
if (this.canScroll(i)) {
|
||||
int j = i - 7;
|
||||
indexStartOffset = (int) ((double) indexStartOffset - amount);
|
||||
indexStartOffset = MathHelper.clamp(indexStartOffset, 0, j);
|
||||
@ -200,32 +194,37 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class WidgetButtonPage extends ButtonWidget {
|
||||
private class WidgetButtonPage extends ButtonWidget {
|
||||
final int index;
|
||||
|
||||
public WidgetButtonPage(int i, int j, int k, PressAction pressAction) {
|
||||
super(i, j, 89, 20, new LiteralText(""), pressAction);
|
||||
super(i, j, 89, 20, "", pressAction);
|
||||
index = k;
|
||||
visible = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) {
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
active = (index + CastingTableScreen.this.indexStartOffset) != CastingTableScreen.this.selectedIndex;
|
||||
super.render(matrixStack, mouseX, mouseY, delta);
|
||||
super.render(mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public void renderToolTip(MatrixStack matrixStack, int mouseX, int mouseY) {
|
||||
public void renderToolTip(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(matrixStack, itemStack, mouseX, mouseY);
|
||||
renderTooltip(itemStack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawCenteredString(TextRenderer textRenderer, String str, int centerX, int y, int color) {
|
||||
drawString(textRenderer, str, x + 5, y, color);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.api.registry.SpellRegistry;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -4,21 +4,17 @@ 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 net.minecraft.command.argument.EntityArgumentType;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
||||
import net.minecraft.command.arguments.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;
|
||||
|
||||
@ -27,147 +23,94 @@ public class SpellCommand {
|
||||
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(CommandManager.literal("spell")
|
||||
.requires(source -> source.hasPermissionLevel(2))
|
||||
.requires(source -> source.hasPermissionLevel(4))
|
||||
.then(CommandManager.literal("list")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.executes(ctx -> {
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
return i;
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("forget")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.then(CommandManager.literal("clear")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.executes(ctx -> {
|
||||
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;
|
||||
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;
|
||||
})
|
||||
.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("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.literal("learn")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
||||
.executes(ctx -> {
|
||||
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;
|
||||
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;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("apply")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.then(CommandManager.literal("add")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
||||
.executes(ctx -> {
|
||||
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;
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||
}
|
||||
return i;
|
||||
|
||||
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;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("remove")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.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");
|
||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||
}
|
||||
return i;
|
||||
|
||||
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;
|
||||
})
|
||||
)
|
||||
)
|
||||
|
@ -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.api.registry.SpellRegistry;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||
import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells;
|
||||
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
||||
import com.thebrokenrail.sorcerycraft.spell.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.projectile.thrown.ThrownItemEntity;
|
||||
import net.minecraft.entity.thrown.ThrownItemEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
|
||||
@ -28,7 +28,6 @@ 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);
|
||||
@ -42,19 +41,14 @@ public class SpellEntity extends ThrownItemEntity {
|
||||
super(SorceryCraft.SPELL_ENTITY, x, y, z, world);
|
||||
}
|
||||
|
||||
public SpellEntity(World world) {
|
||||
super(SorceryCraft.SPELL_ENTITY, world);
|
||||
}
|
||||
|
||||
private boolean didSpellSucceed(Map<Identifier, Integer> spells) {
|
||||
return Math.random() > SorceryCraft.getConfig().failureChance || spells.containsKey(Spells.STEADFAST_SPELL);
|
||||
return Math.random() > SorceryCraft.SPELL_FAILURE_CHANCE || spells.containsKey(Spells.STEADFAST_SPELL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCollision(HitResult hitResult) {
|
||||
super.onCollision(hitResult);
|
||||
if (!getEntityWorld().isClient()) {
|
||||
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
|
||||
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
|
||||
if (!spells.containsKey(Spells.INWARD_SPELL)) {
|
||||
boolean success = didSpellSucceed(spells);
|
||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||
@ -86,7 +80,7 @@ public class SpellEntity extends ThrownItemEntity {
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!getEntityWorld().isClient()) {
|
||||
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
|
||||
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
|
||||
if (spells.containsKey(Spells.INWARD_SPELL)) {
|
||||
if (getOwner() != null) {
|
||||
boolean success = didSpellSucceed(spells);
|
||||
|
@ -3,22 +3,21 @@ 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.api.registry.SpellRegistry;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
||||
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;
|
||||
@ -34,10 +33,10 @@ public class SpellItem extends Item {
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
|
||||
ItemStack itemStack = playerEntity.getStackInHand(hand);
|
||||
|
||||
if (!world.isClient()) {
|
||||
SorceryCraft.playSpellSound(playerEntity);
|
||||
SorceryCraft.playSpellSound(playerEntity);
|
||||
|
||||
playerEntity.incrementStat(SorceryCraft.CAST_SPELL_STAT);
|
||||
if (!world.isClient()) {
|
||||
playerEntity.incrementStat(SorceryCraft.STAT_CAST_SPELL);
|
||||
|
||||
SpellEntity entity = new SpellEntity(world, playerEntity);
|
||||
entity.setItem(itemStack);
|
||||
@ -53,22 +52,16 @@ public class SpellItem extends Item {
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
public boolean hasEnchantmentGlint(ItemStack stack) {
|
||||
Map<Identifier, Integer> spells = SpellTag.getSpells(stack);
|
||||
return spells.size() > 0 || super.hasEnchantmentGlint(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
|
||||
Map<Identifier, Integer> spells = SpellHelper.getSpells(itemStack);
|
||||
Map<Identifier, Integer> spells = SpellTag.getSpells(itemStack);
|
||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||
tooltip.add(SpellHelper.getTranslatedSpell(entry.getKey(), entry.getValue()));
|
||||
tooltip.add(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue(), true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +74,7 @@ public class SpellItem extends Item {
|
||||
ItemStack item = new ItemStack(this);
|
||||
Map<Identifier, Integer> spell = new HashMap<>();
|
||||
spell.put(value.getID(), value.getLevel());
|
||||
SpellHelper.setSpells(item, spell);
|
||||
SpellTag.setSpells(item, spell);
|
||||
stacks.add(item);
|
||||
}
|
||||
}
|
||||
@ -97,9 +90,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 = SpellHelper.getSpells(player.inventory.getStack(slot));
|
||||
Map<Identifier, Integer> itemSpells = SpellTag.getSpells(player.inventory.getInvStack(slot));
|
||||
|
||||
SpellHelper.learnSpells(player, itemSpells);
|
||||
SpellTag.learnSpells(player, itemSpells);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,8 +2,6 @@ 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;
|
||||
@ -16,14 +14,13 @@ 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 info) {
|
||||
public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo callbackInfo) {
|
||||
EntityType<?> entityType = packet.getEntityTypeId();
|
||||
Entity entity = null;
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,11 @@
|
||||
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;
|
||||
@ -20,32 +16,25 @@ import java.util.Map;
|
||||
@SuppressWarnings("unused")
|
||||
@Mixin(PlayerEntity.class)
|
||||
public class MixinPlayerEntity implements SpellPlayerEntity {
|
||||
@Shadow
|
||||
public ScreenHandler currentScreenHandler;
|
||||
@Unique
|
||||
private Map<Identifier, Integer> discoveredSpells = new HashMap<>();
|
||||
private Map<Identifier, Integer> sorceryCraftSpells = new HashMap<>();
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
|
||||
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
||||
discoveredSpells = SpellHelper.getSpells(tag);
|
||||
sorceryCraftSpells = SpellTag.getSpells(tag);
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "writeCustomDataToTag")
|
||||
public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) {
|
||||
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(discoveredSpells));
|
||||
tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(sorceryCraftSpells));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
|
||||
discoveredSpells = spells;
|
||||
if (currentScreenHandler instanceof CastingTableScreenHandler) {
|
||||
//noinspection ConstantConditions
|
||||
((CastingTableScreenHandler) currentScreenHandler).setSpells((PlayerEntity) (Object) this);
|
||||
}
|
||||
public void setSorceryCraftSpells(Map<Identifier, Integer> spells) {
|
||||
this.sorceryCraftSpells = spells;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Identifier, Integer> getDiscoveredSpells() {
|
||||
return discoveredSpells;
|
||||
public Map<Identifier, Integer> getSorceryCraftSpells() {
|
||||
return sorceryCraftSpells;
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,30 @@
|
||||
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.SpellServerPlayerEntity;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
||||
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 extends MixinPlayerEntity implements SpellServerPlayerEntity {
|
||||
public abstract class MixinServerPlayerEntity implements SpellPlayerEntity {
|
||||
@Inject(at = @At("HEAD"), method = "copyFrom")
|
||||
public void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
|
||||
public void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo ci) {
|
||||
SpellPlayerEntity oldSpellPlayer = (SpellPlayerEntity) oldPlayer;
|
||||
SpellPlayerEntity newSpellPlayer = this;
|
||||
|
||||
newSpellPlayer.setDiscoveredSpells(oldSpellPlayer.getDiscoveredSpells());
|
||||
newSpellPlayer.setSorceryCraftSpells(oldSpellPlayer.getSorceryCraftSpells());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
|
||||
super.setDiscoveredSpells(spells);
|
||||
if (currentScreenHandler instanceof CastingTableScreenHandler) {
|
||||
sync();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync() {
|
||||
@Inject(at = @At("HEAD"), method = "playerTick")
|
||||
public void playerTick(CallbackInfo ignored) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(getDiscoveredSpells()));
|
||||
tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(getSorceryCraftSpells()));
|
||||
//noinspection ConstantConditions
|
||||
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.thebrokenrail.sorcerycraft.packet;
|
||||
|
||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
|
||||
import com.thebrokenrail.sorcerycraft.block.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) {
|
||||
@ -22,7 +20,6 @@ public class SelectSpellC2SPacket {
|
||||
}
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static void send(MinecraftClient minecraft, int index) {
|
||||
PacketByteBuf bytes = new PacketByteBuf(Unpooled.buffer());
|
||||
bytes.writeInt(index);
|
||||
|
@ -2,24 +2,21 @@ package com.thebrokenrail.sorcerycraft.packet;
|
||||
|
||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.network.PacketContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.PacketByteBuf;
|
||||
|
||||
public class UpdateKnownSpellsS2CPacket {
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static void handle(PacketContext context, PacketByteBuf bytes) {
|
||||
CompoundTag tag = bytes.readCompoundTag();
|
||||
if (context.getPlayer() != null) {
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer();
|
||||
spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag));
|
||||
spellPlayer.setSorceryCraftSpells(SpellTag.getSpells(tag));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ 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;
|
||||
@ -24,22 +23,19 @@ 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).isIn(BlockTags.FIRE)) {
|
||||
if (world.getBlockState(blockPos).matches(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).isIn(BlockTags.FIRE)) {
|
||||
if (world.getBlockState(sideBlockPos).matches(BlockTags.FIRE)) {
|
||||
world.removeBlock(sideBlockPos, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXPCost() {
|
||||
return 10;
|
||||
return 13;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,10 +25,10 @@ public class DamageSpell extends Spell {
|
||||
public int getXPCost() {
|
||||
switch (getLevel()) {
|
||||
case 0: {
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
case 1: {
|
||||
return 8;
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
@ -22,7 +22,7 @@ public class DissolveSpell extends Spell {
|
||||
|
||||
@Override
|
||||
public int getXPCost() {
|
||||
return 8;
|
||||
return 12;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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) {
|
||||
if (attacker instanceof LivingEntity) {
|
||||
((LivingEntity) attacker).onAttacking(target);
|
||||
}
|
||||
target.setOnFireFor(8 + (getLevel() * 4));
|
||||
target.setFireTicks(400 + (getLevel() * 200));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
|
||||
Items.FLINT_AND_STEEL.useOnBlock(new AutomaticItemPlacementContext(world, hitResult.getBlockPos(), hitResult.getSide().getOpposite(), new ItemStack(Items.FLINT_AND_STEEL), hitResult.getSide()));
|
||||
BlockPos blockPos = hitResult.getBlockPos().offset(hitResult.getSide());
|
||||
if (world.isAir(blockPos)) {
|
||||
world.setBlockState(blockPos, AbstractFireBlock.getState(world, blockPos));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,7 +35,7 @@ public class FlameSpell extends Spell {
|
||||
return 8;
|
||||
}
|
||||
case 1: {
|
||||
return 12;
|
||||
return 16;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
@ -25,10 +25,10 @@ public class HealSpell extends Spell {
|
||||
public int getXPCost() {
|
||||
switch (getLevel()) {
|
||||
case 0: {
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
case 1: {
|
||||
return 8;
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
@ -29,7 +29,7 @@ public class LevitateSpell extends Spell {
|
||||
return 12;
|
||||
}
|
||||
case 1: {
|
||||
return 24;
|
||||
return 21;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
@ -1,56 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ public class TeleportSpell extends Spell {
|
||||
}
|
||||
|
||||
private int getMaxTeleport(World world) {
|
||||
return world.getRegistryKey() != World.OVERWORLD ? 128 : 256;
|
||||
return world.getDimension().isNether() ? 128 : 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,9 +57,6 @@ public class TeleportSpell extends Spell {
|
||||
case 1: {
|
||||
return 18;
|
||||
}
|
||||
case 2: {
|
||||
return 24;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -73,15 +70,12 @@ 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 3;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,11 @@
|
||||
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;
|
||||
@ -22,7 +16,7 @@ public abstract class Spell {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of this spell
|
||||
* Get the ID of this Spell
|
||||
* @return The Spell ID
|
||||
*/
|
||||
public Identifier getID() {
|
||||
@ -30,18 +24,18 @@ public abstract class Spell {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level of this spell
|
||||
* @return The Spell's Level
|
||||
* Get the level of this Spell
|
||||
* @return The Spell 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) {
|
||||
@ -49,10 +43,10 @@ public abstract class Spell {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute this spell on a block
|
||||
* Cast 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) {
|
||||
@ -60,42 +54,20 @@ public abstract class Spell {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of levels required to make this spell in a Casting Table
|
||||
* Get the amount of levels required to make this Spell in a Casting Table
|
||||
* @return The XP cost
|
||||
*/
|
||||
public abstract int getXPCost();
|
||||
|
||||
/**
|
||||
* Get the item(s) required to make this spell in a Casting Table, or ItemStack.EMPTY if an item is not required
|
||||
* Get the item(s) required to make ExampleSpell 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 Spell's Max Level
|
||||
* Get the maximum level of this Spell
|
||||
* @return The 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());
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.thebrokenrail.sorcerycraft.spell.api.registry;
|
||||
package com.thebrokenrail.sorcerycraft.spell.registry;
|
||||
|
||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
||||
import net.minecraft.util.Identifier;
|
||||
@ -9,28 +9,13 @@ 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;
|
||||
@ -43,11 +28,6 @@ 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) {
|
||||
@ -56,10 +36,6 @@ 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()) {
|
||||
@ -77,22 +53,6 @@ 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
|
||||
@ -104,10 +64,6 @@ 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]);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.thebrokenrail.sorcerycraft.spell.api.registry;
|
||||
package com.thebrokenrail.sorcerycraft.spell.registry;
|
||||
|
||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||
import com.thebrokenrail.sorcerycraft.spell.CoolingSpell;
|
||||
@ -8,14 +8,10 @@ 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;
|
||||
@ -27,7 +23,6 @@ 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);
|
||||
@ -39,6 +34,5 @@ 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);
|
||||
}
|
||||
}
|
@ -1,18 +1,13 @@
|
||||
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.api.registry.SpellRegistry;
|
||||
import com.thebrokenrail.sorcerycraft.spell.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;
|
||||
|
||||
@ -26,30 +21,14 @@ 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 = SpellHelper.getSpells(stack);
|
||||
Map<Identifier, Integer> spell = SpellTag.getSpells(stack);
|
||||
spell.put(spells[index].getID(), spells[index].getLevel());
|
||||
SpellHelper.setSpells(stack, spell);
|
||||
SpellTag.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() {
|
||||
|
@ -5,7 +5,7 @@ import net.minecraft.util.Identifier;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SpellPlayerEntity {
|
||||
void setDiscoveredSpells(Map<Identifier, Integer> spells);
|
||||
void setSorceryCraftSpells(Map<Identifier, Integer> spells);
|
||||
|
||||
Map<Identifier, Integer> getDiscoveredSpells();
|
||||
Map<Identifier, Integer> getSorceryCraftSpells();
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package com.thebrokenrail.sorcerycraft.spell.util;
|
||||
|
||||
public interface SpellServerPlayerEntity extends SpellPlayerEntity {
|
||||
void sync();
|
||||
}
|
@ -2,28 +2,23 @@ package com.thebrokenrail.sorcerycraft.spell.util;
|
||||
|
||||
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.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 SpellHelper {
|
||||
public class SpellTag {
|
||||
public static final String SPELL_TAG = "Spells";
|
||||
|
||||
public static void setSpells(ItemStack itemStack, Map<Identifier, Integer> map) {
|
||||
@ -87,27 +82,20 @@ public class SpellHelper {
|
||||
return map;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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)));
|
||||
}
|
||||
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.getDiscoveredSpells();
|
||||
Map<Identifier, Integer> playerSpells = spellPlayer.getSorceryCraftSpells();
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
@ -123,16 +111,15 @@ public class SpellHelper {
|
||||
|
||||
playerSpells.put(spell.getID(), spell.getLevel());
|
||||
assert world.getServer() != null;
|
||||
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));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
SorceryCraft.playSpellSound(player);
|
||||
spellPlayer.setDiscoveredSpells(playerSpells);
|
||||
SorceryCraft.DISCOVER_ALL_SPELLS_CRITERION.trigger((ServerPlayerEntity) player);
|
||||
spellPlayer.setSorceryCraftSpells(playerSpells);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,27 +4,16 @@
|
||||
"itemGroup.sorcerycraft.spells": "SorceryCraft",
|
||||
"container.sorcerycraft.casting_table": "Casting Table",
|
||||
"container.sorcerycraft.spells": "Spells",
|
||||
"chat.sorcerycraft.discovered_spell": "%s has discovered the spell %s",
|
||||
"chat.sorcerycraft.new_spell": "%s has learned the spell %s",
|
||||
"entity.sorcerycraft.spell": "Spell",
|
||||
"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.cleared_spells": "All spells cleared from %s",
|
||||
"command.sorcerycraft.spell.listing_spells": "%s knows the following spells:",
|
||||
"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",
|
||||
@ -33,6 +22,5 @@
|
||||
"spell.sorcerycraft.levitate_spell": "Levitate",
|
||||
"spell.sorcerycraft.teleport_spell": "Teleport",
|
||||
"spell.sorcerycraft.inward_spell": "Inward",
|
||||
"spell.sorcerycraft.cooling_spell": "Cooling",
|
||||
"spell.sorcerycraft.lightning_spell": "Lightning"
|
||||
"spell.sorcerycraft.cooling_spell": "Cooling"
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
"schemaVersion": 1,
|
||||
"id": "sorcerycraft",
|
||||
"version": "${version}",
|
||||
"name": "${name}",
|
||||
"name": "SorceryCraft",
|
||||
"description": "Cast Spells in Minecraft!",
|
||||
"authors": [
|
||||
"TheBrokenRail"
|
||||
@ -20,10 +20,7 @@
|
||||
"com.thebrokenrail.sorcerycraft.SorceryCraft"
|
||||
],
|
||||
"client": [
|
||||
"com.thebrokenrail.sorcerycraft.client.SorceryCraftClient"
|
||||
],
|
||||
"modmenu": [
|
||||
"com.thebrokenrail.sorcerycraft.client.ModMenu"
|
||||
"com.thebrokenrail.sorcerycraft.SorceryCraft"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
@ -33,11 +30,5 @@
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "curseforge",
|
||||
"projectID": 365308
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,9 @@
|
||||
"package": "com.thebrokenrail.sorcerycraft.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"MixinClientPlayerEntity",
|
||||
"MixinClientPlayNetworkHandler",
|
||||
"MixinAbstractButtonWidget"
|
||||
"MixinClientPlayNetworkHandler"
|
||||
],
|
||||
"mixins": [
|
||||
"CriteriaRegistryHook",
|
||||
"MixinPlayerEntity",
|
||||
"MixinServerPlayerEntity"
|
||||
],
|
||||
|
Reference in New Issue
Block a user