Skip to content

Commit

Permalink
Merge pull request #25 from CJBlakey/master
Browse files Browse the repository at this point in the history
Axolotls and goats
  • Loading branch information
Jakllp authored Aug 24, 2021
2 parents 05fec30 + f94171c commit 920cb10
Show file tree
Hide file tree
Showing 11 changed files with 451 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ public static class Ghast {
public static boolean CAN_GLIDE = true;
}

public static class Goat {
public static boolean CAN_GIVE_MILK = true;
public static ConfigItem GROW_UP_ITEM;

}

public static class Hoglin {

public static ConfigItem GROW_UP_ITEM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.util.List;

public enum MyPetType {
Axolotl("AXOLOTL", "1.17.1", MyAxolotl.class, new Compat<>()
.v("1.17.1", "axolotl")
.search()),
Bat("BAT", "1.7.10", MyBat.class, new Compat<>()
.v("1.7.10", 65)
.v("1.13", "bat")
Expand Down Expand Up @@ -99,6 +102,9 @@ public enum MyPetType {
.v("1.7.10", 56)
.v("1.13", "ghast")
.search()),
Goat("GOAT", "1.17.1", MyGoat.class, new Compat<>()
.v("1.17.1", "goat")
.search()),
Giant("GIANT", "1.7.10", MyGiant.class, new Compat<>()
.v("1.7.10", 53)
.v("1.13", "giant")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This file is part of MyPet
*
* Copyright © 2011-2019 Keyle
* MyPet is licensed under the GNU Lesser General Public License.
*
* MyPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.Keyle.MyPet.api.entity.types;

import de.Keyle.MyPet.api.entity.DefaultInfo;
import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.MyPetBaby;
@DefaultInfo(food = {"bucket"})
public interface MyAxolotl extends MyPet, MyPetBaby {

int getVariant();

void setVariant(int variant);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of MyPet
*
* Copyright © 2011-2019 Keyle
* MyPet is licensed under the GNU Lesser General Public License.
*
* MyPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.Keyle.MyPet.api.entity.types;

import de.Keyle.MyPet.api.entity.DefaultInfo;
import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.MyPetBaby;


@DefaultInfo(food = {"wheat"})
public interface MyGoat extends MyPet, MyPetBaby {

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public class CommandOptionCreate implements CommandOptionTabCompleter {
commonTypeOptionList.add("skilltree:");
commonTypeOptionList.add("name:");

petTypeOptionMap.put("axolotl", new CommandOptionCreator()
.add("baby")
.add("type:")
.get());

petTypeOptionMap.put("bee", new CommandOptionCreator()
.add("baby")
.add("angry")
Expand Down Expand Up @@ -110,6 +115,10 @@ public class CommandOptionCreate implements CommandOptionTabCompleter {
.add("type:white")
.get());

petTypeOptionMap.put("goat", new CommandOptionCreator()
.add("baby")
.get());

petTypeOptionMap.put("guardian", new CommandOptionCreator()
.add("1.7.10", "1.11", "elder")
.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.lang.reflect.Constructor;

public enum MyPetClass {
Axolotl(MyAxolotl.class),
Bat(MyBat.class),
Bee(MyBee.class),
Blaze(MyBlaze.class),
Expand All @@ -47,6 +48,7 @@ public enum MyPetClass {
Evoker(MyEvoker.class),
Fox(MyFox.class),
Ghast(MyGhast.class),
Goat(MyGoat.class),
Giant(MyGiant.class),
Guardian(MyGuardian.class),
Hoglin(MyHoglin.class),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* This file is part of MyPet
*
* Copyright © 2011-2019 Keyle
* MyPet is licensed under the GNU Lesser General Public License.
*
* MyPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.Keyle.MyPet.entity.types;

import de.Keyle.MyPet.api.entity.MyPetType;
import de.Keyle.MyPet.api.player.MyPetPlayer;
import de.Keyle.MyPet.entity.MyPet;
import de.keyle.knbt.TagByte;
import de.keyle.knbt.TagCompound;
import de.keyle.knbt.TagInt;
import org.bukkit.ChatColor;

public class MyAxolotl extends MyPet implements de.Keyle.MyPet.api.entity.types.MyAxolotl {

protected boolean isBaby = false;
protected int axolotlType = 1;

public MyAxolotl(MyPetPlayer petOwner) {
super(petOwner);
}
@Override
public TagCompound writeExtendedInfo() {
TagCompound info = super.writeExtendedInfo();
info.getCompoundData().put("Baby", new TagByte(isBaby()));
info.getCompoundData().put("Variant", new TagInt(getVariant()));
return info;
}

@Override
public void readExtendedInfo(TagCompound info) {
if (info.containsKey("Variant")) {
setVariant(info.getAs("Variant", TagInt.class).getIntData());
}
if (info.containsKey("Baby")) {
setBaby(info.getAs("Baby", TagByte.class).getBooleanData());
}

}

@Override
public MyPetType getPetType() {
return MyPetType.Axolotl;
}

@Override
public int getVariant() {
return axolotlType;
}

@Override
public void setVariant(int variant) {
this.axolotlType = Math.min(4, Math.max(0, variant));
if (status == PetState.Here) {
getEntity().ifPresent(entity -> entity.getHandle().updateVisuals());
}
}

public boolean isBaby() {
return isBaby;
}

public void setBaby(boolean flag) {
this.isBaby = flag;
if (status == PetState.Here) {
getEntity().ifPresent(entity -> entity.getHandle().updateVisuals());
}
}

@Override
public String toString() {
return "MyAxolotl{owner=" + getOwner().getName() + ", name=" + ChatColor.stripColor(petName) + ", exp=" + experience.getExp() + "/" + experience.getRequiredExp() + ", lv=" + experience.getLevel() + ", status=" + status.name() + ", skilltree=" + (skilltree != null ? skilltree.getName() : "-") + ", worldgroup=" + worldGroup + ", baby=" + isBaby() + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of MyPet
*
* Copyright © 2011-2019 Keyle
* MyPet is licensed under the GNU Lesser General Public License.
*
* MyPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.Keyle.MyPet.entity.types;

import de.Keyle.MyPet.api.entity.MyPetType;
import de.Keyle.MyPet.api.player.MyPetPlayer;
import de.Keyle.MyPet.entity.MyPet;
import de.keyle.knbt.TagByte;
import de.keyle.knbt.TagCompound;
import org.bukkit.ChatColor;

public class MyGoat extends MyPet implements de.Keyle.MyPet.api.entity.types.MyGoat {
protected boolean isBaby = false;

public MyGoat(MyPetPlayer petOwner) {
super(petOwner);
}

@Override
public TagCompound writeExtendedInfo() {
TagCompound info = super.writeExtendedInfo();
info.getCompoundData().put("Baby", new TagByte(isBaby()));
return info;
}

@Override
public void readExtendedInfo(TagCompound info) {
if (info.containsKey("Baby")) {
setBaby(info.getAs("Baby", TagByte.class).getBooleanData());
}
}

@Override
public MyPetType getPetType() {
return MyPetType.Goat;
}

public boolean isBaby() {
return isBaby;
}

public void setBaby(boolean flag) {
this.isBaby = flag;
if (status == PetState.Here) {
getEntity().ifPresent(entity -> entity.getHandle().updateVisuals());
}
}

@Override
public String toString() {
return "MyGoat{owner=" + getOwner().getName() + ", name=" + ChatColor.stripColor(petName) + ", exp=" + experience.getExp() + "/" + experience.getRequiredExp() + ", lv=" + experience.getLevel() + ", status=" + status.name() + ", skilltree=" + (skilltree != null ? skilltree.getName() : "-") + ", worldgroup=" + worldGroup + ", baby=" + isBaby() + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This file is part of MyPet
*
* Copyright © 2011-2020 Keyle
* MyPet is licensed under the GNU Lesser General Public License.
*
* MyPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.Keyle.MyPet.compat.v1_17_R1.entity.types;

import de.Keyle.MyPet.MyPetApi;
import de.Keyle.MyPet.api.Configuration;
import de.Keyle.MyPet.api.entity.EntitySize;
import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.types.MyAxolotl;
import de.Keyle.MyPet.api.entity.types.MyMooshroom;
import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet;
import net.minecraft.network.syncher.DataWatcher;
import net.minecraft.network.syncher.DataWatcherObject;
import net.minecraft.network.syncher.DataWatcherRegistry;
import net.minecraft.world.EnumHand;
import net.minecraft.world.EnumInteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.World;
import org.bukkit.Bukkit;

@EntitySize(width = 0.7F, height = 1.3F)
public class EntityMyAxolotl extends EntityMyPet {

private static final DataWatcherObject<Boolean> AGE_WATCHER = DataWatcher.a(EntityMyAxolotl.class, DataWatcherRegistry.i);
private static final DataWatcherObject<Integer> VARIANT_WATCHER = DataWatcher.a(EntityMyAxolotl.class, DataWatcherRegistry.b);

public EntityMyAxolotl(World world, MyPet myPet) {
super(world, myPet);
}

@Override
protected String getDeathSound() {
return "entity.axolotl.death";
}

@Override
protected String getHurtSound() {
return "entity.axolotl.hurt";
}

@Override
protected String getLivingSound() {
return "entity.axolotl.idle_air";
}

@Override
protected void initDatawatcher() {
super.initDatawatcher();
getDataWatcher().register(AGE_WATCHER, false);
getDataWatcher().register(VARIANT_WATCHER, 0);
}

@Override
public void updateVisuals() {
this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby());
this.getDataWatcher().set(VARIANT_WATCHER, getMyPet().getVariant());
}

@Override
public void playPetStepSound() {
makeSound("entity.axolotl.step", 0.15F, 1.0F);
}

@Override
public MyAxolotl getMyPet() {
return (MyAxolotl) myPet;
}
}
Loading

0 comments on commit 920cb10

Please sign in to comment.