Skip to content

Commit

Permalink
Merge branch 'morph_commands' into changeling-master
Browse files Browse the repository at this point in the history
  • Loading branch information
asanetargoss committed Mar 1, 2020
2 parents 2f03d59 + 853474d commit 3208f20
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/main/java/mchorse/metamorph/api/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,13 @@ public AbstractMorph morphFromNBT(NBTTagCompound tag)
if (this.factories.get(i).hasMorph(name))
{
AbstractMorph morph = this.factories.get(i).getMorphFromNBT(tag);

this.applySettings(morph);

return morph;

if (morph != null)
{
this.applySettings(morph);

return morph;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/mchorse/metamorph/api/morphs/EntityMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,12 @@ protected void updateEntity(EntityLivingBase target)
{
if (this.settings.updates)
{
if (!Metamorph.proxy.config.show_morph_idle_sounds)
{
this.entity.setSilent(true);
}
this.entity.onUpdate();
this.entity.setSilent(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
throw new CommandException("metamorph.error.acquire", args[1]);
}

sender.addChatMessage(new TextComponentTranslation("metamorph.success.acquire", args[0], args[1]));

if (sender.sendCommandFeedback())
{
sender.addChatMessage(new TextComponentTranslation("metamorph.success.acquire", args[0], args[1]));
}
}

/**
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/mchorse/metamorph/commands/CommandMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import mchorse.metamorph.api.MorphAPI;
import mchorse.metamorph.api.MorphManager;
import mchorse.metamorph.api.morphs.AbstractMorph;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
Expand Down Expand Up @@ -69,17 +70,22 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
if (args.length < 2)
{
MorphAPI.demorph(player);
sender.addChatMessage(new TextComponentTranslation("metamorph.success.demorph", args[0]));
if (sender.sendCommandFeedback())
{
sender.addChatMessage(new TextComponentTranslation("metamorph.success.demorph", args[0]));
}
}
else
{
NBTTagCompound tag = null;
String mergedTagArgs = "";

if (args.length >= 3)
{
try
{
tag = JsonToNBT.getTagFromJson(mergeArgs(args, 2));
mergedTagArgs = mergeArgs(args, 2);
tag = JsonToNBT.getTagFromJson(mergedTagArgs);
}
catch (Exception e)
{
Expand All @@ -94,8 +100,19 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args

tag.setString("Name", args[1]);

MorphAPI.morph(player, MorphManager.INSTANCE.morphFromNBT(tag), true);
sender.addChatMessage(new TextComponentTranslation("metamorph.success.morph", args[0], args[1]));
AbstractMorph newMorph = MorphManager.INSTANCE.morphFromNBT(tag);
boolean morphFound = newMorph != null;

if (!morphFound)
{
throw new CommandException("metamorph.error.morph.factory", args[0], args[1], mergedTagArgs);
}

MorphAPI.morph(player, newMorph, true);
if (sender.sendCommandFeedback())
{
sender.addChatMessage(new TextComponentTranslation("metamorph.success.morph", args[0], args[1]));
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/mchorse/metamorph/config/MetamorphConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public class MetamorphConfig
*/
public boolean morph_in_tight_spaces;

/**
* Whether players make entity idle sounds when morphed
*/
public boolean show_morph_idle_sounds;

/* End of config options */

/**
Expand Down Expand Up @@ -106,6 +111,7 @@ public void reload()
this.disable_morph_disguise = this.config.getBoolean("disable_morph_disguise", cat, false, "Disables the ability of morphs labeled as 'hostile' to avoid being attacked by hostile mobs.", lang + "disable_morph_disguise");
this.acquire_immediately = this.config.getBoolean("acquire_immediately", cat, false, "Acquires morph immediately after player kills an entity instead of spawning a ghost", lang + "acquire_immediately");
this.morph_in_tight_spaces = this.config.getBoolean("morph_in_tight_spaces", cat, false, "Allows morphing even if it could cause suffocation and allow passing through walls", lang + "morph_in_tight_spaces");
this.show_morph_idle_sounds = this.config.getBoolean("show_morph_idle_sounds", cat, true, "When enabled, morphed players make mob idle sounds", lang + "show_morph_idle_sounds");

this.config.getCategory(cat).setComment("General configuration of Metamorph mod");

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mchorse/vanilla_pack/PlayerMorphFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public AbstractMorph getMorphFromNBT(NBTTagCompound tag)

player.fromNBT(tag);

return player;
return player.profile != null ? player : null;
}

return null;
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/metamorph/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ metamorph.config.disable_morph_animation=Disable morph animation
metamorph.config.disable_morph_disguise=Disable morph hostility
metamorph.config.acquire_immediately=Acquire morph immediately
metamorph.config.morph_in_tight_spaces=Allow morphing in tight spaces
metamorph.config.show_morph_idle_sounds=Show morph idle sounds

# Commands
metamorph.commands.morph=Morph command. This command is responsible for morphing player into specified morph.\n\n/morph <username> [morph_name] [data_tag]
Expand All @@ -76,6 +77,7 @@ metamorph.commands.metamorph=Changeling server command. This command allows to m

metamorph.error.morph.not_player=Entity %s isn't not a player!
metamorph.error.morph.nbt=Error occurred during data tag parsing:\n%s
metamorph.error.morph.factory=Could not morph into %2$s with given data tag
metamorph.error.acquire=Couldn't acquire a morph by name %s!
metamorph.success.morph=Player by username %s was successfully morphed into %s!
metamorph.success.demorph=Player by username %s was successfully demorphed!
Expand All @@ -90,4 +92,4 @@ morph.category.boss=Boss morphs
morph.category.acquired=Your morphs
morph.category.hostile=Hostile morphs
morph.category.players=Player morphs
morph.category.modded=Morphs from %s
morph.category.modded=Morphs from %s

0 comments on commit 3208f20

Please sign in to comment.