Skip to content

Commit

Permalink
feat: sentry suit can be walked into from behind
Browse files Browse the repository at this point in the history
  • Loading branch information
Duzos committed Sep 30, 2024
1 parent 7375bbe commit 70a7e60
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/mc/duzo/timeless/suit/ironman/IronManEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.List;
import java.util.Optional;

public class IronManEntity extends LivingEntity { // todo - PathAwareEntity for sentry mode
private static final TrackedData<String> SUIT = DataTracker.registerData(IronManEntity.class, TrackedDataHandlerRegistry.STRING);
private int cooldown = 0;

public IronManEntity(EntityType<? extends IronManEntity> entityType, World world) {
super(entityType, world);
Expand All @@ -31,6 +36,7 @@ public IronManEntity(World world, IronManSuit suit) {
this(Register.Entities.IRON_MAN, world);

this.setSuit(suit);
this.cooldown = 60;
}
public IronManEntity(World world, IronManSuit suit, Vec3d pos, float yaw, float pitch) {
this(world, suit);
Expand Down Expand Up @@ -65,6 +71,42 @@ public ActionResult interact(PlayerEntity player, Hand hand) {
return success ? ActionResult.SUCCESS : ActionResult.FAIL;
}

@Override
public void tick() {
super.tick();

if (!this.getWorld().isClient()){
if (this.cooldown > 0) {
this.cooldown--;
} else {
this.tryApply();
}
}
}

private void tryApply() {
PlayerEntity found = findNearbyPlayer().orElse(null);

if (found == null) return;

boolean success = this.getSuit().getSet().wear(found);

if (success) {
this.discard();
}
}

private Optional<PlayerEntity> findNearbyPlayer() {
EntityHitResult ray = ProjectileUtil.getEntityCollision(this.getWorld(), this, this.getPos(), this.getPos().offset(this.getMovementDirection().getOpposite(), 0.25f).add(0, 1.5, 0), this.getBoundingBox().stretch(this.getVelocity()).expand(1.0), (entity -> (entity instanceof PlayerEntity)));;
if (ray == null) return Optional.empty();
return Optional.of((PlayerEntity) ray.getEntity());
}

@Override
public boolean damage(DamageSource source, float amount) {
return false;
}

@Override
protected void initDataTracker() {
super.initDataTracker();
Expand Down

0 comments on commit 70a7e60

Please sign in to comment.