Miscellaneous setup

This commit is contained in:
Electroblob
2018-01-30 16:02:13 +00:00
parent da6b007a3a
commit 2af7329478
59 changed files with 1833 additions and 13509 deletions
@@ -4,6 +4,8 @@ import java.util.List;
import electroblob.wizardry.WizardData;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.event.SpellCastEvent;
import electroblob.wizardry.event.SpellCastEvent.Source;
import electroblob.wizardry.packet.PacketCastSpell;
import electroblob.wizardry.packet.WizardryPacketHandler;
import electroblob.wizardry.spell.Spell;
@@ -24,6 +26,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
public class CommandCastSpell extends CommandBase {
@@ -63,12 +66,14 @@ public class CommandCastSpell extends CommandBase {
throw new WrongUsageException("commands.wizardry:cast.usage", Wizardry.settings.castCommandName);
}else{
// ===== Parameter retrieval =====
int i=0;
EntityPlayerMP entityplayermp = null;
EntityPlayerMP caster = null;
try{
entityplayermp = getCommandSenderAsPlayer(sender);
caster = getCommandSenderAsPlayer(sender);
}catch(PlayerNotFoundException exception){
// Nothing here since the player specifying is done later, I just don't want it to throw an exception here.
}
@@ -85,10 +90,10 @@ public class CommandCastSpell extends CommandBase {
try{
// If the second argument is a player and is not the player that gave the command, the spell is cast
// as the given player rather than the command sender, and there is a different chat readout.
EntityPlayerMP entityplayermp1 = getPlayer(server, sender, arguments[i++]);
if(entityplayermp != entityplayermp1){
EntityPlayerMP entityplayermp = getPlayer(server, sender, arguments[i++]);
if(caster != entityplayermp){
castAsOtherPlayer = true;
entityplayermp = entityplayermp1;
caster = entityplayermp;
}
}catch(PlayerNotFoundException exception){
// If no player was found, rather than give an error it simply assumes the player was unspecified.
@@ -98,7 +103,7 @@ public class CommandCastSpell extends CommandBase {
// If, after this point, the player is still null, the sender must be a command block or the console and the
// player must not have been specified, meaning an exception should be thrown.
if(entityplayermp == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
if(caster == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
SpellModifiers modifiers = new SpellModifiers();
@@ -122,20 +127,30 @@ public class CommandCastSpell extends CommandBase {
}
}
// ===== Spell casting =====
// If anything stops the spell working at this point, nothing else happens.
if(MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Pre(caster, spell, modifiers, Source.COMMAND))){
displayFailMessage(sender, spell);
return;
}
WizardData data = WizardData.get((EntityPlayer)caster);
if(spell.isContinuous){
WizardData properties = WizardData.get((EntityPlayer)entityplayermp);
// Events for continuous spell casting via commands are dealt with in WizardData.
if(properties != null){
if(properties.isCasting()){
WizardData.get((EntityPlayer)entityplayermp).stopCastingContinuousSpell();
if(data != null){
if(data.isCasting()){
data.stopCastingContinuousSpell();
}else{
WizardData.get((EntityPlayer)entityplayermp).startCastingContinuousSpell(spell, modifiers);
data.startCastingContinuousSpell(spell, modifiers);
if(castAsOtherPlayer){
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_remote_continuous", spell.getNameForTranslationFormatted(), entityplayermp.getName()));
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_remote_continuous", spell.getNameForTranslationFormatted(), caster.getName()));
}else{
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_continuous", spell.getNameForTranslationFormatted()));
}
@@ -146,27 +161,20 @@ public class CommandCastSpell extends CommandBase {
}else{
if(spell.cast(entityplayermp.worldObj, entityplayermp, EnumHand.MAIN_HAND, 0, modifiers)){
if(spell.cast(caster.worldObj, caster, EnumHand.MAIN_HAND, 0, modifiers)){
MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(caster, spell, modifiers, Source.COMMAND));
if(spell.doesSpellRequirePacket()){
// Sends a packet to all players in dimension to tell them to spawn particles.
// Only sent if the spell succeeded, because if the spell failed, you wouldn't
// need to spawn any particles!
IMessage msg = new PacketCastSpell.Message(entityplayermp.getEntityId(), null, spell.id(), modifiers);
WizardryPacketHandler.net.sendToDimension(msg, entityplayermp.worldObj.provider.getDimension());
IMessage msg = new PacketCastSpell.Message(caster.getEntityId(), null, spell.id(), modifiers);
WizardryPacketHandler.net.sendToDimension(msg, caster.worldObj.provider.getDimension());
}
if(WizardData.get((EntityPlayer)entityplayermp) != null){
// Added optimisation from 1.7.10: if the spell was already discovered, nothing happens.
if(WizardData.get((EntityPlayer)entityplayermp).discoverSpell(spell)){
// If the spell didn't send a packet itself, the extended player needs to be synced so the
// spell discovery updates on the client.
if(!spell.doesSpellRequirePacket()) WizardData.get((EntityPlayer)entityplayermp).sync();
}
}
if(castAsOtherPlayer){
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_remote", spell.getNameForTranslationFormatted(), entityplayermp.getName()));
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_remote", spell.getNameForTranslationFormatted(), caster.getName()));
}else{
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success", spell.getNameForTranslationFormatted()));
}
@@ -174,10 +182,15 @@ public class CommandCastSpell extends CommandBase {
}
}
ITextComponent message = new TextComponentTranslation("commands.wizardry:cast.fail", spell.getNameForTranslationFormatted());
message.getStyle().setColor(TextFormatting.RED);
sender.addChatMessage(message);
displayFailMessage(sender, spell);
}
}
/** Displays the "Unable to cast [spell]" message in the chat. */
private void displayFailMessage(ICommandSender sender, Spell spell){
ITextComponent message = new TextComponentTranslation("commands.wizardry:cast.fail", spell.getNameForTranslationFormatted());
message.getStyle().setColor(TextFormatting.RED);
sender.addChatMessage(message);
}
}
@@ -4,6 +4,7 @@ import java.util.List;
import electroblob.wizardry.WizardData;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.event.DiscoverSpellEvent;
import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.spell.Spell;
import net.minecraft.command.CommandBase;
@@ -16,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.common.MinecraftForge;
public class CommandDiscoverSpell extends CommandBase {
@@ -66,10 +68,10 @@ public class CommandDiscoverSpell extends CommandBase {
boolean clear = false;
boolean all = false;
EntityPlayerMP entityplayermp = null;
EntityPlayerMP player = null;
try{
entityplayermp = getCommandSenderAsPlayer(sender);
player = getCommandSenderAsPlayer(sender);
}catch(PlayerNotFoundException exception){
// Nothing here since the player specifying is done later, I just don't want it to throw an exception here.
}
@@ -94,32 +96,34 @@ public class CommandDiscoverSpell extends CommandBase {
if(i < arguments.length){
// If the second argument is a player and is not the player that gave the command, the spell is
// discovered as the given player rather than the command sender.
EntityPlayerMP entityplayermp1 = getPlayer(server, sender, arguments[i++]);
if(entityplayermp != entityplayermp1){
entityplayermp = entityplayermp1;
EntityPlayerMP entityplayermp = getPlayer(server, sender, arguments[i++]);
if(player != entityplayermp){
player = entityplayermp;
}
}
// If, after this point, the player is still null, the sender must be a command block or the console and the
// player must not have been specified, meaning an exception should be thrown.
if(entityplayermp == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
if(player == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
WizardData properties = WizardData.get(entityplayermp);
WizardData properties = WizardData.get(player);
if(properties != null){
if(clear){
properties.spellsDiscovered.clear();
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.clear", entityplayermp.getName()));
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.clear", player.getName()));
}else if(all){
properties.spellsDiscovered.addAll(Spell.getSpells(Spell.allSpells));
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.all", entityplayermp.getName()));
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.all", player.getName()));
}else{
if(properties.hasSpellBeenDiscovered(spell)){
properties.spellsDiscovered.remove(spell);
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.removespell", spell.getNameForTranslationFormatted(), entityplayermp.getName()));
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.removespell", spell.getNameForTranslationFormatted(), player.getName()));
}else{
properties.discoverSpell(spell);
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.addspell", spell.getNameForTranslationFormatted(), entityplayermp.getName()));
if(!MinecraftForge.EVENT_BUS.post(new DiscoverSpellEvent(player, spell, DiscoverSpellEvent.Source.COMMAND))){
properties.discoverSpell(spell);
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.addspell", spell.getNameForTranslationFormatted(), player.getName()));
}
}
}
properties.sync();