Compare commits
No commits in common. "acf08c7fa63937dcc9e893a5d89d3d7b62991e02" and "d381beff167dc87ba45509fbf023520ddffd5655" have entirely different histories.
acf08c7fa6
...
d381beff16
2
API.md
2
API.md
@ -8,7 +8,7 @@
|
||||
}
|
||||
dependencies {
|
||||
modImplementation 'com.thebrokenrail:sorcerycraft:VERSION'
|
||||
// VERSION = "<Mod Version>+<MC Version>", for example "1.2.4+20w12a"
|
||||
// VERSION = "<Mod Version>+<MC Version>", for example "1.2.3+20w12a"
|
||||
}
|
||||
```
|
||||
2. Add Dependency to ```fabric.mod.json```
|
||||
|
@ -1,10 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
**1.2.4**
|
||||
* Optimize Packets
|
||||
* Allow Command Blocks to use ```/spell``` Command
|
||||
* Namespace Statistics
|
||||
|
||||
**1.2.3**
|
||||
* Tweak Cooling Spell
|
||||
* Tweak Versioning
|
||||
|
@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
|
||||
fabric_loader_version = 0.7.8+build.189
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.2.4
|
||||
mod_version = 1.2.3
|
||||
maven_group = com.thebrokenrail
|
||||
archives_base_name = sorcerycraft
|
||||
|
||||
|
@ -2,7 +2,6 @@ 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;
|
||||
@ -37,11 +36,6 @@ public class CastingTableBlock extends Block {
|
||||
|
||||
@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"));
|
||||
return new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> new CastingTableScreenHandler(i, playerInventory, ScreenHandlerContext.create(world, pos)), new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table"));
|
||||
}
|
||||
}
|
||||
|
@ -27,41 +27,36 @@ 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())
|
||||
.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++;
|
||||
}
|
||||
return i;
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
)
|
||||
.then(CommandManager.literal("forget")
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.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;
|
||||
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");
|
||||
@ -70,11 +65,10 @@ public class SpellCommand {
|
||||
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;
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
@ -82,33 +76,29 @@ public class SpellCommand {
|
||||
.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;
|
||||
return 1;
|
||||
})
|
||||
.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;
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
@ -119,7 +109,6 @@ public class SpellCommand {
|
||||
.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");
|
||||
@ -133,12 +122,11 @@ public class SpellCommand {
|
||||
|
||||
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);
|
||||
}
|
||||
return i;
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
@ -148,7 +136,6 @@ public class SpellCommand {
|
||||
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||
.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");
|
||||
@ -163,11 +150,10 @@ public class SpellCommand {
|
||||
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);
|
||||
}
|
||||
return i;
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
|
@ -28,7 +28,7 @@ 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 Spell[] spells;
|
||||
private final ScreenHandlerContext context;
|
||||
private int index = 0;
|
||||
|
||||
@ -44,7 +44,21 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
context = blockContext;
|
||||
result = new CraftingResultInventory();
|
||||
|
||||
setSpells(playerInventory.player);
|
||||
if (playerInventory.player.isCreative() ? SorceryCraft.getConfig().limitCastingTable.creative : SorceryCraft.getConfig().limitCastingTable.survival) {
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) playerInventory.player;
|
||||
Map<Identifier, Integer> spellsMap = spellPlayer.getDiscoveredSpells();
|
||||
List<Spell> spellsArray = new ArrayList<>();
|
||||
|
||||
Spell[] allSpells = SpellRegistry.getSpells();
|
||||
for (Spell spell : allSpells) {
|
||||
if (spellsMap.containsKey(spell.getID()) && spellsMap.get(spell.getID()) >= spell.getLevel()) {
|
||||
spellsArray.add(spell);
|
||||
}
|
||||
}
|
||||
spells = spellsArray.toArray(new Spell[0]);
|
||||
} else {
|
||||
spells = SpellRegistry.getSpells();
|
||||
}
|
||||
|
||||
addSlot(new Slot(inventory, 0, 136, 37) {
|
||||
@Override
|
||||
@ -109,26 +123,6 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
index = 0;
|
||||
onContentChanged(inventory);
|
||||
}
|
||||
|
||||
public boolean canTakeResult(PlayerEntity playerEntity) {
|
||||
return playerEntity.isCreative() || playerEntity.experienceLevel >= spells[index].getXPCost();
|
||||
}
|
||||
|
@ -4,10 +4,8 @@ import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
||||
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.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@ -18,7 +16,6 @@ import java.util.Map;
|
||||
@SuppressWarnings("unused")
|
||||
@Mixin(PlayerEntity.class)
|
||||
public class MixinPlayerEntity implements SpellPlayerEntity {
|
||||
@Shadow public ScreenHandler currentScreenHandler;
|
||||
// Namespace Fields
|
||||
private Map<Identifier, Integer> sorceryCraftDiscoveredSpells = new HashMap<>();
|
||||
|
||||
|
@ -1,24 +1,18 @@
|
||||
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.minecraft.entity.player.PlayerEntity;
|
||||
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) {
|
||||
SpellPlayerEntity oldSpellPlayer = (SpellPlayerEntity) oldPlayer;
|
||||
@ -27,22 +21,11 @@ public abstract class MixinServerPlayerEntity extends MixinPlayerEntity implemen
|
||||
newSpellPlayer.setDiscoveredSpells(oldSpellPlayer.getDiscoveredSpells());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
|
||||
super.setDiscoveredSpells(spells);
|
||||
sync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync() {
|
||||
@Inject(at = @At("HEAD"), method = "playerTick")
|
||||
public void playerTick(CallbackInfo info) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(getDiscoveredSpells()));
|
||||
//noinspection ConstantConditions
|
||||
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
|
||||
|
||||
if (currentScreenHandler instanceof CastingTableScreenHandler) {
|
||||
//noinspection ConstantConditions
|
||||
((CastingTableScreenHandler) currentScreenHandler).setSpells((PlayerEntity) (Object) this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.thebrokenrail.sorcerycraft.packet;
|
||||
|
||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@ -18,9 +17,6 @@ public class UpdateKnownSpellsS2CPacket {
|
||||
if (context.getPlayer() != null) {
|
||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer();
|
||||
spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag));
|
||||
if (context.getPlayer().currentScreenHandler instanceof CastingTableScreenHandler) {
|
||||
((CastingTableScreenHandler) context.getPlayer().currentScreenHandler).setSpells(context.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
package com.thebrokenrail.sorcerycraft.spell.util;
|
||||
|
||||
public interface SpellServerPlayerEntity extends SpellPlayerEntity {
|
||||
void sync();
|
||||
}
|
Reference in New Issue
Block a user