Skip to content

Commit

Permalink
llama
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTheTech committed Sep 26, 2023
1 parent dbcccff commit 7287c8f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public enum PetItem {
SLIME("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTIwZTg0ZDMyZDFlOWM5MTlkM2ZkYmI1M2YyYjM3YmEyNzRjMTIxYzU3YjI4MTBlNWE0NzJmNDBkYWNmMDA0ZiJ9fX0="),
EVOKER("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDk1NDEzNWRjODIyMTM5NzhkYjQ3ODc3OGFlMTIxMzU5MWI5M2QyMjhkMzZkZDU0ZjFlYTFkYTQ4ZTdjYmE2In19fQ=="),
WANDERING_TRADER("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWYxMzc5YTgyMjkwZDdhYmUxZWZhYWJiYzcwNzEwZmYyZWMwMmRkMzRhZGUzODZiYzAwYzkzMGM0NjFjZjkzMiJ9fX0="),
CREAMY_LLAMA("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmE1ZjEwZTZlNjIzMmYxODJmZTk2NmY1MDFmMWMzNzk5ZDQ1YWUxOTAzMWExZTQ5NDFiNWRlZTBmZWZmMDU5YiJ9fX0="),
LLAMA("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmE1ZjEwZTZlNjIzMmYxODJmZTk2NmY1MDFmMWMzNzk5ZDQ1YWUxOTAzMWExZTQ5NDFiNWRlZTBmZWZmMDU5YiJ9fX0="),
PIGLIN("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjg4MmFmMTI5NGE3NDAyM2U2OTE5YTMxZDFhMDI3MzEwZjJlMTQyYWZiNDY2N2QyMzBkMTU1ZTdmMjFkYmI0MSJ9fX0="),
ZOMBIFIED_PIGLIN("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTkzNTg0MmFmNzY5MzgwZjc4ZThiOGE4OGQxZWE2Y2EyODA3YzFlNTY5M2MyY2Y3OTc0NTY2MjA4MzNlOTM2ZiJ9fX0="),
POLAR_BEAR("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDQ2ZDIzZjA0ODQ2MzY5ZmEyYTM3MDJjMTBmNzU5MTAxYWY3YmZlODQxOTk2NjQyOTUzM2NkODFhMTFkMmIifX19"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum OptionSelector {
HOGLIN(new String[] {Option.NAME.name(), Option.BABY.name()}),
HORSE(new String[] {Option.NAME.name(), Option.BABY.name(), Option.SADDLE.name(), Option.VARIANT.name(), Option.MARKING.name()}),
IRON_GOLEM(new String[] {Option.NAME.name()}),
LLAMA(new String[] {Option.NAME.name(), Option.BABY.name(), Option.CHEST.name(), Option.VARIANT.name(), Option.SADDLE.name(), Option.COLOR.name()}),

;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lee/code/pets/pets/pet/animal/HorsePet.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public HorsePet(Player player, String[] data) {

@Override
protected void registerGoals() {
goalSelector.addGoal(0, new FollowOwnerGoal(this, 2));
goalSelector.addGoal(0, new FollowOwnerGoal(this, 3));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lee/code/pets/pets/pet/animal/LlamaPet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public LlamaPet(Player player, String[] data) {
setBaby(Boolean.parseBoolean(data[2]));
setChest(Boolean.parseBoolean(data[3]));
setVariant(Variant.valueOf(data[4]));
if (Boolean.parseBoolean(data[5])) inventory.setItem(1, CraftItemStack.asNMSCopy(new ItemStack(Material.valueOf(data[6]))));
if (Boolean.parseBoolean(data[5])) inventory.setItem(1, CraftItemStack.asNMSCopy(new ItemStack(Material.valueOf(data[6] + "_CARPET"))));
setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false);
moveControl = new ControllerWASD(this, player.getUniqueId());
targetSelector.getAvailableGoals().clear();
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/lee/code/pets/utils/PetDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import lee.code.pets.pets.pet.util.HorseVariantUtil;
import lee.code.pets.pets.pet.util.ParrotVariantUtil;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -83,6 +85,16 @@ public static String getPetData(EntityType entityType, String[] data, Option opt
case MARKING -> {return data[5];}
}
}
case LLAMA -> {
switch (option) {
case NAME -> {return data[1];}
case BABY -> {return data[2];}
case CHEST -> {return data[3];}
case VARIANT -> {return data[4];}
case SADDLE -> {return data[5];}
case COLOR -> {return data[6];}
}
}
}
return null;
}
Expand Down Expand Up @@ -137,6 +149,14 @@ public static String serializePetData(Entity entity) {
final boolean hasSaddle = entity instanceof Horse horse && horse.getInventory().getSaddle() != null;
return startingData + sep + isBaby + sep + hasSaddle + sep + horseVariant.name() + sep + horseMarking.name();
}
case LLAMA -> {
final Llama.Color llamaVariant = entity instanceof Llama llama ? llama.getColor() : Llama.Color.WHITE;
final boolean hasChest = entity instanceof Llama llama && llama.isCarryingChest();
final ItemStack saddleItem = entity instanceof Llama llama ? llama.getInventory().getSaddle() : null;
final boolean hasSaddle = saddleItem != null;
final DyeColor color = saddleItem == null ? DyeColor.WHITE : DyeColor.valueOf(saddleItem.getType().name().substring(0, saddleItem.getType().name().indexOf('_')));
return startingData + sep + isBaby + sep + hasChest + sep + llamaVariant + sep + hasSaddle + sep + color.name();
}
}
return null;
}
Expand Down Expand Up @@ -212,6 +232,16 @@ public static String addNewPetData(EntityType entityType, String[] data, String
case MARKING -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + data[4] + sep + newData;}
}
}
case LLAMA -> {
switch (option) {
case NAME -> {return data[0] + sep + newData + sep + data[2] + sep + data[3] + sep + data[4] + sep + data[5] + sep + data[6];}
case BABY -> {return data[0] + sep + data[1] + sep + newData + sep + data[3] + sep + data[4] + sep + data[5] + sep + data[6];}
case CHEST -> {return data[0] + sep + data[1] + sep + data[2] + sep + newData + sep + data[4] + sep + data[5] + sep + data[6];}
case VARIANT -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + newData + sep + data[5] + sep + data[6];}
case SADDLE -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + data[4] + sep + newData + sep + data[6];}
case COLOR -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + data[4] + sep + data[5] + sep + newData;}
}
}
}
return null;
}
Expand Down Expand Up @@ -246,6 +276,12 @@ public static String getNextVariant(EntityType entityType, String variant) {
final HorseVariantUtil nextVariant = horseVariant.ordinal() + 1 < variants.size() ? variants.get(horseVariant.ordinal() + 1) : variants.get(0);
return nextVariant.name();
}
case LLAMA -> {
final Llama.Color llamaVariant = Llama.Color.valueOf(variant);
final ArrayList<Llama.Color> variants = new ArrayList<>(List.of(Llama.Color.values()));
final Llama.Color nextVariant = llamaVariant.ordinal() + 1 < variants.size() ? variants.get(llamaVariant.ordinal() + 1) : variants.get(0);
return nextVariant.name();
}
}
return null;
}
Expand Down

0 comments on commit 7287c8f

Please sign in to comment.