Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---
}
}
28 changes: 21 additions & 7 deletions src/net/kaupenjoe/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,51 @@
import java.util.List;
import java.util.Optional;

public class Entity {
public class Entity
{
private final int id;
private List<Component> 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 <T extends Component> void remove(Class<T> type) {
public <T extends Component> void remove(Class<T> type)
{
components.removeIf(type::isInstance);
}

public <T extends Component> Optional<T> getOptionalComponent(Class<T> type) {
public <T extends Component> Optional<T> getOptionalComponent(Class<T> type)
{
return components.stream()
.filter(type::isInstance)
.map(type::cast)
.findFirst();
}

public <T extends Component> T getComponent(Class<T> type) {
public <T extends Component> T getComponent(Class<T> type)
{
return components.stream()
.filter(type::isInstance)
.map(type::cast)
.findFirst().orElse(null);
}

public int getId() {
public <T extends Component> boolean hasComponent(Class<T> type)
{
return components.stream()
.anyMatch(type::isInstance);
}


public int getId()
{
return id;
}
}