Skip to content

Commit

Permalink
New Baby-System for 1.17 -> No more axolotlcide - Fixed Follow-Telepo…
Browse files Browse the repository at this point in the history
…rtation

Fixed:
- The actual teleportation works now (in addition to respawn)
- Axolotls don't kill other axolotls anymore

Internal:
- New Baby-System for 1.17 (using AgeableMob)
  • Loading branch information
Jakllp committed Aug 27, 2021
1 parent 60e183c commit 2b46858
Show file tree
Hide file tree
Showing 35 changed files with 178 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.List;
import java.util.UUID;

import javax.annotation.Nullable;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
Expand Down Expand Up @@ -100,6 +102,7 @@
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
Expand All @@ -108,6 +111,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
Expand All @@ -127,7 +131,7 @@
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

public abstract class EntityMyPet extends Mob implements MyPetMinecraftEntity {
public abstract class EntityMyPet extends AgeableMob implements MyPetMinecraftEntity {

protected static final EntityDataAccessor<Byte> POTION_PARTICLE_WATCHER = Mob.DATA_SHARED_FLAGS_ID;

Expand Down Expand Up @@ -161,6 +165,7 @@ public EntityMyPet(Level world, MyPet myPet) {

try {
this.replaceCraftAttributes();
ageLocked = true;

this.myPet = myPet;
this.isMyPet = true;
Expand Down Expand Up @@ -1420,4 +1425,9 @@ public DamageSource getLastDamageSource() {
public UUID getUniqueID() {
return this.uuid;
}

@Override
public @Nullable AgeableMob getBreedOffspring(ServerLevel arg0, AgeableMob arg1) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.movement;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;

Expand Down Expand Up @@ -114,12 +115,12 @@ public void tick() {
if (this.petEntity.canMove()) {
if (!owner.getAbilities().flying) {
if (!waitForGround) {
if (owner.flyDist <= 4) {
if (owner.fallDistance <= 4) {
if (this.petEntity.distanceToSqr(owner) >= this.teleportDistance) {
if (controlPathfinderGoal.moveTo == null) {
if (!petEntity.hasTarget()) {
if (MyPetApi.getPlatformHelper().canSpawn(ownerLocation, this.petEntity)) {
this.petEntity.flyDist = 0;
this.petEntity.fallDistance = 0;
this.petEntity.moveTo(ownerLocation.getX(), ownerLocation.getY(), ownerLocation.getZ(), this.petEntity.getYRot(), this.petEntity.getXRot());
this.setPathTimer = 0;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@EntitySize(width = 0.7F, height = 1.3F)
public class EntityMyAxolotl extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyAxolotl.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Integer> VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyAxolotl.class, EntityDataSerializers.INT);

public EntityMyAxolotl(Level world, MyPet myPet) {
Expand All @@ -59,13 +58,16 @@ protected String getLivingSound() {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
getEntityData().define(VARIANT_WATCHER, 0);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
@EntitySize(width = 0.6F, height = 0.6f)
public class EntityMyBee extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyBee.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Byte> BEE_STATUS_WATCHER = SynchedEntityData.defineId(EntityMyBee.class, EntityDataSerializers.BYTE);
private static final EntityDataAccessor<Integer> ANGER_WATCHER = SynchedEntityData.defineId(EntityMyBee.class, EntityDataSerializers.INT);

Expand Down Expand Up @@ -76,14 +75,17 @@ public float getSoundSpeed() {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
getEntityData().define(BEE_STATUS_WATCHER, (byte) 0);
getEntityData().define(ANGER_WATCHER, 0);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
this.getEntityData().set(ANGER_WATCHER, (getMyPet().isAngry() || isAngry) ? 1 : 0);
this.setBeeStatus(8, getMyPet().hasNectar());
this.setBeeStatus(4, getMyPet().hasStung());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
@EntitySize(width = 0.6F, height = 0.8F)
public class EntityMyCat extends EntityMyPet {

protected static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.BOOLEAN);
protected static final EntityDataAccessor<Byte> SIT_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.BYTE);
protected static final EntityDataAccessor<Optional<UUID>> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.OPTIONAL_UUID);
protected static final EntityDataAccessor<Integer> TYPE_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.INT);
Expand Down Expand Up @@ -116,7 +115,6 @@ public InteractionResult handlePlayerInteraction(Player entityhuman, Interaction
@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
getEntityData().define(SIT_WATCHER, (byte) 0);
getEntityData().define(OWNER_WATCHER, Optional.empty());
getEntityData().define(TYPE_WATCHER, 1);
Expand All @@ -127,7 +125,11 @@ protected void defineSynchedData() {

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
this.getEntityData().set(TYPE_WATCHER, getMyPet().getCatType().ordinal());
this.getEntityData().set(COLLAR_COLOR_WATCHER, getMyPet().getCollarColor().ordinal());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
@EntitySize(width = 0.4F, height = 0.7F)
public class EntityMyChicken extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyChicken.class, EntityDataSerializers.BOOLEAN);

private int nextEggTimer;

public EntityMyChicken(Level world, MyPet myPet) {
Expand Down Expand Up @@ -85,15 +83,13 @@ public InteractionResult handlePlayerInteraction(Player entityhuman, Interaction
return InteractionResult.PASS;
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
@EntitySize(width = 0.7F, height = 1.3F)
public class EntityMyCow extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyCow.class, EntityDataSerializers.BOOLEAN);

public EntityMyCow(Level world, MyPet myPet) {
super(world, myPet);
}
Expand Down Expand Up @@ -87,15 +85,13 @@ public InteractionResult handlePlayerInteraction(Player entityhuman, Interaction
return InteractionResult.PASS;
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@

@EntitySize(width = 1.4F, height = 1.6F)
public class EntityMyDonkey extends EntityMyPet implements PlayerRideableJumping {

protected static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.BOOLEAN);

protected static final EntityDataAccessor<Byte> SADDLE_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.BYTE);
protected static final EntityDataAccessor<Optional<UUID>> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.OPTIONAL_UUID);
private static final EntityDataAccessor<Boolean> CHEST_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.BOOLEAN);
Expand Down Expand Up @@ -174,15 +173,18 @@ public InteractionResult handlePlayerInteraction(Player entityhuman, Interaction
@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
getEntityData().define(SADDLE_WATCHER, (byte) 0);
getEntityData().define(OWNER_WATCHER, Optional.empty());
getEntityData().define(CHEST_WATCHER, false);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest());
applyVisual(4, getMyPet().hasSaddle());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
@EntitySize(width = 0.6F, height = 0.8F)
public class EntityMyFox extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Integer> FOX_TYPE_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Byte> ACTIONS_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.BYTE);
private static final EntityDataAccessor<Optional<UUID>> FRIEND_A_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.OPTIONAL_UUID);
Expand Down Expand Up @@ -153,7 +152,6 @@ public InteractionResult handlePlayerInteraction(Player entityhuman, Interaction
@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
getEntityData().define(FRIEND_A_WATCHER, Optional.empty());
getEntityData().define(FRIEND_B_WATCHER, Optional.empty());
getEntityData().define(FOX_TYPE_WATCHER, 0);
Expand All @@ -162,7 +160,11 @@ protected void defineSynchedData() {

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
this.getEntityData().set(FOX_TYPE_WATCHER, getMyPet().getType().ordinal());

Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@

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

import javax.annotation.Nullable;

import de.Keyle.MyPet.api.Configuration;
import de.Keyle.MyPet.api.entity.EntitySize;
import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet;
import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack.MeleeAttack;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.level.Level;

@EntitySize(width = 4.F, height = 4.F)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
@EntitySize(width = 0.7F, height = 1.3F)
public class EntityMyGoat extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyGoat.class, EntityDataSerializers.BOOLEAN);

public EntityMyGoat(Level world, MyPet myPet) {
super(world, myPet);
}
Expand Down Expand Up @@ -84,15 +82,14 @@ public InteractionResult handlePlayerInteraction(Player entityhuman, Interaction
}
return InteractionResult.PASS;
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
@EntitySize(width = 1.3965F, height = 1.4F)
public class EntityMyHoglin extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyHoglin.class, EntityDataSerializers.BOOLEAN);

public EntityMyHoglin(Level world, MyPet myPet) {
super(world, myPet);
}
Expand Down Expand Up @@ -79,15 +77,13 @@ public InteractionResult handlePlayerInteraction(final Player entityhuman, Inter
return InteractionResult.PASS;
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@

@EntitySize(width = 1.3965F, height = 1.6F)
public class EntityMyHorse extends EntityMyPet implements PlayerRideableJumping {

protected static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.BOOLEAN);

protected static final EntityDataAccessor<Byte> SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.BYTE);
protected static final EntityDataAccessor<Optional<UUID>> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.OPTIONAL_UUID);
private static final EntityDataAccessor<Integer> VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.INT);
Expand Down Expand Up @@ -217,15 +216,18 @@ protected boolean isArmor(org.bukkit.inventory.ItemStack item) {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(AGE_WATCHER, false);
getEntityData().define(SADDLE_CHEST_WATCHER, (byte) 0);
getEntityData().define(OWNER_WATCHER, Optional.empty());
getEntityData().define(VARIANT_WATCHER, 0);
}

@Override
public void updateVisuals() {
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if(getMyPet().isBaby()) {
this.setAge(-1);
} else {
this.setAge(1);
}
this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
applyVisual(4, getMyPet().hasSaddle());
Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> {
Expand Down
Loading

0 comments on commit 2b46858

Please sign in to comment.