Tweak Loot Tables Fix Dispenser Bugs Fix Inward Bugs
This commit is contained in:
parent
cdaac350db
commit
28fa7115c6
@ -1,5 +1,10 @@
|
|||||||
### Changelog
|
### Changelog
|
||||||
|
|
||||||
|
**1.0.3**
|
||||||
|
* Tweak Loot Tables
|
||||||
|
* Fix Dispenser Bugs
|
||||||
|
* Fix Inward Bugs
|
||||||
|
|
||||||
**1.0.2**
|
**1.0.2**
|
||||||
* Add Inward Spell
|
* Add Inward Spell
|
||||||
* Tweak Rebound Mechanic
|
* Tweak Rebound Mechanic
|
||||||
|
38
build.gradle
38
build.gradle
@ -1,14 +1,15 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '0.2.6-SNAPSHOT'
|
id 'fabric-loom' version '0.2.6-SNAPSHOT'
|
||||||
id 'maven-publish'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
compileJava {
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
archivesBaseName = project.archives_base_name
|
archivesBaseName = project.archives_base_name
|
||||||
version = project.mod_version
|
version = project.mod_version as Object
|
||||||
group = project.maven_group
|
group = project.maven_group as Object
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
}
|
}
|
||||||
@ -22,11 +23,13 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", version
|
||||||
|
inputs.property "modid", archivesBaseName
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
include "fabric.mod.json"
|
include "fabric.mod.json"
|
||||||
expand "version": project.version
|
expand "version": version
|
||||||
|
expand "modid": archivesBaseName
|
||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
@ -52,24 +55,3 @@ task sourcesJar(type: Jar, dependsOn: classes) {
|
|||||||
jar {
|
jar {
|
||||||
from "LICENSE"
|
from "LICENSE"
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the maven publication
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
mavenJava(MavenPublication) {
|
|
||||||
// add all the jars that should be included when publishing to maven
|
|
||||||
artifact(remapJar) {
|
|
||||||
builtBy remapJar
|
|
||||||
}
|
|
||||||
artifact(sourcesJar) {
|
|
||||||
builtBy remapSourcesJar
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// select the repositories you want to publish to
|
|
||||||
repositories {
|
|
||||||
// uncomment to publish to the local maven
|
|
||||||
// mavenLocal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -8,7 +8,7 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
loader_version = 0.7.8+build.184
|
loader_version = 0.7.8+build.184
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.2
|
mod_version = 1.0.3
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
archives_base_name = sorcerycraft
|
archives_base_name = sorcerycraft
|
||||||
|
|
||||||
|
@ -7,11 +7,10 @@ import com.thebrokenrail.sorcerycraft.client.entity.SpellEntityRenderer;
|
|||||||
import com.thebrokenrail.sorcerycraft.command.SpellCommand;
|
import com.thebrokenrail.sorcerycraft.command.SpellCommand;
|
||||||
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.item.SpellItem;
|
import com.thebrokenrail.sorcerycraft.item.SpellItem;
|
||||||
import com.thebrokenrail.sorcerycraft.packet.LearnedNewSpellS2CPacket;
|
|
||||||
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
||||||
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
|
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.RandomSpellLootTableFunction;
|
import com.thebrokenrail.sorcerycraft.spell.RandomSpellLootTableFunction;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
import com.thebrokenrail.sorcerycraft.spell.Spells;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||||
@ -39,6 +38,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.loot.BinomialLootTableRange;
|
import net.minecraft.loot.BinomialLootTableRange;
|
||||||
import net.minecraft.loot.LootTables;
|
import net.minecraft.loot.LootTables;
|
||||||
import net.minecraft.loot.entry.ItemEntry;
|
import net.minecraft.loot.entry.ItemEntry;
|
||||||
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvent;
|
import net.minecraft.sound.SoundEvent;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
@ -69,7 +69,7 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
|
|||||||
LootTables.STRONGHOLD_LIBRARY_CHEST
|
LootTables.STRONGHOLD_LIBRARY_CHEST
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final double SPELL_FAILURE_CHANCE = 0.3;
|
public static final double SPELL_FAILURE_CHANCE = 0.3d;
|
||||||
|
|
||||||
private boolean isSelectedLootTable(Identifier lootTable) {
|
private boolean isSelectedLootTable(Identifier lootTable) {
|
||||||
for (Identifier id : LOOT_TABLES) {
|
for (Identifier id : LOOT_TABLES) {
|
||||||
@ -82,6 +82,8 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
new Spells();
|
||||||
|
|
||||||
ITEM_GROUP = FabricItemGroupBuilder.create(
|
ITEM_GROUP = FabricItemGroupBuilder.create(
|
||||||
new Identifier(NAMESPACE, "spells"))
|
new Identifier(NAMESPACE, "spells"))
|
||||||
.icon(() -> new ItemStack(SPELL_ITEM))
|
.icon(() -> new ItemStack(SPELL_ITEM))
|
||||||
@ -98,8 +100,6 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
|
|||||||
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "casting_table"), CASTING_TABLE_BLOCK_ITEM);
|
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "casting_table"), CASTING_TABLE_BLOCK_ITEM);
|
||||||
Registry.register(Registry.ENTITY_TYPE, new Identifier(NAMESPACE, "spell"), SPELL_ENTITY);
|
Registry.register(Registry.ENTITY_TYPE, new Identifier(NAMESPACE, "spell"), SPELL_ENTITY);
|
||||||
|
|
||||||
SpellRegistry.init();
|
|
||||||
|
|
||||||
ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (syncId, identifier, player, buf) -> {
|
ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (syncId, identifier, player, buf) -> {
|
||||||
final World world = player.world;
|
final World world = player.world;
|
||||||
final BlockPos pos = buf.readBlockPos();
|
final BlockPos pos = buf.readBlockPos();
|
||||||
@ -110,7 +110,6 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
|
|||||||
|
|
||||||
ServerSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "select_spell"), SelectSpellC2SPacket::handle);
|
ServerSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "select_spell"), SelectSpellC2SPacket::handle);
|
||||||
ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "update_known_spells"), UpdateKnownSpellsS2CPacket::handle);
|
ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "update_known_spells"), UpdateKnownSpellsS2CPacket::handle);
|
||||||
ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "learned_new_spell"), LearnedNewSpellS2CPacket::handle);
|
|
||||||
|
|
||||||
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
|
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
|
||||||
if (isSelectedLootTable(id)) {
|
if (isSelectedLootTable(id)) {
|
||||||
@ -130,13 +129,22 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
|
|||||||
entity.setItem(itemStack);
|
entity.setItem(itemStack);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void playSound(BlockPointer pointer) {
|
||||||
|
playSpellSound(pointer);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final SoundEvent SPELL_SOUND_EFFECT = SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE;
|
private static final SoundEvent SPELL_SOUND_EFFECT = SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE;
|
||||||
|
|
||||||
|
public static void playSpellSound(BlockPointer block) {
|
||||||
|
block.getWorld().playSound(null, block.getBlockPos(), SPELL_SOUND_EFFECT, SoundCategory.BLOCKS, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
public static void playSpellSound(PlayerEntity player) {
|
public static void playSpellSound(PlayerEntity player) {
|
||||||
player.playSound(SPELL_SOUND_EFFECT, 1.0f, 1.0f);
|
player.playSound(SPELL_SOUND_EFFECT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -144,7 +152,7 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
|
|||||||
EntityRendererRegistry.INSTANCE.register(SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher));
|
EntityRendererRegistry.INSTANCE.register(SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher));
|
||||||
ScreenProviderRegistry.INSTANCE.<CastingTableContainer>registerFactory(new Identifier(NAMESPACE, "casting_table"), (container) -> {
|
ScreenProviderRegistry.INSTANCE.<CastingTableContainer>registerFactory(new Identifier(NAMESPACE, "casting_table"), (container) -> {
|
||||||
assert MinecraftClient.getInstance().player != null;
|
assert MinecraftClient.getInstance().player != null;
|
||||||
return new CastingTableScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText("block.sorcerycraft.casting_table"));
|
return new CastingTableScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText("block." + SorceryCraft.NAMESPACE + ".casting_table"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,6 @@ public class CastingTableBlock extends Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NameableContainerFactory createContainerFactory(BlockState state, World world, BlockPos pos) {
|
public NameableContainerFactory createContainerFactory(BlockState state, World world, BlockPos pos) {
|
||||||
return new SimpleNamedContainerFactory((i, playerInventory, playerEntity) -> new CastingTableContainer(i, playerInventory, BlockContext.create(world, pos)), new TranslatableText("container.sorcerycraft.casting_table"));
|
return new SimpleNamedContainerFactory((i, playerInventory, playerEntity) -> new CastingTableContainer(i, playerInventory, BlockContext.create(world, pos)), new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import net.minecraft.inventory.BasicInventory;
|
|||||||
import net.minecraft.inventory.CraftingResultInventory;
|
import net.minecraft.inventory.CraftingResultInventory;
|
||||||
import net.minecraft.inventory.Inventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -44,7 +44,7 @@ public class CastingTableContainer extends Container {
|
|||||||
spells = SpellRegistry.getSpells();
|
spells = SpellRegistry.getSpells();
|
||||||
} else {
|
} else {
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) playerInventory.player;
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) playerInventory.player;
|
||||||
Map<String, Integer> spellsMap = spellPlayer.getSpells();
|
Map<Identifier, Integer> spellsMap = spellPlayer.getSpells();
|
||||||
List<Spell> spellsArray = new ArrayList<>();
|
List<Spell> spellsArray = new ArrayList<>();
|
||||||
|
|
||||||
Spell[] allSpells = SpellRegistry.getSpells();
|
Spell[] allSpells = SpellRegistry.getSpells();
|
||||||
@ -149,7 +149,7 @@ public class CastingTableContainer extends Container {
|
|||||||
cost.getItem() == spells[index].getItemCost().getItem() &&
|
cost.getItem() == spells[index].getItemCost().getItem() &&
|
||||||
cost.getCount() >= spells[index].getItemCost().getCount()) {
|
cost.getCount() >= spells[index].getItemCost().getCount()) {
|
||||||
ItemStack resultItem = item.copy();
|
ItemStack resultItem = item.copy();
|
||||||
Map<String, Integer> resultSpells = SpellTag.getSpells(resultItem);
|
Map<Identifier, Integer> resultSpells = SpellTag.getSpells(resultItem);
|
||||||
if (!resultSpells.containsKey(spells[index].getID()) || resultSpells.get(spells[index].getID()) <= spells[index].getLevel()) {
|
if (!resultSpells.containsKey(spells[index].getID()) || resultSpells.get(spells[index].getID()) <= spells[index].getLevel()) {
|
||||||
resultSpells.put(spells[index].getID(), spells[index].getLevel());
|
resultSpells.put(spells[index].getID(), spells[index].getLevel());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.client.block;
|
package com.thebrokenrail.sorcerycraft.client.block;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.block.CastingTableContainer;
|
import com.thebrokenrail.sorcerycraft.block.CastingTableContainer;
|
||||||
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.Spell;
|
import com.thebrokenrail.sorcerycraft.spell.Spell;
|
||||||
@ -34,7 +35,7 @@ public class CastingTableScreen extends ContainerScreen<CastingTableContainer> {
|
|||||||
int j = containerHeight - 94;
|
int j = containerHeight - 94;
|
||||||
font.draw(title.asFormattedString(), (float) (49 + this.containerWidth / 2 - font.getStringWidth(title.asFormattedString()) / 2), 6.0F, 4210752);
|
font.draw(title.asFormattedString(), (float) (49 + this.containerWidth / 2 - font.getStringWidth(title.asFormattedString()) / 2), 6.0F, 4210752);
|
||||||
font.draw(playerInventory.getDisplayName().asFormattedString(), 107.0F, (float) j, 4210752);
|
font.draw(playerInventory.getDisplayName().asFormattedString(), 107.0F, (float) j, 4210752);
|
||||||
String spells = new TranslatableText("container.sorcerycraft.spells").getString();
|
String spells = new TranslatableText("container." + SorceryCraft.NAMESPACE + ".spells").getString();
|
||||||
font.draw(spells, (float) (5 - font.getStringWidth(spells) / 2 + 48), 6.0F, 4210752);
|
font.draw(spells, (float) (5 - font.getStringWidth(spells) / 2 + 48), 6.0F, 4210752);
|
||||||
renderXPCost();
|
renderXPCost();
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.command;
|
package com.thebrokenrail.sorcerycraft.command;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
||||||
import net.minecraft.command.arguments.EntityArgumentType;
|
import net.minecraft.command.arguments.EntityArgumentType;
|
||||||
@ -13,62 +10,37 @@ import net.minecraft.server.command.CommandManager;
|
|||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class SpellCommand {
|
public class SpellCommand {
|
||||||
public static SuggestionProvider<ServerCommandSource> getOptions() {
|
|
||||||
return (ctx, builder) -> getSuggestionsBuilder(builder, new String[]{"clear", "list"});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CompletableFuture<Suggestions> getSuggestionsBuilder(SuggestionsBuilder builder, String[] list) {
|
|
||||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
|
||||||
|
|
||||||
if (list.length < 1) {
|
|
||||||
return Suggestions.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String str : list) {
|
|
||||||
if (str.toLowerCase(Locale.ROOT).startsWith(remaining)) {
|
|
||||||
builder.suggest(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.buildFuture();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
dispatcher.register(CommandManager.literal("spell")
|
dispatcher.register(CommandManager.literal("spell")
|
||||||
.requires(source -> source.hasPermissionLevel(4))
|
.requires(source -> source.hasPermissionLevel(4))
|
||||||
.then(CommandManager.argument("action", StringArgumentType.word())
|
.then(CommandManager.literal("list")
|
||||||
.suggests(getOptions())
|
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||||
|
.executes(ctx -> {
|
||||||
|
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||||
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName()), false);
|
||||||
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
|
Map<Identifier, Integer> spells = spellPlayer.getSpells();
|
||||||
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||||
|
ctx.getSource().sendFeedback(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue()).formatted(Formatting.YELLOW), false);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.then(CommandManager.literal("clear")
|
||||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
String action = StringArgumentType.getString(ctx, "action");
|
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||||
switch (action) {
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
case "clear": {
|
spellPlayer.setSpells(new HashMap<>());
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.cleared_spells", player.getDisplayName()), true);
|
||||||
spellPlayer.setSpells(new HashMap<>());
|
return 1;
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.spell.cleared_spells", player.getDisplayName()), true);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
case "list": {
|
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.spell.listing_spells", player.getDisplayName()), false);
|
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
|
||||||
Map<String, Integer> spells = spellPlayer.getSpells();
|
|
||||||
for (Map.Entry<String, Integer> entry : spells.entrySet()) {
|
|
||||||
ctx.getSource().sendFeedback(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue()).formatted(Formatting.YELLOW), false);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.spell.invalid_action", action).formatted(Formatting.RED), true);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -4,6 +4,7 @@ import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
|||||||
import com.thebrokenrail.sorcerycraft.spell.Spell;
|
import com.thebrokenrail.sorcerycraft.spell.Spell;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
||||||
|
import com.thebrokenrail.sorcerycraft.spell.Spells;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
@ -15,6 +16,7 @@ import net.minecraft.network.Packet;
|
|||||||
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
|
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
import net.minecraft.util.hit.HitResult;
|
import net.minecraft.util.hit.HitResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@ -30,43 +32,40 @@ public class SpellEntity extends ThrownItemEntity {
|
|||||||
super(SorceryCraft.SPELL_ENTITY, owner, world);
|
super(SorceryCraft.SPELL_ENTITY, owner, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean firstTick = false;
|
private boolean firstTick = true;
|
||||||
|
|
||||||
public SpellEntity(World world, double x, double y, double z) {
|
public SpellEntity(World world, double x, double y, double z) {
|
||||||
super(SorceryCraft.SPELL_ENTITY, x, y, z, world);
|
super(SorceryCraft.SPELL_ENTITY, x, y, z, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean didSpellSucceed(Map<String, Integer> spells) {
|
private boolean didSpellSucceed(Map<Identifier, Integer> spells) {
|
||||||
return Math.random() > SorceryCraft.SPELL_FAILURE_CHANCE || spells.containsKey("steadfast_spell");
|
return Math.random() > SorceryCraft.SPELL_FAILURE_CHANCE || spells.containsKey(Spells.STEADFAST_SPELL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCollision(HitResult hitResult) {
|
protected void onCollision(HitResult hitResult) {
|
||||||
boolean remove = false;
|
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
|
||||||
if (hitResult.getType() == HitResult.Type.BLOCK) {
|
if (!spells.containsKey(Spells.INWARD_SPELL)) {
|
||||||
remove = true;
|
if (hitResult.getType() == HitResult.Type.BLOCK) {
|
||||||
} else if (hitResult.getType() == HitResult.Type.ENTITY) {
|
remove();
|
||||||
Entity entity = ((EntityHitResult) hitResult).getEntity();
|
} else if (hitResult.getType() == HitResult.Type.ENTITY) {
|
||||||
|
Entity entity = ((EntityHitResult) hitResult).getEntity();
|
||||||
|
|
||||||
Map<String, Integer> spells = SpellTag.getSpells(getItem());
|
boolean success = didSpellSucceed(spells);
|
||||||
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||||
boolean success = didSpellSucceed(spells);
|
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue());
|
||||||
for (Map.Entry<String, Integer> entry : spells.entrySet()) {
|
if (spell != null) {
|
||||||
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue());
|
if (success) {
|
||||||
if (spell != null) {
|
spell.execute(entity, this, getOwner());
|
||||||
if (success) {
|
} else if (getOwner() != null) {
|
||||||
spell.execute(entity, this, getOwner());
|
getOwner().playSound(SoundEvents.ENCHANT_THORNS_HIT, 1.0f, 1.0f);
|
||||||
} else if (getOwner() != null) {
|
spell.execute(getOwner(), this, getOwner());
|
||||||
getOwner().playSound(SoundEvents.ENCHANT_THORNS_HIT, 1.0f, 1.0f);
|
}
|
||||||
spell.execute(getOwner(), this, getOwner());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
remove = true;
|
remove();
|
||||||
}
|
}
|
||||||
if (remove && !getEntityWorld().isClient()) {
|
|
||||||
remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,15 +84,18 @@ public class SpellEntity extends ThrownItemEntity {
|
|||||||
super.tick();
|
super.tick();
|
||||||
if (firstTick) {
|
if (firstTick) {
|
||||||
firstTick = false;
|
firstTick = false;
|
||||||
Map<String, Integer> spells = SpellTag.getSpells(getItem());
|
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
|
||||||
if (spells.containsKey("inward_spell")) {
|
if (spells.containsKey(Spells.INWARD_SPELL)) {
|
||||||
boolean success = didSpellSucceed(spells);
|
if (getOwner() != null) {
|
||||||
for (Map.Entry<String, Integer> entry : spells.entrySet()) {
|
boolean success = didSpellSucceed(spells);
|
||||||
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue());
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||||
if (spell != null && success) {
|
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue());
|
||||||
spell.execute(getOwner(), this, getOwner());
|
if (spell != null && success) {
|
||||||
|
spell.execute(getOwner(), this, getOwner());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,16 @@ package com.thebrokenrail.sorcerycraft.item;
|
|||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.packet.LearnedNewSpellS2CPacket;
|
|
||||||
import com.thebrokenrail.sorcerycraft.spell.Spell;
|
import com.thebrokenrail.sorcerycraft.spell.Spell;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
||||||
import net.minecraft.block.dispenser.ProjectileDispenserBehavior;
|
|
||||||
import net.minecraft.client.item.TooltipContext;
|
import net.minecraft.client.item.TooltipContext;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.sound.SoundEvents;
|
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
@ -23,6 +19,7 @@ import net.minecraft.util.ActionResult;
|
|||||||
import net.minecraft.util.DefaultedList;
|
import net.minecraft.util.DefaultedList;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.Rarity;
|
import net.minecraft.util.Rarity;
|
||||||
import net.minecraft.util.TypedActionResult;
|
import net.minecraft.util.TypedActionResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@ -40,7 +37,7 @@ public class SpellItem extends Item {
|
|||||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
|
||||||
ItemStack itemStack = playerEntity.getStackInHand(hand);
|
ItemStack itemStack = playerEntity.getStackInHand(hand);
|
||||||
|
|
||||||
Map<String, Integer> spells = SpellTag.getSpells(itemStack);
|
Map<Identifier, Integer> spells = SpellTag.getSpells(itemStack);
|
||||||
|
|
||||||
if (spells.size() > 0) {
|
if (spells.size() > 0) {
|
||||||
SorceryCraft.playSpellSound(playerEntity);
|
SorceryCraft.playSpellSound(playerEntity);
|
||||||
@ -64,14 +61,14 @@ public class SpellItem extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasEnchantmentGlint(ItemStack stack) {
|
public boolean hasEnchantmentGlint(ItemStack stack) {
|
||||||
Map<String, Integer> spells = SpellTag.getSpells(stack);
|
Map<Identifier, Integer> spells = SpellTag.getSpells(stack);
|
||||||
return spells.size() > 0;
|
return spells.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
|
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
|
||||||
Map<String, Integer> spells = SpellTag.getSpells(itemStack);
|
Map<Identifier, Integer> spells = SpellTag.getSpells(itemStack);
|
||||||
for (Map.Entry<String, Integer> entry : spells.entrySet()) {
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||||
tooltip.add(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue()));
|
tooltip.add(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +80,7 @@ public class SpellItem extends Item {
|
|||||||
Spell[] spells = SpellRegistry.getSpells();
|
Spell[] spells = SpellRegistry.getSpells();
|
||||||
for (Spell value : spells) {
|
for (Spell value : spells) {
|
||||||
ItemStack item = new ItemStack(this);
|
ItemStack item = new ItemStack(this);
|
||||||
Map<String, Integer> spell = new HashMap<>();
|
Map<Identifier, Integer> spell = new HashMap<>();
|
||||||
spell.put(value.getID(), value.getLevel());
|
spell.put(value.getID(), value.getLevel());
|
||||||
SpellTag.setSpells(item, spell);
|
SpellTag.setSpells(item, spell);
|
||||||
stacks.add(item);
|
stacks.add(item);
|
||||||
@ -103,12 +100,12 @@ public class SpellItem extends Item {
|
|||||||
PlayerEntity player = (PlayerEntity) entity;
|
PlayerEntity player = (PlayerEntity) entity;
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
|
|
||||||
Map<String, Integer> playerSpells = spellPlayer.getSpells();
|
Map<Identifier, Integer> playerSpells = spellPlayer.getSpells();
|
||||||
Map<String, Integer> itemSpells = SpellTag.getSpells(player.inventory.getInvStack(slot));
|
Map<Identifier, Integer> itemSpells = SpellTag.getSpells(player.inventory.getInvStack(slot));
|
||||||
|
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> entry : itemSpells.entrySet()) {
|
for (Map.Entry<Identifier, Integer> entry : itemSpells.entrySet()) {
|
||||||
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue());
|
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue());
|
||||||
if (spell != null) {
|
if (spell != null) {
|
||||||
if (spell.getLevel() >= spell.getMaxLevel()) {
|
if (spell.getLevel() >= spell.getMaxLevel()) {
|
||||||
@ -121,13 +118,14 @@ public class SpellItem extends Item {
|
|||||||
playerSpells.put(spell.getID(), spell.getLevel());
|
playerSpells.put(spell.getID(), spell.getLevel());
|
||||||
assert world.getServer() != null;
|
assert world.getServer() != null;
|
||||||
Text text = new LiteralText("[").append(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel()).getString()).append("]").formatted(Formatting.GREEN);
|
Text text = new LiteralText("[").append(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel()).getString()).append("]").formatted(Formatting.GREEN);
|
||||||
world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat.sorcerycraft.new_spell", player.getDisplayName(), text));
|
world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".new_spell", player.getDisplayName(), text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
LearnedNewSpellS2CPacket.send((ServerPlayerEntity) player);
|
//LearnedNewSpellS2CPacket.send((ServerPlayerEntity) player);
|
||||||
|
SorceryCraft.playSpellSound(player);
|
||||||
spellPlayer.setSpells(playerSpells);
|
spellPlayer.setSpells(playerSpells);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
|||||||
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
@ -15,7 +16,7 @@ import java.util.Map;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Mixin(PlayerEntity.class)
|
@Mixin(PlayerEntity.class)
|
||||||
public class MixinPlayerEntity implements SpellPlayerEntity {
|
public class MixinPlayerEntity implements SpellPlayerEntity {
|
||||||
private Map<String, Integer> spells = new HashMap<>();
|
private Map<Identifier, Integer> spells = new HashMap<>();
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
|
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
|
||||||
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
||||||
@ -28,12 +29,12 @@ public class MixinPlayerEntity implements SpellPlayerEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSpells(Map<String, Integer> spells) {
|
public void setSpells(Map<Identifier, Integer> spells) {
|
||||||
this.spells = spells;
|
this.spells = spells;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Integer> getSpells() {
|
public Map<Identifier, Integer> getSpells() {
|
||||||
return spells;
|
return spells;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.packet;
|
|
||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.fabricmc.fabric.api.network.PacketContext;
|
|
||||||
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 LearnedNewSpellS2CPacket {
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static void handle(PacketContext context, PacketByteBuf bytes) {
|
|
||||||
if (context.getPlayer() != null) {
|
|
||||||
SorceryCraft.playSpellSound(context.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void send(ServerPlayerEntity player) {
|
|
||||||
PacketByteBuf bytes = new PacketByteBuf(Unpooled.buffer());
|
|
||||||
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(new Identifier(SorceryCraft.NAMESPACE, "learned_new_spell"), bytes));
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,9 +5,10 @@ import net.minecraft.entity.LivingEntity;
|
|||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.entity.effect.StatusEffects;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class DamageSpell extends Spell {
|
public class DamageSpell extends Spell {
|
||||||
public DamageSpell(String id, int level) {
|
public DamageSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@ import net.minecraft.entity.Entity;
|
|||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class DissolveSpell extends Spell {
|
public class DissolveSpell extends Spell {
|
||||||
public DissolveSpell(String id, int level) {
|
public DissolveSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,10 @@ package com.thebrokenrail.sorcerycraft.spell;
|
|||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class FlameSpell extends Spell {
|
public class FlameSpell extends Spell {
|
||||||
public FlameSpell(String id, int level) {
|
public FlameSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,10 @@ import net.minecraft.entity.LivingEntity;
|
|||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.entity.effect.StatusEffects;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class HealSpell extends Spell {
|
public class HealSpell extends Spell {
|
||||||
public HealSpell(String id, int level) {
|
public HealSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,14 +3,16 @@ package com.thebrokenrail.sorcerycraft.spell;
|
|||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class InwardSpell extends Spell {
|
public class InwardSpell extends Spell {
|
||||||
public InwardSpell(String id, int level) {
|
public InwardSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Entity target, Entity source, Entity attacker) {
|
public void execute(Entity target, Entity source, Entity attacker) {
|
||||||
|
// NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +22,7 @@ public class InwardSpell extends Spell {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemCost() {
|
public ItemStack getItemCost() {
|
||||||
return new ItemStack(Items.BLAZE_ROD);
|
return new ItemStack(Items.ENDER_EYE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,9 +6,10 @@ import net.minecraft.entity.effect.StatusEffectInstance;
|
|||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.entity.effect.StatusEffects;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class LevitateSpell extends Spell {
|
public class LevitateSpell extends Spell {
|
||||||
public LevitateSpell(String id, int level) {
|
public LevitateSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ import net.minecraft.loot.condition.LootCondition;
|
|||||||
import net.minecraft.loot.context.LootContext;
|
import net.minecraft.loot.context.LootContext;
|
||||||
import net.minecraft.loot.function.ConditionalLootFunction;
|
import net.minecraft.loot.function.ConditionalLootFunction;
|
||||||
import net.minecraft.loot.function.LootFunction;
|
import net.minecraft.loot.function.LootFunction;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class RandomSpellLootTableFunction extends ConditionalLootFunction {
|
public class RandomSpellLootTableFunction extends ConditionalLootFunction {
|
||||||
@ -15,11 +15,15 @@ public class RandomSpellLootTableFunction extends ConditionalLootFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack process(ItemStack stack, LootContext context) {
|
public ItemStack process(ItemStack stack, LootContext context) {
|
||||||
Spell[] spells = SpellRegistry.getSpells();
|
double chance = 1.0d;
|
||||||
int index = context.getRandom().nextInt(spells.length);
|
while (!(context.getRandom().nextDouble() > chance)) {
|
||||||
Map<String, Integer> spell = new HashMap<>();
|
Spell[] spells = SpellRegistry.getSpells();
|
||||||
spell.put(spells[index].getID(), spells[index].getLevel());
|
int index = context.getRandom().nextInt(spells.length);
|
||||||
SpellTag.setSpells(stack, spell);
|
Map<Identifier, Integer> spell = SpellTag.getSpells(stack);
|
||||||
|
spell.put(spells[index].getID(), spells[index].getLevel());
|
||||||
|
SpellTag.setSpells(stack, spell);
|
||||||
|
chance = chance * 0.25d;
|
||||||
|
}
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,17 +2,18 @@ package com.thebrokenrail.sorcerycraft.spell;
|
|||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public abstract class Spell {
|
public abstract class Spell {
|
||||||
private final String id;
|
private final Identifier id;
|
||||||
private final int level;
|
private final int level;
|
||||||
|
|
||||||
public Spell(String id, int level) {
|
public Spell(Identifier id, int level) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public Identifier getID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.spell;
|
package com.thebrokenrail.sorcerycraft.spell;
|
||||||
|
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface SpellPlayerEntity {
|
public interface SpellPlayerEntity {
|
||||||
void setSpells(Map<String, Integer> spells);
|
void setSpells(Map<Identifier, Integer> spells);
|
||||||
|
|
||||||
Map<String, Integer> getSpells();
|
Map<Identifier, Integer> getSpells();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.spell;
|
package com.thebrokenrail.sorcerycraft.spell;
|
||||||
|
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -7,21 +9,21 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class SpellRegistry {
|
public class SpellRegistry {
|
||||||
private static final Map<String, Class<?>> spells = new HashMap<>();
|
private static final Map<Identifier, Class<?>> spells = new HashMap<>();
|
||||||
|
|
||||||
public static Spell getSpell(String id, int level) {
|
public static Spell getSpell(Identifier id, int level) {
|
||||||
if (!spells.containsKey(id)) {
|
if (!spells.containsKey(id)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return (Spell) spells.get(id).getConstructor(String.class, int.class).newInstance(id, level);
|
return (Spell) spells.get(id).getConstructor(Identifier.class, int.class).newInstance(id, level);
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxLevel(String id) {
|
public static int getMaxLevel(Identifier id) {
|
||||||
Spell tempSpell = getSpell(id, 0);
|
Spell tempSpell = getSpell(id, 0);
|
||||||
if (tempSpell == null) {
|
if (tempSpell == null) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -31,7 +33,7 @@ public class SpellRegistry {
|
|||||||
|
|
||||||
public static Spell[] getSpells() {
|
public static Spell[] getSpells() {
|
||||||
List<Spell> out = new ArrayList<>();
|
List<Spell> out = new ArrayList<>();
|
||||||
for (Map.Entry<String, Class<?>> entry : spells.entrySet()) {
|
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
|
||||||
int maxLevel = getMaxLevel(entry.getKey());
|
int maxLevel = getMaxLevel(entry.getKey());
|
||||||
if (maxLevel == -1) {
|
if (maxLevel == -1) {
|
||||||
continue;
|
continue;
|
||||||
@ -46,18 +48,8 @@ public class SpellRegistry {
|
|||||||
return out.toArray(new Spell[0]);
|
return out.toArray(new Spell[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerSpell(String id, Class<?> spell) {
|
public static Identifier registerSpell(Identifier id, Class<?> spell) {
|
||||||
spells.put(id, spell);
|
spells.put(id, spell);
|
||||||
}
|
return id;
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
SpellRegistry.registerSpell("heal_spell", HealSpell.class);
|
|
||||||
SpellRegistry.registerSpell("damage_spell", DamageSpell.class);
|
|
||||||
SpellRegistry.registerSpell("dissolve_spell", DissolveSpell.class);
|
|
||||||
SpellRegistry.registerSpell("steadfast_spell", SteadfastSpell.class);
|
|
||||||
SpellRegistry.registerSpell("flame_spell", FlameSpell.class);
|
|
||||||
SpellRegistry.registerSpell("levitate_spell", LevitateSpell.class);
|
|
||||||
SpellRegistry.registerSpell("teleport_spell", TeleportSpell.class);
|
|
||||||
SpellRegistry.registerSpell("inward_spell", InwardSpell.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.spell;
|
package com.thebrokenrail.sorcerycraft.spell;
|
||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
@ -8,6 +7,7 @@ import net.minecraft.nbt.Tag;
|
|||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -15,7 +15,7 @@ import java.util.Map;
|
|||||||
public class SpellTag {
|
public class SpellTag {
|
||||||
public static final String SPELL_TAG = "Spells";
|
public static final String SPELL_TAG = "Spells";
|
||||||
|
|
||||||
public static void setSpells(ItemStack itemStack, Map<String, Integer> map) {
|
public static void setSpells(ItemStack itemStack, Map<Identifier, Integer> map) {
|
||||||
CompoundTag tag;
|
CompoundTag tag;
|
||||||
if (itemStack.hasTag()) {
|
if (itemStack.hasTag()) {
|
||||||
tag = itemStack.getTag();
|
tag = itemStack.getTag();
|
||||||
@ -30,12 +30,12 @@ public class SpellTag {
|
|||||||
itemStack.setTag(tag);
|
itemStack.setTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListTag createSpellsTag(Map<String, Integer> map) {
|
public static ListTag createSpellsTag(Map<Identifier, Integer> map) {
|
||||||
ListTag spells = new ListTag();
|
ListTag spells = new ListTag();
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
for (Map.Entry<Identifier, Integer> entry : map.entrySet()) {
|
||||||
CompoundTag spell = new CompoundTag();
|
CompoundTag spell = new CompoundTag();
|
||||||
spell.putString("id", entry.getKey());
|
spell.putString("id", entry.getKey().toString());
|
||||||
spell.putInt("level", entry.getValue());
|
spell.putInt("level", entry.getValue());
|
||||||
spells.add(spell);
|
spells.add(spell);
|
||||||
}
|
}
|
||||||
@ -43,11 +43,11 @@ public class SpellTag {
|
|||||||
return spells;
|
return spells;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Integer> getSpells(ItemStack itemStack) {
|
public static Map<Identifier, Integer> getSpells(ItemStack itemStack) {
|
||||||
return getSpells(itemStack.getTag());
|
return getSpells(itemStack.getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Integer> getSpells(CompoundTag tag) {
|
public static Map<Identifier, Integer> getSpells(CompoundTag tag) {
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
tag = new CompoundTag();
|
tag = new CompoundTag();
|
||||||
tag.put(SPELL_TAG, new ListTag());
|
tag.put(SPELL_TAG, new ListTag());
|
||||||
@ -60,11 +60,11 @@ public class SpellTag {
|
|||||||
spells = new ListTag();
|
spells = new ListTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Integer> map = new HashMap<>();
|
Map<Identifier, Integer> map = new HashMap<>();
|
||||||
|
|
||||||
for (int i = 0; i < spells.size(); i++) {
|
for (int i = 0; i < spells.size(); i++) {
|
||||||
CompoundTag spell = spells.getCompound(i);
|
CompoundTag spell = spells.getCompound(i);
|
||||||
String id = spell.getString("id");
|
Identifier id = new Identifier(spell.getString("id"));
|
||||||
int level = spell.getInt("level");
|
int level = spell.getInt("level");
|
||||||
if (map.get(id) == null || map.get(id) < level) {
|
if (map.get(id) == null || map.get(id) < level) {
|
||||||
map.put(id, level);
|
map.put(id, level);
|
||||||
@ -74,8 +74,8 @@ public class SpellTag {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text getTranslatedSpell(String id, int level) {
|
public static Text getTranslatedSpell(Identifier id, int level) {
|
||||||
Text text = new TranslatableText("spell." + SorceryCraft.NAMESPACE + '.' + id);
|
Text text = new TranslatableText("spell." + id.getNamespace() + '.' + id.getPath());
|
||||||
text.formatted(Formatting.GRAY);
|
text.formatted(Formatting.GRAY);
|
||||||
if (level != 0 || SpellRegistry.getMaxLevel(id) != 1) {
|
if (level != 0 || SpellRegistry.getMaxLevel(id) != 1) {
|
||||||
text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1)));
|
text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1)));
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.thebrokenrail.sorcerycraft.spell;
|
||||||
|
|
||||||
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class Spells {
|
||||||
|
public static final Identifier HEAL_SPELL;
|
||||||
|
public static final Identifier DAMAGE_SPELL;
|
||||||
|
public static final Identifier DISSOLVE_SPELL;
|
||||||
|
public static final Identifier STEADFAST_SPELL;
|
||||||
|
public static final Identifier FLAME_SPELL;
|
||||||
|
public static final Identifier LEVITATE_SPELL;
|
||||||
|
public static final Identifier TELEPORT_SPELL;
|
||||||
|
public static final Identifier INWARD_SPELL;
|
||||||
|
|
||||||
|
static {
|
||||||
|
HEAL_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "heal_spell"), HealSpell.class);
|
||||||
|
DAMAGE_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "damage_spell"), DamageSpell.class);
|
||||||
|
DISSOLVE_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "dissolve_spell"), DissolveSpell.class);
|
||||||
|
STEADFAST_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "steadfast_spell"), SteadfastSpell.class);
|
||||||
|
FLAME_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "flame_spell"), FlameSpell.class);
|
||||||
|
LEVITATE_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "levitate_spell"), LevitateSpell.class);
|
||||||
|
TELEPORT_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "teleport_spell"), TeleportSpell.class);
|
||||||
|
INWARD_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "inward_spell"), InwardSpell.class);
|
||||||
|
}
|
||||||
|
}
|
@ -3,14 +3,16 @@ package com.thebrokenrail.sorcerycraft.spell;
|
|||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class SteadfastSpell extends Spell {
|
public class SteadfastSpell extends Spell {
|
||||||
public SteadfastSpell(String id, int level) {
|
public SteadfastSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Entity target, Entity source, Entity attacker) {
|
public void execute(Entity target, Entity source, Entity attacker) {
|
||||||
|
// NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,16 +2,16 @@ package com.thebrokenrail.sorcerycraft.spell;
|
|||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.effect.StatusEffects;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class TeleportSpell extends Spell {
|
public class TeleportSpell extends Spell {
|
||||||
public TeleportSpell(String id, int level) {
|
public TeleportSpell(Identifier id, int level) {
|
||||||
super(id, level);
|
super(id, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
"container.sorcerycraft.spells": "Spells",
|
"container.sorcerycraft.spells": "Spells",
|
||||||
"chat.sorcerycraft.new_spell": "%s has learned the spell %s",
|
"chat.sorcerycraft.new_spell": "%s has learned the spell %s",
|
||||||
"entity.sorcerycraft.spell": "Spell",
|
"entity.sorcerycraft.spell": "Spell",
|
||||||
"command.sorcerycraft.spell.invalid_action": "Invalid sub-command \"%s\"",
|
|
||||||
"command.sorcerycraft.spell.cleared_spells": "All spells cleared from %s",
|
"command.sorcerycraft.spell.cleared_spells": "All spells cleared from %s",
|
||||||
"command.sorcerycraft.spell.listing_spells": "%s knows the following spells:",
|
"command.sorcerycraft.spell.listing_spells": "%s knows the following spells:",
|
||||||
"spell.sorcerycraft.damage_spell": "Damage",
|
"spell.sorcerycraft.damage_spell": "Damage",
|
||||||
@ -15,5 +14,6 @@
|
|||||||
"spell.sorcerycraft.steadfast_spell": "Steadfast",
|
"spell.sorcerycraft.steadfast_spell": "Steadfast",
|
||||||
"spell.sorcerycraft.flame_spell": "Flame",
|
"spell.sorcerycraft.flame_spell": "Flame",
|
||||||
"spell.sorcerycraft.levitate_spell": "Levitate",
|
"spell.sorcerycraft.levitate_spell": "Levitate",
|
||||||
"spell.sorcerycraft.teleport_spell": "Teleport"
|
"spell.sorcerycraft.teleport_spell": "Teleport",
|
||||||
|
"spell.sorcerycraft.inward_spell": "Inward"
|
||||||
}
|
}
|
Reference in New Issue
Block a user