From 70bc189854a9f8f9c6f975f868182961111a18be Mon Sep 17 00:00:00 2001 From: raunakdeysarkar Date: Fri, 29 May 2026 12:23:27 +0530 Subject: [PATCH] Add hasComponent utility method to Entity Architecture --- src/Main.java | 22 ++++++++++++++++++++++ src/net/kaupenjoe/entity/Entity.java | 28 +++++++++++++++++++++------- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/Main.java b/src/Main.java index 4706149..dbb9671 100644 --- a/src/Main.java +++ b/src/Main.java @@ -45,5 +45,27 @@ public static void main(String[] args) { // world.edit(whiskersId).add(new BirthdayRequest()); // whiskers.birthday(); world.process(); + + // --- START OF DIAGNOSTIC TEST FOR YOUR NEW METHOD --- + System.out.println("\n--- RUNNING DIAGNOSTIC CHECK ON VEDAL ---"); + + // 1. Fetch the actual Entity object for Vedal from the world engine + net.kaupenjoe.entity.Entity vedalEntity = world.edit(vedalId); + + // 2. Execute your brand-new method to check for a shell component + if (vedalEntity.hasComponent(HasShellComponent.class)) { + System.out.println("SUCCESS: Vedal has a protective shell component attached!"); + } else { + System.out.println("DEBUG: No shell component detected."); + } + + // 3. Let's verify a negative test (checking if Vedal has a BirthdayRequest component) + if (vedalEntity.hasComponent(BirthdayRequest.class)) { + System.out.println("DEBUG: Vedal has a pending birthday request."); + } else { + System.out.println("SUCCESS: Negative check passed. Vedal does not have a pending birthday request."); + } + System.out.println("-------------------------------------------\n"); + // --- END OF DIAGNOSTIC TEST --- } } \ No newline at end of file diff --git a/src/net/kaupenjoe/entity/Entity.java b/src/net/kaupenjoe/entity/Entity.java index 3af9a55..e458076 100644 --- a/src/net/kaupenjoe/entity/Entity.java +++ b/src/net/kaupenjoe/entity/Entity.java @@ -6,37 +6,51 @@ import java.util.List; import java.util.Optional; -public class Entity { +public class Entity +{ private final int id; private List components = new ArrayList<>(); - public Entity(int id) { + public Entity(int id) + { this.id = id; } - public void add(Component component) { + public void add(Component component) + { this.components.add(component); } - public void remove(Class type) { + public void remove(Class type) + { components.removeIf(type::isInstance); } - public Optional getOptionalComponent(Class type) { + public Optional getOptionalComponent(Class type) + { return components.stream() .filter(type::isInstance) .map(type::cast) .findFirst(); } - public T getComponent(Class type) { + public T getComponent(Class type) + { return components.stream() .filter(type::isInstance) .map(type::cast) .findFirst().orElse(null); } - public int getId() { + public boolean hasComponent(Class type) + { + return components.stream() + .anyMatch(type::isInstance); + } + + + public int getId() + { return id; } }