Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTheTech committed Sep 21, 2023
1 parent dbb3533 commit 011af25
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/main/java/lee/code/pets/commands/cmds/TestCMD.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean performAsyncSynchronized() {

@Override
public void perform(Player player, String[] args) {
pets.getPetManager().spawn(player, EntityType.CREEPER, new String[]{"&d&lMASTER_GAY", "true"});
pets.getPetManager().spawn(player, EntityType.COD, new String[]{"&d&lMASTER_GAY"});
}

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

import lee.code.pets.pets.pet.animal.*;
import lee.code.pets.pets.pet.animal.CatPet;
import lee.code.pets.pets.pet.fish.CodPet;
import lee.code.pets.pets.pet.mob.*;
import net.minecraft.world.entity.Entity;
import org.bukkit.World;
Expand Down Expand Up @@ -29,6 +30,9 @@ public void spawn(Player player, EntityType entityType, String[] data) {
case MAGMA_CUBE -> spawn(player.getWorld(), new MagmaCubePet(player, data[0], data[1]));
case RAVAGER -> spawn(player.getWorld(), new RavagerPet(player, data[0]));
case CREEPER -> spawn(player.getWorld(), new CreeperPet(player, data[0], Boolean.parseBoolean(data[1])));
case SKELETON -> spawn(player.getWorld(), new SkeletonPet(player, data[0]));
case HORSE -> spawn(player.getWorld(), new HorsePet(player, Boolean.parseBoolean(data[0]), data[1], data[2], data[3]));
case COD -> spawn(player.getWorld(), new CodPet(player, data[0]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public void tick() {
final float forward = Math.max(0, (float) riddenInput.z);
final float pitch = rider.getXRot();
final float yaw = rider.getYRot();
final double motionX = forward * -Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch));
final double motionY = forward * -Math.sin(Math.toRadians(pitch));
final double motionZ = forward * Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch));

// Set the mob's motion
mob.setSpeed(0.2F); // You can adjust the speed as needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package lee.code.pets.pets.controllers;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.WaterFluid;
import net.minecraft.world.phys.Vec3;

import java.util.UUID;

public class ControllerWASDWater extends ControllerWASD {

public ControllerWASDWater(Mob mob, UUID owner) {
super(mob, owner);
}

@Override
public void tick() {
if (mob.getPassengers().isEmpty()) {
super.tick();
return;
}
if (!(mob.getPassengers().get(0) instanceof Player player)) return;
if (!player.getUUID().equals(owner)) return;
this.rider = player;

final Vec3 riddenInput = getRiddenInput(rider);

float forward = (float) riddenInput.z * 0.5F;
float strafe = (float) riddenInput.x * 0.25F;
if (forward <= 0.0F) forward *= 0.5F;

// Calculate the player's yaw and pitch
float yaw = rider.getBukkitYaw();
float pitch = rider.getXRot();

// Calculate the direction based on yaw and pitch
double motionX = forward * -Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch));
double motionY = forward * -Math.sin(Math.toRadians(pitch)); // Adjust vertical motion based on pitch
double motionZ = forward * Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch));

// Add upward motion when jumping
if (rider.jumping) {
motionY += 0.5D;
}

if (!mob.isInWater()) {
// Limit upward motion if out of water
motionY = Math.min(-0.1D, motionY);

// If solid block below entity out of water, slow down
final BlockPos downPos = mob.blockPosition().relative(Direction.DOWN);
final BlockState frontBlockState = mob.level().getBlockState(downPos);
if (!(frontBlockState.getBlock() instanceof LiquidBlock)) {
motionX *= 0.2D;
motionY *= 0.2D;
motionZ *= 0.2D;
}
}

// Set the mob's motion
mob.setDeltaMovement(new Vec3(motionX, motionY, motionZ));

// Set the yaw rotation of the mob
mob.setYRot(yaw);

// Set the desired speed and direction of the mob.
mob.setSpeed(1F);
mob.setZza(forward);
mob.setXxa(0.0F);
}
}
33 changes: 0 additions & 33 deletions src/main/java/lee/code/pets/pets/goals/FollowOwnerFlyingGoal.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void tick() {
final BlockPos frontPos = mob.blockPosition().relative(mob.getDirection());
final BlockState frontBlockState = mob.level().getBlockState(frontPos);
if (frontBlockState.isSolidRender(mob.level(), frontPos) || frontBlockState.getBlock() instanceof LeavesBlock) {
// Jump logic here.
mob.getJumpControl().jump();
}
}
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/lee/code/pets/pets/pet/animal/HorsePet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package lee.code.pets.pets.pet.animal;

import lee.code.pets.pets.controllers.ControllerWASD;
import lee.code.pets.pets.goals.FollowOwnerGoal;
import lee.code.pets.utils.CoreUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.horse.Horse;
import net.minecraft.world.entity.animal.horse.Markings;
import net.minecraft.world.entity.animal.horse.Variant;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityTargetEvent;

public class HorsePet extends Horse {

public HorsePet(Player player, boolean baby, String name, String variant, String markings) {
super(EntityType.HORSE, ((CraftWorld) player.getLocation().getWorld()).getHandle());
setPos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
setInvulnerable(true);
setCustomNameVisible(true);
setPersistenceRequired(true);
collides = false;
setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(name)));
setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false);
moveControl = new ControllerWASD(this, player.getUniqueId());
if (baby) setBaby(true);
setVariantAndMarkings(Variant.valueOf(variant), Markings.valueOf(markings));
}

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

@Override
public void ageUp(int age) {
}

@Override
public void ageUp(int age, boolean overGrow) {
}

@Override
public void load(CompoundTag compoundTag) {
}

@Override
public boolean save(CompoundTag compoundTag) {
return false;
}
}
43 changes: 43 additions & 0 deletions src/main/java/lee/code/pets/pets/pet/fish/CodPet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lee.code.pets.pets.pet.fish;

import lee.code.pets.pets.controllers.ControllerWASD;
import lee.code.pets.pets.controllers.ControllerWASDWater;
import lee.code.pets.pets.goals.FollowOwnerGoal;
import lee.code.pets.utils.CoreUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Cod;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityTargetEvent;

public class CodPet extends Cod {

public CodPet(Player player, String name) {
super(EntityType.COD, ((CraftWorld) player.getLocation().getWorld()).getHandle());
setPos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
setInvulnerable(true);
setCustomNameVisible(true);
setPersistenceRequired(true);
collides = false;
setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(name)));
setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false);
moveControl = new ControllerWASDWater(this, player.getUniqueId());
}

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

@Override
public void load(CompoundTag compoundTag) {
}

@Override
public boolean save(CompoundTag compoundTag) {
return false;
}
}
42 changes: 42 additions & 0 deletions src/main/java/lee/code/pets/pets/pet/mob/SkeletonPet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package lee.code.pets.pets.pet.mob;

import lee.code.pets.pets.controllers.ControllerWASD;
import lee.code.pets.pets.goals.FollowOwnerGoal;
import lee.code.pets.utils.CoreUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityTargetEvent;

public class SkeletonPet extends Mob {

public SkeletonPet(Player player, String name) {
super(EntityType.SKELETON, ((CraftWorld) player.getLocation().getWorld()).getHandle());
setPos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
setInvulnerable(true);
setCustomNameVisible(true);
setPersistenceRequired(true);
collides = false;
setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(name)));
setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false);
moveControl = new ControllerWASD(this, player.getUniqueId());
}

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

@Override
public void load(CompoundTag compoundTag) {
}

@Override
public boolean save(CompoundTag compoundTag) {
return false;
}
}

0 comments on commit 011af25

Please sign in to comment.