Skip to content

Commit

Permalink
Added /heal
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro270707 committed Jan 21, 2024
1 parent 2df03bb commit 1a3b7b4
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 3 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ repositories {
}
metadataSources { artifact() }
}
ivy {
url = "https://github.com/ToufouMaster"
patternLayout {
artifact "[organisation]/releases/download/[revision]/[module]-[revision].jar"
m2compatible = true
}
metadataSources { artifact() }
}
}

dependencies {
Expand All @@ -90,6 +98,7 @@ dependencies {
// If you do not need Halplibe you can comment this line out or delete this line
modImplementation "com.github.Turnip-Labs:bta-halplibe:${project.halplibe_version}"

modImplementation "BTWaila:btwaila:1.0.8-7.1"
modImplementation "ModMenu:ModMenu:2.0.0"

include modImplementation('com.mojang:brigadier:1.0.18')
Expand Down
2 changes: 1 addition & 1 deletion output/production/commander-bta.main/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "commander",
"version": "1.2.10",
"version": "1.2.11",

"name": "Commander",
"description": "This mod overhauls the command system.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ argument_types.commander.block.invalid_block=Invalid block ID
argument_types.commander.item.invalid_item=Invalid item ID
argument_types.commander.dimension.invalid_dimension=Invalid dimension ID
argument_types.commander.biome.invalid_biome=Invalid biome ID
argument_types.commander.damage_type.invalid_damage_type=Invalid damage type ID
argument_types.commander.gamerule.invalid_value=Invalid game rule value
argument_types.commander.entity.invalid_selector.single_player_only=Selector includes more than one entity, but command only accepts a single player as an argument
argument_types.commander.entity.invalid_selector.single_entity_only=Selector includes more than one entity, but command only accepts a single entity as an argument
Expand Down Expand Up @@ -149,4 +150,8 @@ commands.commander.testfor.entity.none=No entities match the given selector
commands.commander.testfor.entity.single=%s entity matches the given selector
commands.commander.testfor.entity.plural=%s entities match the given selector
commands.commander.testfor.block.success=The two blocks are equal
commands.commander.testfor.block.failure=The two blocks are not equal
commands.commander.testfor.block.failure=The two blocks are not equal
commands.commander.damage.success_single=Damaged %s entity
commands.commander.damage.success_multiple=Damaged %s entities
commands.commander.heal.success_single=Healed %s entity
commands.commander.heal.success_multiple=Healed %s entities
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void init() {
TellRawCommand.register(DISPATCHER);
TestForCommand.register(DISPATCHER);
DamageCommand.register(DISPATCHER);
HealCommand.register(DISPATCHER);

if (this.isServer) {
StopCommand.register(DISPATCHER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void register(CommandDispatcher<CommanderCommandSource> dispatcher
for (Entity entity : entities) {
if (entity.hurt(null, amount, type)) ++entitiesAffected;
}
c.getSource().sendTranslatableMessage("commands.commander.damage.success_" + (entitiesAffected == 1 ? "single" : "multiple"), entitiesAffected);
return entitiesAffected;
})))));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.pedroricardo.commander.content.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.EntityLiving;
import net.minecraft.core.util.helper.MathHelper;
import net.minecraft.core.world.World;
import net.pedroricardo.commander.content.CommanderCommandSource;
import net.pedroricardo.commander.content.arguments.EntityArgumentType;
import net.pedroricardo.commander.content.helpers.EntitySelector;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

public class HealCommand {
public static void register(CommandDispatcher<CommanderCommandSource> dispatcher) {
dispatcher.register(LiteralArgumentBuilder.<CommanderCommandSource>literal("heal")
.then(RequiredArgumentBuilder.<CommanderCommandSource, EntitySelector>argument("entities", EntityArgumentType.entities())
.then(RequiredArgumentBuilder.<CommanderCommandSource, Integer>argument("amount", IntegerArgumentType.integer(0, 32768))
.executes(c -> {
List<? extends Entity> entities = c.getArgument("entities", EntitySelector.class).get(c.getSource());
int amount = c.getArgument("amount", Integer.class);

int entitiesAffected = 0;
for (Entity entity : entities) {
if (entity instanceof EntityLiving) {
int maxHealth = 20;
try {
maxHealth = ((EntityLiving)entity.getClass().getConstructor(World.class).newInstance(c.getSource().getWorld())).health;
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ignored) {
}
int originalHealth = ((EntityLiving)entity).health;
((EntityLiving)entity).health = MathHelper.clamp(((EntityLiving)entity).health + amount, 0, maxHealth);
if (((EntityLiving)entity).health != originalHealth) ++entitiesAffected;
}
}
c.getSource().sendTranslatableMessage("commands.commander.heal.success_" + (entitiesAffected == 1 ? "single" : "multiple"), entitiesAffected);
return entitiesAffected;
}))));
}
}
6 changes: 5 additions & 1 deletion src/main/resources/lang/commander/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,8 @@ commands.commander.testfor.entity.none=No entities match the given selector
commands.commander.testfor.entity.single=%s entity matches the given selector
commands.commander.testfor.entity.plural=%s entities match the given selector
commands.commander.testfor.block.success=The two blocks are equal
commands.commander.testfor.block.failure=The two blocks are not equal
commands.commander.testfor.block.failure=The two blocks are not equal
commands.commander.damage.success_single=Damaged %s entity
commands.commander.damage.success_multiple=Damaged %s entities
commands.commander.heal.success_single=Healed %s entity
commands.commander.heal.success_multiple=Healed %s entities

0 comments on commit 1a3b7b4

Please sign in to comment.