Skip to content

Commit

Permalink
horse
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTheTech committed Sep 26, 2023
1 parent f90588a commit 4822965
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/main/java/lee/code/pets/menus/menu/PetOptionMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.logging.Level;

public class PetOptionMenu extends MenuPaginatedGUI {
private final Pets pets;
private final EntityType entityType;
Expand Down Expand Up @@ -76,6 +74,10 @@ private MenuButton createOptionButton(Player player, Option option) {
final String variant = PetDataUtil.getNextVariant(entityType, targetData);
cachePets.updatePetData(petID, PetDataUtil.addNewPetData(entityType, petData, variant, option));
}
case MARKING -> {
final String marking = PetDataUtil.getNextHorseMarking(targetData);
cachePets.updatePetData(petID, PetDataUtil.addNewPetData(entityType, petData, marking, option));
}
case BABY, SADDLE, CHEST, HORNS -> {
final String petOption = String.valueOf(!Boolean.parseBoolean(targetData));
cachePets.updatePetData(petID, PetDataUtil.addNewPetData(entityType, petData, petOption, option));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum Option {
VARIANT(Material.TURTLE_EGG, "&e&lVariant"),
SADDLE(Material.SADDLE, "&e&lSaddle"),
CHEST(Material.CHEST, "&e&lChest"),
HORNS(Material.GOAT_HORN, "&e&lHorns")
HORNS(Material.GOAT_HORN, "&e&lHorns"),
MARKING(Material.HORSE_SPAWN_EGG, "&e&lMarking")

;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public enum OptionSelector {
DONKEY(new String[] {Option.NAME.name(), Option.BABY.name(), Option.CHEST.name(), Option.SADDLE.name()}),
FOX(new String[] {Option.NAME.name(), Option.BABY.name(), Option.VARIANT.name()}),
GOAT(new String[] {Option.NAME.name(), Option.BABY.name(), Option.HORNS.name()}),
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()}),

;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/lee/code/pets/pets/pet/animal/CatPet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lee.code.pets.pets.controllers.ControllerWASD;
import lee.code.pets.pets.goals.FollowOwnerGoal;
import lee.code.pets.pets.pet.util.CatUtil;
import lee.code.pets.pets.pet.util.CatVariantUtil;
import lee.code.pets.utils.CoreUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand All @@ -29,7 +29,7 @@ public CatPet(Player player, String[] data) {
ageLocked = true;
setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(data[1])));
setBaby(Boolean.parseBoolean(data[2]));
setVariant(CatUtil.valueOf(data[3]).getCatVariant());
setVariant(CatVariantUtil.valueOf(data[3]).getCatVariant());
setCollarColor(DyeColor.valueOf(data[4]));
setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false);
moveControl = new ControllerWASD(this, player.getUniqueId());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/lee/code/pets/pets/pet/fish/FrogPet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lee.code.pets.pets.controllers.ControllerWASDWater;
import lee.code.pets.pets.goals.FollowOwnerWaterGoal;
import lee.code.pets.pets.pet.util.FrogUtil;
import lee.code.pets.pets.pet.util.FrogVariantUtil;
import lee.code.pets.utils.CoreUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand All @@ -26,7 +26,7 @@ public FrogPet(Player player, String[] data) {
collides = false;
ageLocked = true;
setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(data[1])));
setVariant(FrogUtil.valueOf(data[2]).getFrogVariant());
setVariant(FrogVariantUtil.valueOf(data[2]).getFrogVariant());
setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false);
moveControl = new ControllerWASDWater(this, player.getUniqueId(), true, false);
targetSelector.getAvailableGoals().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.world.entity.animal.CatVariant;

@AllArgsConstructor
public enum CatUtil {
public enum CatVariantUtil {
WHITE(BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.WHITE)),
JELLIE(BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.JELLIE)),
BLACK(BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.BLACK)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.world.entity.animal.FrogVariant;

@AllArgsConstructor
public enum FrogUtil {
public enum FrogVariantUtil {
COLD(FrogVariant.COLD),
WARM(FrogVariant.WARM),
TEMPERATE(FrogVariant.TEMPERATE)
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/lee/code/pets/pets/pet/util/HorseMarkingUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lee.code.pets.pets.pet.util;

import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.world.entity.animal.horse.Horse;
import net.minecraft.world.entity.animal.horse.Markings;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;

@AllArgsConstructor
public enum HorseMarkingUtil {
WHITE(Markings.WHITE),
BLACK_DOTS(Markings.BLACK_DOTS),
WHITE_DOTS(Markings.WHITE_DOTS),
WHITE_FIELD(Markings.WHITE_FIELD),
NONE(Markings.NONE)
;
@Getter private final Markings marking;

public static HorseMarkingUtil getMarking(Entity entity) {
if (((CraftEntity) entity).getHandle() instanceof Horse horse) return HorseMarkingUtil.valueOf(horse.getMarkings().name());
return HorseMarkingUtil.NONE;
}
}
26 changes: 26 additions & 0 deletions src/main/java/lee/code/pets/pets/pet/util/HorseVariantUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package lee.code.pets.pets.pet.util;

import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.world.entity.animal.horse.Horse;
import net.minecraft.world.entity.animal.horse.Variant;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;

@AllArgsConstructor
public enum HorseVariantUtil {
WHITE(Variant.WHITE),
BLACK(Variant.BLACK),
BROWN(Variant.BROWN),
DARK_BROWN(Variant.DARK_BROWN),
CREAMY(Variant.CREAMY),
CHESTNUT(Variant.CHESTNUT),
GRAY(Variant.GRAY)
;
@Getter private final Variant horseVariant;

public static HorseVariantUtil getVariant(Entity entity) {
if (((CraftEntity) entity).getHandle() instanceof Horse horse) return HorseVariantUtil.valueOf(horse.getVariant().name());
return HorseVariantUtil.WHITE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.bukkit.entity.Entity;

@AllArgsConstructor
public enum ParrotUtil {
public enum ParrotVariantUtil {
BLUE(Parrot.Variant.BLUE),
RED_BLUE(Parrot.Variant.RED_BLUE),
YELLOW_BLUE(Parrot.Variant.YELLOW_BLUE),
Expand All @@ -16,8 +16,8 @@ public enum ParrotUtil {
;
@Getter private final Parrot.Variant parrotVariant;

public static ParrotUtil getVariant(Entity entity) {
if (((CraftEntity) entity).getHandle() instanceof Parrot parrot) return ParrotUtil.valueOf(parrot.getVariant().name());
return ParrotUtil.RED_BLUE;
public static ParrotVariantUtil getVariant(Entity entity) {
if (((CraftEntity) entity).getHandle() instanceof Parrot parrot) return ParrotVariantUtil.valueOf(parrot.getVariant().name());
return ParrotVariantUtil.RED_BLUE;
}
}
67 changes: 53 additions & 14 deletions src/main/java/lee/code/pets/utils/PetDataUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package lee.code.pets.utils;

import lee.code.pets.menus.menu.menudata.options.Option;
import lee.code.pets.pets.pet.util.CatUtil;
import lee.code.pets.pets.pet.util.ParrotUtil;
import lee.code.pets.pets.pet.util.CatVariantUtil;
import lee.code.pets.pets.pet.util.HorseMarkingUtil;
import lee.code.pets.pets.pet.util.HorseVariantUtil;
import lee.code.pets.pets.pet.util.ParrotVariantUtil;
import org.bukkit.DyeColor;
import org.bukkit.entity.*;

Expand All @@ -16,7 +18,7 @@ public static String getPetData(EntityType entityType, String[] data, Option opt
case ALLAY, BAT -> {
return data[1];
}
case COW, BEE, CHICKEN -> {
case COW, BEE, CHICKEN, HOGLIN -> {
switch (option) {
case NAME -> {return data[1];}
case BABY -> {return data[2];}
Expand Down Expand Up @@ -72,6 +74,15 @@ public static String getPetData(EntityType entityType, String[] data, Option opt
case COLOR -> {return data[4];}
}
}
case HORSE -> {
switch (option) {
case NAME -> {return data[1];}
case BABY -> {return data[2];}
case SADDLE -> {return data[3];}
case VARIANT -> {return data[4];}
case MARKING -> {return data[5];}
}
}
}
return null;
}
Expand All @@ -86,13 +97,13 @@ public static String serializePetData(Entity entity) {
case ALLAY, BAT -> {
return startingData;
}
case COW, BEE, CHICKEN, HOGLIN -> {
return startingData + sep + isBaby;
}
case FOX -> {
final Fox.Type foxType = entity instanceof Fox fox ? fox.getFoxType() : Fox.Type.RED;
return startingData + sep + isBaby + sep + foxType.name();
}
case COW, BEE, CHICKEN -> {
return startingData + sep + isBaby;
}
case CAMEL -> {
final boolean hasSaddle = entity instanceof Camel camel && camel.getInventory().getSaddle() != null;
return startingData + sep + isBaby + sep + hasSaddle;
Expand All @@ -107,7 +118,7 @@ public static String serializePetData(Entity entity) {
return startingData + sep + isBaby + sep + hasHorns;
}
case PARROT -> {
final ParrotUtil variant = ParrotUtil.getVariant(entity);
final ParrotVariantUtil variant = ParrotVariantUtil.getVariant(entity);
return startingData + sep + variant.name();
}
case DONKEY -> {
Expand All @@ -120,6 +131,12 @@ public static String serializePetData(Entity entity) {
final DyeColor color = entity instanceof Cat cat ? cat.getCollarColor() : DyeColor.RED;
return startingData + sep + isBaby + sep + catType.name() + sep + color.name();
}
case HORSE -> {
final HorseVariantUtil horseVariant = HorseVariantUtil.getVariant(entity);
final HorseMarkingUtil horseMarking = HorseMarkingUtil.getMarking(entity);
final boolean hasSaddle = entity instanceof Horse horse && horse.getInventory().getSaddle() != null;
return startingData + sep + isBaby + sep + hasSaddle + sep + horseVariant.name() + sep + horseMarking.name();
}
}
return null;
}
Expand All @@ -130,7 +147,7 @@ public static String addNewPetData(EntityType entityType, String[] data, String
case ALLAY, BAT -> {
return data[0] + sep + newData;
}
case COW, BEE, CHICKEN -> {
case COW, BEE, CHICKEN, HOGLIN -> {
switch (option) {
case NAME -> {return data[0] + sep + newData + sep + data[2];}
case BABY -> {return data[0] + sep + data[1] + sep + newData;}
Expand Down Expand Up @@ -186,6 +203,15 @@ public static String addNewPetData(EntityType entityType, String[] data, String
case HORNS -> {return data[0] + sep + data[1] + sep + data[2] + sep + newData;}
}
}
case HORSE -> {
switch (option) {
case NAME -> {return data[0] + sep + newData + sep + data[2] + sep + data[3] + sep + data[4] + sep + data[5];}
case BABY -> {return data[0] + sep + data[1] + sep + newData + sep + data[3] + sep + data[4] + sep + data[5];}
case SADDLE -> {return data[0] + sep + data[1] + sep + data[2] + sep + newData + sep + data[4] + sep + data[5];}
case VARIANT -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + newData + sep + data[5];}
case MARKING -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + data[4] + sep + newData;}
}
}
}
return null;
}
Expand All @@ -198,23 +224,36 @@ public static String getNextColor(DyeColor dyeColor) {
public static String getNextVariant(EntityType entityType, String variant) {
switch (entityType) {
case PARROT -> {
final ParrotUtil parrotVariant = ParrotUtil.valueOf(variant);
final ArrayList<ParrotUtil> variants = new ArrayList<>(List.of(ParrotUtil.values()));
final ParrotUtil nextVariant = parrotVariant.ordinal() + 1 < variants.size() ? variants.get(parrotVariant.ordinal() + 1) : variants.get(0);
final ParrotVariantUtil parrotVariant = ParrotVariantUtil.valueOf(variant);
final ArrayList<ParrotVariantUtil> variants = new ArrayList<>(List.of(ParrotVariantUtil.values()));
final ParrotVariantUtil nextVariant = parrotVariant.ordinal() + 1 < variants.size() ? variants.get(parrotVariant.ordinal() + 1) : variants.get(0);
return nextVariant.name();
}
case CAT -> {
final CatUtil catVariant = CatUtil.valueOf(variant);
final ArrayList<CatUtil> variants = new ArrayList<>(List.of(CatUtil.values()));
final CatUtil nextVariant = catVariant.ordinal() + 1 < variants.size() ? variants.get(catVariant.ordinal() + 1) : variants.get(0);
final CatVariantUtil catVariant = CatVariantUtil.valueOf(variant);
final ArrayList<CatVariantUtil> variants = new ArrayList<>(List.of(CatVariantUtil.values()));
final CatVariantUtil nextVariant = catVariant.ordinal() + 1 < variants.size() ? variants.get(catVariant.ordinal() + 1) : variants.get(0);
return nextVariant.name();
}
case FOX -> {
final Fox.Type foxType = Fox.Type.valueOf(variant);
if (foxType.equals(Fox.Type.RED)) return Fox.Type.SNOW.name();
else return Fox.Type.RED.name();
}
case HORSE -> {
final HorseVariantUtil horseVariant = HorseVariantUtil.valueOf(variant);
final ArrayList<HorseVariantUtil> variants = new ArrayList<>(List.of(HorseVariantUtil.values()));
final HorseVariantUtil nextVariant = horseVariant.ordinal() + 1 < variants.size() ? variants.get(horseVariant.ordinal() + 1) : variants.get(0);
return nextVariant.name();
}
}
return null;
}

public static String getNextHorseMarking(String marking) {
final HorseMarkingUtil horseMarking = HorseMarkingUtil.valueOf(marking);
final ArrayList<HorseMarkingUtil> variants = new ArrayList<>(List.of(HorseMarkingUtil.values()));
final HorseMarkingUtil nextVariant = horseMarking.ordinal() + 1 < variants.size() ? variants.get(horseMarking.ordinal() + 1) : variants.get(0);
return nextVariant.name();
}
}

0 comments on commit 4822965

Please sign in to comment.