mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-09 01:47:54 +01:00
Modernize the demo package
This commit is contained in:
parent
a25e414754
commit
7241dbdcf7
@ -23,8 +23,9 @@ public class ArgumentEnum<E extends Enum> extends Argument<E> {
|
||||
this.values = enumClass.getEnumConstants();
|
||||
}
|
||||
|
||||
public void setFormat(@NotNull Format format) {
|
||||
public ArgumentEnum setFormat(@NotNull Format format) {
|
||||
this.format = format;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -18,67 +18,87 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class ArgumentType {
|
||||
|
||||
/**
|
||||
* @see ArgumentLiteral
|
||||
*/
|
||||
public static ArgumentLiteral Literal(@NotNull String id) {
|
||||
return new ArgumentLiteral(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentGroup
|
||||
*/
|
||||
public static ArgumentGroup Group(@NotNull String id, @NotNull Argument<?>... arguments) {
|
||||
return new ArgumentGroup(id, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentLoop
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> ArgumentLoop<T> Loop(@NotNull String id, @NotNull Argument<T>... arguments) {
|
||||
return new ArgumentLoop<>(id, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentBoolean
|
||||
*/
|
||||
public static ArgumentBoolean Boolean(@NotNull String id) {
|
||||
return new ArgumentBoolean(id);
|
||||
}
|
||||
|
||||
public static ArgumentLong Long(@NotNull String id) {
|
||||
return new ArgumentLong(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentInteger
|
||||
*/
|
||||
public static ArgumentInteger Integer(@NotNull String id) {
|
||||
return new ArgumentInteger(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentDouble
|
||||
*/
|
||||
public static ArgumentDouble Double(@NotNull String id) {
|
||||
return new ArgumentDouble(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentFloat
|
||||
*/
|
||||
public static ArgumentFloat Float(@NotNull String id) {
|
||||
return new ArgumentFloat(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentString
|
||||
*/
|
||||
public static ArgumentString String(@NotNull String id) {
|
||||
return new ArgumentString(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentWord
|
||||
*/
|
||||
public static ArgumentWord Word(@NotNull String id) {
|
||||
return new ArgumentWord(id);
|
||||
}
|
||||
|
||||
public static ArgumentDynamicWord DynamicWord(@NotNull String id, @NotNull SuggestionType suggestionType) {
|
||||
return new ArgumentDynamicWord(id, suggestionType);
|
||||
}
|
||||
|
||||
public static ArgumentDynamicWord DynamicWord(@NotNull String id) {
|
||||
return DynamicWord(id, SuggestionType.ASK_SERVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentStringArray
|
||||
*/
|
||||
public static ArgumentStringArray StringArray(@NotNull String id) {
|
||||
return new ArgumentStringArray(id);
|
||||
}
|
||||
|
||||
public static ArgumentDynamicStringArray DynamicStringArray(@NotNull String id) {
|
||||
return new ArgumentDynamicStringArray(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentCommand
|
||||
*/
|
||||
public static ArgumentCommand Command(@NotNull String id) {
|
||||
return new ArgumentCommand(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentEnum
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static <E extends Enum> ArgumentEnum<E> Enum(@NotNull String id, @NotNull Class<E> enumClass) {
|
||||
return new ArgumentEnum<>(id, enumClass);
|
||||
@ -86,72 +106,167 @@ public class ArgumentType {
|
||||
|
||||
// Minecraft specific arguments
|
||||
|
||||
/**
|
||||
* @see ArgumentColor
|
||||
*/
|
||||
public static ArgumentColor Color(@NotNull String id) {
|
||||
return new ArgumentColor(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentTime
|
||||
*/
|
||||
public static ArgumentTime Time(@NotNull String id) {
|
||||
return new ArgumentTime(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentEnchantment
|
||||
*/
|
||||
public static ArgumentEnchantment Enchantment(@NotNull String id) {
|
||||
return new ArgumentEnchantment(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentParticle
|
||||
*/
|
||||
public static ArgumentParticle Particle(@NotNull String id) {
|
||||
return new ArgumentParticle(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentPotionEffect
|
||||
*/
|
||||
public static ArgumentPotionEffect Potion(@NotNull String id) {
|
||||
return new ArgumentPotionEffect(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentEntityType
|
||||
*/
|
||||
public static ArgumentEntityType EntityType(@NotNull String id) {
|
||||
return new ArgumentEntityType(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentBlockState
|
||||
*/
|
||||
public static ArgumentBlockState BlockState(@NotNull String id) {
|
||||
return new ArgumentBlockState(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentIntRange
|
||||
*/
|
||||
public static ArgumentIntRange IntRange(@NotNull String id) {
|
||||
return new ArgumentIntRange(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentFloatRange
|
||||
*/
|
||||
public static ArgumentFloatRange FloatRange(@NotNull String id) {
|
||||
return new ArgumentFloatRange(id);
|
||||
}
|
||||
|
||||
public static ArgumentEntity Entities(@NotNull String id) {
|
||||
/**
|
||||
* @see ArgumentEntity
|
||||
*/
|
||||
public static ArgumentEntity Entity(@NotNull String id) {
|
||||
return new ArgumentEntity(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentItemStack
|
||||
*/
|
||||
public static ArgumentItemStack ItemStack(@NotNull String id) {
|
||||
return new ArgumentItemStack(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentComponent
|
||||
*/
|
||||
public static ArgumentComponent Component(@NotNull String id) {
|
||||
return new ArgumentComponent(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentNbtTag
|
||||
*/
|
||||
public static ArgumentNbtTag NBT(@NotNull String id) {
|
||||
return new ArgumentNbtTag(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentNbtCompoundTag
|
||||
*/
|
||||
public static ArgumentNbtCompoundTag NbtCompound(@NotNull String id) {
|
||||
return new ArgumentNbtCompoundTag(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentRelativeBlockPosition
|
||||
*/
|
||||
public static ArgumentRelativeBlockPosition RelativeBlockPosition(@NotNull String id) {
|
||||
return new ArgumentRelativeBlockPosition(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentRelativeVec3
|
||||
*/
|
||||
public static ArgumentRelativeVec3 RelativeVec3(@NotNull String id) {
|
||||
return new ArgumentRelativeVec3(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentRelativeVec2
|
||||
*/
|
||||
public static ArgumentRelativeVec2 RelativeVec2(@NotNull String id) {
|
||||
return new ArgumentRelativeVec2(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentLoop
|
||||
* @deprecated brigadier does not support long
|
||||
*/
|
||||
@Deprecated
|
||||
public static ArgumentLong Long(@NotNull String id) {
|
||||
return new ArgumentLong(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentEntity
|
||||
* @deprecated use {@link #Entity(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static ArgumentEntity Entities(@NotNull String id) {
|
||||
return new ArgumentEntity(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentDynamicWord
|
||||
* @deprecated will be replaced soon
|
||||
*/
|
||||
@Deprecated
|
||||
public static ArgumentDynamicWord DynamicWord(@NotNull String id, @NotNull SuggestionType suggestionType) {
|
||||
return new ArgumentDynamicWord(id, suggestionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentDynamicWord
|
||||
* @deprecated will be replaced soon
|
||||
*/
|
||||
@Deprecated
|
||||
public static ArgumentDynamicWord DynamicWord(@NotNull String id) {
|
||||
return DynamicWord(id, SuggestionType.ASK_SERVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArgumentDynamicStringArray
|
||||
* @deprecated will be replaced soon
|
||||
*/
|
||||
@Deprecated
|
||||
public static ArgumentDynamicStringArray DynamicStringArray(@NotNull String id) {
|
||||
return new ArgumentDynamicStringArray(id);
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -18,7 +18,7 @@ public class EntitySelectorCommand extends Command {
|
||||
|
||||
setDefaultExecutor((sender, args) -> System.out.println("DEFAULT"));
|
||||
|
||||
ArgumentEntity argumentEntity = ArgumentType.Entities("entities").onlyPlayers(true);
|
||||
ArgumentEntity argumentEntity = ArgumentType.Entity("entities").onlyPlayers(true);
|
||||
|
||||
setArgumentCallback((sender, exception) -> exception.printStackTrace(), argumentEntity);
|
||||
|
||||
@ -28,7 +28,8 @@ public class EntitySelectorCommand extends Command {
|
||||
|
||||
private void executor(CommandSender commandSender, Arguments arguments) {
|
||||
Instance instance = commandSender.asPlayer().getInstance();
|
||||
List<Entity> entities = arguments.getEntities("entities").find(instance, null);
|
||||
System.out.println("test " + ((Player) entities.get(0)).getUsername());
|
||||
EntityFinder entityFinder = arguments.get("entities");
|
||||
List<Entity> entities = entityFinder.find(commandSender);
|
||||
System.out.println("found " + entities.size() + " entities");
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,12 @@ package demo.commands;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Arguments;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentEnum;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
|
||||
/**
|
||||
* Command that make a player change gamemode
|
||||
@ -22,15 +21,14 @@ public class GamemodeCommand extends Command {
|
||||
|
||||
setDefaultExecutor(this::usage);
|
||||
|
||||
Argument player = ArgumentType.Word("player");
|
||||
var player = ArgumentType.Entity("player")
|
||||
.onlyPlayers(true)
|
||||
.singleEntity(true);
|
||||
|
||||
GameMode[] gameModes = GameMode.values();
|
||||
String[] names = new String[gameModes.length];
|
||||
for (int i = 0; i < gameModes.length; i++) {
|
||||
names[i] = gameModes[i].name().toLowerCase();
|
||||
}
|
||||
Argument mode = ArgumentType.Word("mode").from(names);
|
||||
var mode = ArgumentType.Enum("gamemode", GameMode.class)
|
||||
.setFormat(ArgumentEnum.Format.LOWER_CASED);
|
||||
|
||||
setArgumentCallback(this::targetCallback, player);
|
||||
setArgumentCallback(this::gameModeCallback, mode);
|
||||
|
||||
addSyntax(this::executeOnSelf, mode);
|
||||
@ -44,27 +42,24 @@ public class GamemodeCommand extends Command {
|
||||
private void executeOnSelf(CommandSender sender, Arguments arguments) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
String gamemodeName = arguments.getWord("mode");
|
||||
GameMode mode = GameMode.valueOf(gamemodeName.toUpperCase());
|
||||
assert mode != null; // mode is not supposed to be null, because gamemodeName will be valid
|
||||
player.setGameMode(mode);
|
||||
player.sendMessage("You are now playing in " + gamemodeName);
|
||||
GameMode gamemode = arguments.get("gamemode");
|
||||
assert gamemode != null; // mode is not supposed to be null, because gamemodeName will be valid
|
||||
player.setGameMode(gamemode);
|
||||
player.sendMessage("You are now playing in " + gamemode.toString().toLowerCase());
|
||||
}
|
||||
|
||||
private void executeOnOther(CommandSender sender, Arguments arguments) {
|
||||
Player player = (Player) sender;
|
||||
GameMode gamemode = arguments.get("gamemode");
|
||||
EntityFinder targetFinder = arguments.get("player");
|
||||
Player target = targetFinder.findFirstPlayer(sender);
|
||||
assert gamemode != null; // mode is not supposed to be null, because gamemodeName will be valid
|
||||
assert target != null;
|
||||
target.setGameMode(gamemode);
|
||||
target.sendMessage("You are now playing in " + gamemode.toString().toLowerCase());
|
||||
}
|
||||
|
||||
String gamemodeName = arguments.getWord("mode");
|
||||
String targetName = arguments.getWord("player");
|
||||
GameMode mode = GameMode.valueOf(gamemodeName.toUpperCase());
|
||||
assert mode != null; // mode is not supposed to be null, because gamemodeName will be valid
|
||||
Optional<Player> target = player.getInstance().getPlayers().stream().filter(p -> p.getUsername().equalsIgnoreCase(targetName)).findFirst();
|
||||
if (target.isPresent()) {
|
||||
target.get().setGameMode(mode);
|
||||
target.get().sendMessage("You are now playing in " + gamemodeName);
|
||||
} else {
|
||||
player.sendMessage("'" + targetName + "' is not a valid player name.");
|
||||
}
|
||||
private void targetCallback(CommandSender sender, ArgumentSyntaxException exception) {
|
||||
sender.sendMessage("'" + exception.getInput() + "' is not a valid player name.");
|
||||
}
|
||||
|
||||
private void gameModeCallback(CommandSender sender, ArgumentSyntaxException exception) {
|
||||
|
@ -58,13 +58,13 @@ public class HealthCommand extends Command {
|
||||
}
|
||||
|
||||
private void sendSuggestionMessage(CommandSender sender, Arguments args) {
|
||||
sender.sendMessage("/health " + args.getWord("mode") + " [Integer]");
|
||||
sender.sendMessage("/health " + args.get("mode") + " [Integer]");
|
||||
}
|
||||
|
||||
private void onHealthCommand(CommandSender sender, Arguments args) {
|
||||
final Player player = (Player) sender;
|
||||
final String mode = args.getWord("mode");
|
||||
final int value = args.getInteger("value");
|
||||
final String mode = args.get("mode");
|
||||
final int value = args.get("value");
|
||||
|
||||
switch (mode.toLowerCase()) {
|
||||
case "set":
|
||||
|
@ -65,11 +65,11 @@ public class HorseCommand extends Command {
|
||||
boolean baby = args.get("baby");
|
||||
HorseMeta.Marking marking = args.get("marking");
|
||||
HorseMeta.Color color = args.get("color");
|
||||
var horse = new EntityCreature(EntityType.HORSE, player.getPosition());
|
||||
var horse = new EntityCreature(EntityType.HORSE);
|
||||
var meta = (HorseMeta) horse.getEntityMeta();
|
||||
meta.setBaby(baby);
|
||||
meta.setVariant(new HorseMeta.Variant(marking, color));
|
||||
horse.setInstance(player.getInstance());
|
||||
horse.setInstance(player.getInstance(), player.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Arguments;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.potion.Potion;
|
||||
@ -21,8 +20,8 @@ public class PotionCommand extends Command {
|
||||
sender.sendMessage("Usage: /potion [type] [duration (seconds)]");
|
||||
}));
|
||||
|
||||
Argument potionArg = ArgumentType.Potion("potion");
|
||||
Argument durationArg = ArgumentType.Integer("duration");
|
||||
var potionArg = ArgumentType.Potion("potion");
|
||||
var durationArg = ArgumentType.Integer("duration");
|
||||
|
||||
addSyntax(this::onPotionCommand, potionArg, durationArg);
|
||||
}
|
||||
@ -37,8 +36,8 @@ public class PotionCommand extends Command {
|
||||
|
||||
private void onPotionCommand(CommandSender sender, Arguments args) {
|
||||
final Player player = (Player) sender;
|
||||
final PotionEffect potion = args.getPotionEffect("potion");
|
||||
final int duration = args.getInteger("duration");
|
||||
final PotionEffect potion = args.get("potion");
|
||||
final int duration = args.get("duration");
|
||||
|
||||
player.sendMessage(player.getActiveEffects().toString());
|
||||
player.addEffect(new Potion(
|
||||
|
@ -41,7 +41,7 @@ public class ShootCommand extends Command {
|
||||
|
||||
private void onShootCommand(CommandSender sender, Arguments args) {
|
||||
Player player = (Player) sender;
|
||||
String mode = args.getWord("type");
|
||||
String mode = args.get("type");
|
||||
EntityProjectile projectile;
|
||||
switch (mode) {
|
||||
case "default":
|
||||
|
@ -4,7 +4,6 @@ import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Arguments;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.utils.Position;
|
||||
@ -17,27 +16,27 @@ public class TeleportCommand extends Command {
|
||||
|
||||
setDefaultExecutor((source, args) -> source.sendMessage("Usage: /tp x y z"));
|
||||
|
||||
Argument posArg = ArgumentType.RelativeVec3("pos");
|
||||
Argument playerArg = ArgumentType.Word("player");
|
||||
var posArg = ArgumentType.RelativeVec3("pos");
|
||||
var playerArg = ArgumentType.Word("player");
|
||||
|
||||
addSyntax(this::onPlayerTeleport, playerArg);
|
||||
addSyntax(this::onPositionTeleport, posArg);
|
||||
}
|
||||
|
||||
private void onPlayerTeleport(CommandSender sender, Arguments args) {
|
||||
final String playerName = args.getWord("player");
|
||||
final String playerName = args.get("player");
|
||||
Player pl = MinecraftServer.getConnectionManager().getPlayer(playerName);
|
||||
if (pl != null && sender.isPlayer()) {
|
||||
Player player = (Player) sender;
|
||||
player.teleport(pl.getPosition());
|
||||
}
|
||||
sender.sendMessage("Teleported to player "+playerName);
|
||||
sender.sendMessage("Teleported to player " + playerName);
|
||||
}
|
||||
|
||||
private void onPositionTeleport(CommandSender sender, Arguments args) {
|
||||
final Player player = sender.asPlayer();
|
||||
|
||||
final RelativeVec relativeVec = args.getRelativeVector("pos");
|
||||
final RelativeVec relativeVec = args.get("pos");
|
||||
final Position position = relativeVec.from(player).toPosition();
|
||||
|
||||
player.teleport(position);
|
||||
|
@ -1,14 +1,12 @@
|
||||
package demo.commands;
|
||||
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Arguments;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.minestom.server.command.builder.arguments.ArgumentType.Component;
|
||||
import static net.minestom.server.command.builder.arguments.ArgumentType.Integer;
|
||||
import static net.minestom.server.command.builder.arguments.ArgumentType.*;
|
||||
|
||||
public class TestCommand extends Command {
|
||||
|
||||
@ -16,17 +14,11 @@ public class TestCommand extends Command {
|
||||
super("testcmd");
|
||||
setDefaultExecutor(this::usage);
|
||||
|
||||
addSyntax((sender, args) -> {
|
||||
final CommandResult result = args.get("command");
|
||||
System.out.println("test " + result.getType() + " " + result.getInput());
|
||||
}, Literal("cmd"), Command("command"));
|
||||
var number = Integer("number2");
|
||||
|
||||
addSyntax((sender, args) -> {
|
||||
List<Arguments> groups = args.get("groups");
|
||||
System.out.println("size " + groups.size());
|
||||
}, Literal("loop"), Loop("groups",
|
||||
Group("group", Literal("name"), Word("word1")),
|
||||
Group("group2", Literal("delay"), Integer("number2"))));
|
||||
sender.sendMessage((JsonMessage) args.get("msg"));
|
||||
}, Component("msg"));
|
||||
}
|
||||
|
||||
private void usage(CommandSender sender, Arguments arguments) {
|
||||
|
@ -31,7 +31,7 @@ public class TitleCommand extends Command {
|
||||
}
|
||||
|
||||
Player player = source.asPlayer();
|
||||
String titleContent = args.getString("content");
|
||||
String titleContent = args.get("content");
|
||||
|
||||
player.sendTitleTime(10, 100, 10);
|
||||
try {
|
||||
|
@ -2,24 +2,18 @@ package demo.entity;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minestom.server.attribute.Attributes;
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.ai.EntityAIGroupBuilder;
|
||||
import net.minestom.server.entity.ai.goal.DoNothingGoal;
|
||||
import net.minestom.server.entity.ai.goal.MeleeAttackGoal;
|
||||
import net.minestom.server.entity.ai.goal.RandomStrollGoal;
|
||||
import net.minestom.server.entity.ai.target.ClosestEntityTarget;
|
||||
import net.minestom.server.entity.ai.target.LastEntityDamagerTarget;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.entity.type.animal.EntityChicken;
|
||||
import net.minestom.server.event.entity.EntityAttackEvent;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.Vector;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
|
||||
public class ChickenCreature extends EntityChicken {
|
||||
public class ChickenCreature extends EntityCreature {
|
||||
|
||||
public ChickenCreature(Position defaultPosition) {
|
||||
super(defaultPosition);
|
||||
public ChickenCreature() {
|
||||
super(EntityType.CHICKEN);
|
||||
|
||||
addAIGroup(
|
||||
ImmutableList.of(
|
||||
|
@ -1,14 +1,14 @@
|
||||
package demo.entity;
|
||||
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.ai.EntityAIGroupBuilder;
|
||||
import net.minestom.server.entity.ai.goal.RandomLookAroundGoal;
|
||||
import net.minestom.server.entity.type.monster.EntityZombie;
|
||||
import net.minestom.server.utils.Position;
|
||||
|
||||
public class ZombieCreature extends EntityZombie {
|
||||
public class ZombieCreature extends EntityCreature {
|
||||
|
||||
public ZombieCreature(Position spawnPosition) {
|
||||
super(spawnPosition);
|
||||
public ZombieCreature() {
|
||||
super(EntityType.ZOMBIE);
|
||||
addAIGroup(
|
||||
new EntityAIGroupBuilder()
|
||||
.addGoalSelector(new RandomLookAroundGoal(this, 20))
|
||||
|
@ -1,7 +1,8 @@
|
||||
package improveextensions.unloadcallbacks;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.type.monster.EntityZombie;
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.event.EventCallback;
|
||||
import net.minestom.server.event.GlobalEventHandler;
|
||||
import net.minestom.server.event.entity.EntityTickEvent;
|
||||
@ -42,14 +43,14 @@ public class UnloadCallbacksExtension extends Extension {
|
||||
|
||||
// add an event callback on an instance
|
||||
instance.addEventCallback(InstanceTickEvent.class, e -> instanceTicked = true);
|
||||
instance.loadChunk(0,0);
|
||||
instance.loadChunk(0, 0);
|
||||
|
||||
// add an event callback on an entity
|
||||
EntityZombie zombie = new EntityZombie(new Position(8,64,8) /* middle of chunk */);
|
||||
EntityCreature zombie = new EntityCreature(EntityType.ZOMBIE);
|
||||
zombie.addEventCallback(EntityTickEvent.class, e -> {
|
||||
zombieTicked = true;
|
||||
});
|
||||
zombie.setInstance(instance);
|
||||
zombie.setInstance(instance, new Position(8, 64, 8) /* middle of chunk */);
|
||||
|
||||
// this callback will be cancelled
|
||||
MinecraftServer.getSchedulerManager().buildTask(() -> {
|
||||
|
Loading…
Reference in New Issue
Block a user