Skip to content

Commit

Permalink
actually working version of creating components
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWeabo committed Sep 15, 2024
1 parent d5fcc3e commit 2682d58
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class ItemInputInventory implements ItemInventory, WorldStateValidator {
private long limit;
private UUID key;

public ItemInputInventory(Integer size, Long limit) {
this((int) size, (long) limit);
}

public ItemInputInventory(int size, long limit) {
inv = new IItemStackLong[size];
for (int i = 0; i < size; i++) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gtnewhorizons.mutecore.api.registry;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class ComponentsCreator {

private boolean built;
private List<Supplier<Object>> componentBuilders = new ArrayList<>();

public ComponentsCreator() {}

public ComponentsCreator component(Supplier<Object> componentBuilder) {
if (built) throw new IllegalStateException("Cannot add components after the builder has been finished");
componentBuilders.add(componentBuilder);
return this;
}

public ComponentsCreator build() {
built = true;
return this;
}

public List<Object> createComponents() {
if (!built) throw new IllegalStateException("Cannot create components when the builder is unfinished");
List<Object> components = new ArrayList<>();
for (int i = 0; i < componentBuilders.size(); i++) {
components.add(componentBuilders.get(i).get());
}
return components;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MultiTileContainer {
private final @Nonnull Class<? extends MultiTileEntity> clazz;
private final int id;
private final @Nonnull WeakReference<MultiTileEntityRegistry> reg;
private final Set<ComponentContainer> components;
private @Nonnull ComponentsCreator componentsCreator;
private final @Nonnull Entity fakeEntity;
private Class<? extends TooltipAssigner> tooltipClass;
private @Nonnull MuTEGUI gui;
Expand All @@ -37,13 +37,13 @@ public MultiTileContainer(@Nonnull MultiTileEntityRegistry reg, int id,
this.clazz = clazz;
this.id = id;
fakeEntity = MuTECore.ENGINE.createEntity(new FakeEntity());
components = new HashSet<>();
}

public @Nonnull MultiTileContainer addComponents(ComponentContainer... components) {
for (ComponentContainer component : components) {
this.components.add(component);
fakeEntity.add(component.create());
public @Nonnull MultiTileContainer componentsCreator(ComponentsCreator componentsCreator) {
this.componentsCreator = componentsCreator;
List<Object> components = this.componentsCreator.createComponents();
for (int i = 0; i < components.size(); i++) {
fakeEntity.add(components.get(i));
}
return this;
}
Expand All @@ -70,12 +70,7 @@ public boolean register() {
}

public @Nonnull Entity createNewEntity() {
List<Object> components = new ArrayList<>();
for (ComponentContainer componentContainer : this.components) {
Object component = componentContainer.create();
if (component == null) continue;
components.add(component);
}
List<Object> components = componentsCreator.createComponents();
Entity newEntity = MuTECore.ENGINE.createEntity(components.toArray());
newEntity.add(
new Id(
Expand Down

0 comments on commit 2682d58

Please sign in to comment.