Skip to content

Commit

Permalink
Rewrite menu module, ready to test in Ender IO
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Sep 24, 2024
1 parent 289054e commit cb8577e
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 489 deletions.
86 changes: 11 additions & 75 deletions src/main/java/com/enderio/regilite/Regilite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,17 @@

import com.enderio.regilite.blockentities.RegiliteBlockEntities;
import com.enderio.regilite.blocks.RegiliteBlocks;
import com.enderio.regilite.data.RegiliteDataProvider;
import com.enderio.regilite.entities.RegiliteEntities;
import com.enderio.regilite.events.ScreenEvents;
import com.enderio.regilite.fluids.RegiliteFluidTypes;
import com.enderio.regilite.items.RegiliteItems;
import com.enderio.regilite.lang.RegiliteLang;
import com.enderio.regilite.loot.RegiliteLootTables;
import com.enderio.regilite.registry.MenuRegistry;
import com.enderio.regilite.menus.RegiliteMenus;
import com.enderio.regilite.tags.RegiliteTags;
import com.enderio.regilite.utils.BundledDataProvider;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.world.inventory.MenuType;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Regilite {

private final String modId;

private final List<DeferredHolder<MenuType<?>, ? extends MenuType<?>>> menus = new ArrayList<>();
public class Regilite extends AbstractRegilite {

private final RegiliteLang langModule;
private final RegiliteTags tagsModule;
Expand All @@ -46,17 +29,12 @@ public class Regilite {
private final RegiliteBlockEntities blockEntityRegistry;
private final RegiliteFluidTypes fluidTypesModule;
private final RegiliteEntities entitiesModule;

private final RegiliteDataProvider dataProvider;

private final ObjectList<RegiliteModuleDataGen> modulesWithDataGeneration = new ObjectArrayList<>();
private final ObjectList<RegiliteModuleEvents> modulesWithEvents = new ObjectArrayList<>();
private final RegiliteMenus regiliteMenus;

private final DeferredRegister.DataComponents dataComponentsRegistry;

public Regilite(String modId) {
this.modId = modId;
this.dataProvider = new RegiliteDataProvider(this);
super(modId);

this.langModule = registerModule(new RegiliteLang(modId));
this.tagsModule = registerModule(new RegiliteTags(modId));
Expand All @@ -67,26 +45,11 @@ public Regilite(String modId) {
this.blockEntityRegistry = registerModule(RegiliteBlockEntities.create(this));
this.fluidTypesModule = registerModule(RegiliteFluidTypes.create(this));
this.entitiesModule = registerModule(RegiliteEntities.create(this));
this.regiliteMenus = registerModule(RegiliteMenus.create(this));

dataComponentsRegistry = DeferredRegister.createDataComponents(modId);
}

private <T> T registerModule(T module) {
if (module instanceof RegiliteModuleDataGen dataGenModule) {
modulesWithDataGeneration.add(dataGenModule);
}

if (module instanceof RegiliteModuleEvents eventsModule) {
modulesWithEvents.add(eventsModule);
}

return module;
}

public String modId() {
return modId;
}

public RegiliteLang lang() {
return langModule;
}
Expand Down Expand Up @@ -115,6 +78,10 @@ public RegiliteEntities entities() {
return entitiesModule;
}

public RegiliteMenus menus() {
return regiliteMenus;
}

public DeferredRegister.DataComponents dataComponents() {
return dataComponentsRegistry;
}
Expand All @@ -123,40 +90,9 @@ public RegiliteLootTables lootTables() {
return lootTablesModule;
}

@Override
public void register(IEventBus modbus) {
dataProvider.register(modbus);
super.register(modbus);
dataComponentsRegistry.register(modbus);

modbus.addListener(this::onGatherData);

for (var module : modulesWithEvents) {
module.register(modbus);
}

if (FMLEnvironment.dist.isClient()) {
modbus.addListener(new ScreenEvents(this)::screenEvent);
}
}

private void onGatherData(GatherDataEvent event) {
var provider = new BundledDataProvider(modId);

for (var module : modulesWithDataGeneration) {
module.gatherProviders(event, provider::addSubProvider);
}

event.getGenerator().addProvider(true, provider);
}

public MenuRegistry menuRegistry() {
return MenuRegistry.create(this);
}

public List<DeferredHolder<MenuType<?>, ? extends MenuType<?>>> getMenus() {
return menus;
}

public void addMenus(Collection<DeferredHolder<MenuType<?>, ? extends MenuType<?>>> entries) {
this.menus.addAll(entries);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/enderio/regilite/RegiliteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected RegiliteBuilder(H holder) {
* This will allow all the builder data to be flushed after initialization.
* @return The holder.
*/
public final H asHolder() {
public final H finish() {
return holder;
}

Expand Down

This file was deleted.

71 changes: 0 additions & 71 deletions src/main/java/com/enderio/regilite/data/RegiliteDataProvider.java

This file was deleted.

39 changes: 0 additions & 39 deletions src/main/java/com/enderio/regilite/events/ScreenEvents.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public <I extends BucketItem> FluidTypeBuilder<T> customBucket(Function<Supplier
var bucket = itemsModule.create(getId().getPath() + "_bucket", () -> supplier.apply(holder::sourceFluid));
bucket.modelProvider((prov, ctx) -> prov.bucketItem(ctx.get()));
itemConfigure.accept(bucket);
holder.bucketHolder(bucket.asHolder());
holder.bucketHolder(bucket.finish());
return this;
}

Expand All @@ -118,7 +118,7 @@ public <B extends LiquidBlock> FluidTypeBuilder<T> block(Function<Supplier<? ext
public <B extends LiquidBlock> FluidTypeBuilder<T> block(Function<Supplier<? extends BaseFlowingFluid>, B> supplier, Consumer<BlockBuilder<B>> blockConfigure) {
var block = blocksModule.create(getId().getPath(), () -> supplier.apply(holder::flowingFluid));
blockConfigure.accept(block);
holder.blockHolder(block.asHolder());
holder.blockHolder(block.finish());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private void onClientSetupEvent(FMLClientSetupEvent event) {
for (var fluidType : fluids) {
var renderType = fluidType.renderTypeSupplier.get().get();
if (renderType != null) {
ItemBlockRenderTypes.setRenderLayer(fluidType.asHolder().flowingFluid(), renderType);
ItemBlockRenderTypes.setRenderLayer(fluidType.asHolder().sourceFluid(), renderType);
ItemBlockRenderTypes.setRenderLayer(fluidType.finish().flowingFluid(), renderType);
ItemBlockRenderTypes.setRenderLayer(fluidType.finish().sourceFluid(), renderType);
}
}
}
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/com/enderio/regilite/holder/RegiliteEntity.java

This file was deleted.

Loading

0 comments on commit cb8577e

Please sign in to comment.