Skip to content

Commit

Permalink
chore: Many renames and additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Sep 30, 2024
1 parent e18b37c commit 79217f5
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 112 deletions.
48 changes: 24 additions & 24 deletions src/main/java/com/enderio/regilite/Regilite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

package com.enderio.regilite;

import com.enderio.regilite.blockentities.RegiliteBlockEntities;
import com.enderio.regilite.blockentities.RegiliteBlockEntityTypes;
import com.enderio.regilite.blocks.RegiliteBlocks;
import com.enderio.regilite.entities.RegiliteEntities;
import com.enderio.regilite.entities.RegiliteEntityTypes;
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.menus.RegiliteMenus;
import com.enderio.regilite.menus.RegiliteMenuTypes;
import com.enderio.regilite.tags.RegiliteTags;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredRegister;
Expand All @@ -24,12 +24,12 @@ public class Regilite extends AbstractRegilite {

private final RegiliteLootTables lootTablesModule;

private final RegiliteItems itemsModule;
private final RegiliteBlocks blocksRegistry;
private final RegiliteBlockEntities blockEntityRegistry;
private final RegiliteFluidTypes fluidTypesModule;
private final RegiliteEntities entitiesModule;
private final RegiliteMenus regiliteMenus;
private final RegiliteItems items;
private final RegiliteBlocks blocks;
private final RegiliteBlockEntityTypes blockEntityTypes;
private final RegiliteFluidTypes fluidTypes;
private final RegiliteEntityTypes entityTypes;
private final RegiliteMenuTypes menuTypes;

private final DeferredRegister.DataComponents dataComponentsRegistry;

Expand All @@ -40,12 +40,12 @@ public Regilite(String modId) {
this.tagsModule = registerModule(new RegiliteTags(modId));
this.lootTablesModule = registerModule(new RegiliteLootTables());

this.itemsModule = registerModule(RegiliteItems.create(this));
this.blocksRegistry = registerModule(RegiliteBlocks.create(this));
this.blockEntityRegistry = registerModule(RegiliteBlockEntities.create(this));
this.fluidTypesModule = registerModule(RegiliteFluidTypes.create(this));
this.entitiesModule = registerModule(RegiliteEntities.create(this));
this.regiliteMenus = registerModule(RegiliteMenus.create(this));
this.items = registerModule(RegiliteItems.create(this));
this.blocks = registerModule(RegiliteBlocks.create(this));
this.blockEntityTypes = registerModule(RegiliteBlockEntityTypes.create(this));
this.fluidTypes = registerModule(RegiliteFluidTypes.create(this));
this.entityTypes = registerModule(RegiliteEntityTypes.create(this));
this.menuTypes = registerModule(RegiliteMenuTypes.create(this));

dataComponentsRegistry = DeferredRegister.createDataComponents(modId);
}
Expand All @@ -59,27 +59,27 @@ public RegiliteTags tags() {
}

public RegiliteItems items() {
return itemsModule;
return items;
}

public RegiliteBlocks blocks() {
return blocksRegistry;
return blocks;
}

public RegiliteBlockEntities blockEntities() {
return blockEntityRegistry;
public RegiliteBlockEntityTypes blockEntityTypes() {
return blockEntityTypes;
}

public RegiliteFluidTypes fluidTypes() {
return fluidTypesModule;
return fluidTypes;
}

public RegiliteEntities entities() {
return entitiesModule;
public RegiliteEntityTypes entityTypes() {
return entityTypes;
}

public RegiliteMenus menus() {
return regiliteMenus;
public RegiliteMenuTypes menuTypes() {
return menuTypes;
}

public DeferredRegister.DataComponents dataComponents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,43 @@
import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.registries.DeferredHolder;

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

public class BlockEntityBuilder<T extends BlockEntity>
extends RegiliteBuilder<BlockEntityBuilder<T>, BlockEntityType<?>, BlockEntityType<T>, DeferredHolder<BlockEntityType<?>, BlockEntityType<T>>> {
public class BlockEntityTypeBuilder<T extends BlockEntity>
extends RegiliteBuilder<BlockEntityTypeBuilder<T>, BlockEntityType<?>, BlockEntityType<T>, DeferredBlockEntityType<T>> {

private final RegiliteTags tagsModule;

protected Supplier<Function<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> rendererFactory;

private final List<AttachedCapability<T, ?, ?>> attachedCapabilityList = new ArrayList<>();

protected BlockEntityBuilder(DeferredHolder<BlockEntityType<?>, BlockEntityType<T>> holder, RegiliteTags tagsModule) {
protected BlockEntityTypeBuilder(DeferredBlockEntityType<T> holder, RegiliteTags tagsModule) {
super(holder);
this.tagsModule = tagsModule;
}

public BlockEntityBuilder<T> tag(TagKey<BlockEntityType<?>> tag) {
public BlockEntityTypeBuilder<T> tag(TagKey<BlockEntityType<?>> tag) {
tagsModule.blockEntityTypes().tag(tag).add(this::get);
return this;
}

@SafeVarargs
public final BlockEntityBuilder<T> tags(TagKey<BlockEntityType<?>>... tags) {
public final BlockEntityTypeBuilder<T> tags(TagKey<BlockEntityType<?>>... tags) {
tagsModule.blockEntityTypes().addToTags(this::get, tags);
return this;
}

public BlockEntityBuilder<T> renderer(Supplier<Function<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> rendererFactory) {
public BlockEntityTypeBuilder<T> renderer(Supplier<Function<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> rendererFactory) {
this.rendererFactory = rendererFactory;
return this;
}

public <TCap, TContext> BlockEntityBuilder<T> capability(BlockCapability<TCap, TContext> capability, ICapabilityProvider<? super T, TContext, TCap> provider) {
public <TCap, TContext> BlockEntityTypeBuilder<T> capability(BlockCapability<TCap, TContext> capability, ICapabilityProvider<? super T, TContext, TCap> provider) {
attachedCapabilityList.add(new AttachedCapability<>(capability, provider));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.enderio.regilite.blockentities;

import com.enderio.regilite.fluids.DeferredFluidType;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredHolder;

public class DeferredBlockEntityType<T extends BlockEntity> extends DeferredHolder<BlockEntityType<?>, BlockEntityType<T>> {
private DeferredBlockEntityType(ResourceKey<BlockEntityType<?>> key) {
super(key);
}

public static <T extends BlockEntity> DeferredBlockEntityType<T> from(DeferredHolder<BlockEntityType<?>, BlockEntityType<T>> blockEntityTypeHolder) {
return new DeferredBlockEntityType<>(blockEntityTypeHolder.getKey());
}

public T create(BlockPos pos, BlockState state) {
return value().create(pos, state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@
import java.util.Arrays;
import java.util.function.Supplier;

public class RegiliteBlockEntities implements RegiliteRegistryModule<BlockEntityType<?>, DeferredRegister<BlockEntityType<?>>>, RegiliteModuleEvents {
public class RegiliteBlockEntityTypes implements RegiliteRegistryModule<BlockEntityType<?>, DeferredRegister<BlockEntityType<?>>>, RegiliteModuleEvents {

private final RegiliteTags tagsModule;
private final DeferredRegister<BlockEntityType<?>> deferredRegister;

final ObjectList<BlockEntityBuilder<?>> blockEntities = new ObjectArrayList<>();
final ObjectList<BlockEntityTypeBuilder<?>> blockEntities = new ObjectArrayList<>();

protected RegiliteBlockEntities(RegiliteTags tagsModule, DeferredRegister<BlockEntityType<?>> deferredRegister) {
protected RegiliteBlockEntityTypes(RegiliteTags tagsModule, DeferredRegister<BlockEntityType<?>> deferredRegister) {
this.tagsModule = tagsModule;
this.deferredRegister = deferredRegister;
}

@ApiStatus.Internal
public static RegiliteBlockEntities create(Regilite regilite) {
return new RegiliteBlockEntities(regilite.tags(), DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, regilite.modId()));
public static RegiliteBlockEntityTypes create(Regilite regilite) {
return new RegiliteBlockEntityTypes(regilite.tags(), DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, regilite.modId()));
}

@SafeVarargs
public final <T extends BlockEntity> BlockEntityBuilder<T> create(String name, BlockEntityType.BlockEntitySupplier<T> factory, Supplier<? extends Block>... blocks) {
public final <T extends BlockEntity> BlockEntityTypeBuilder<T> create(String name, BlockEntityType.BlockEntitySupplier<T> factory, Supplier<? extends Block>... blocks) {
return create(name, () -> {
var blocksArray = Arrays.stream(blocks).map(Supplier::get).toList().toArray(new Block[]{});
return BlockEntityType.Builder.of(factory, blocksArray).build(null);
});
}

public <T extends BlockEntity> BlockEntityBuilder<T> create(String name, Supplier<BlockEntityType<T>> supplier) {
var holder = deferredRegister.register(name, supplier);
var builder = new BlockEntityBuilder<>(holder, tagsModule);
public <T extends BlockEntity> BlockEntityTypeBuilder<T> create(String name, Supplier<BlockEntityType<T>> supplier) {
var holder = DeferredBlockEntityType.from(deferredRegister.register(name, supplier));
var builder = new BlockEntityTypeBuilder<>(holder, tagsModule);
blockEntities.add(builder);
return builder;
}
Expand All @@ -59,12 +59,12 @@ public void register(IEventBus modEventBus) {
modEventBus.addListener(this::onRegisterCapabilities);

if (FMLEnvironment.dist.isClient()) {
modEventBus.register(new RegiliteClientBlockEntities(this));
modEventBus.register(new RegiliteClientBlockEntityTypes(this));
}
}

private void onRegisterCapabilities(RegisterCapabilitiesEvent event) {
blockEntities.forEach(blockEntityBuilder -> blockEntityBuilder.attachCapabilities(event));
blockEntities.forEach(blockEntityTypeBuilder -> blockEntityTypeBuilder.attachCapabilities(event));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;

class RegiliteClientBlockEntities {
private final RegiliteBlockEntities regiliteBlockEntities;
class RegiliteClientBlockEntityTypes {
private final RegiliteBlockEntityTypes regiliteBlockEntityTypes;

public RegiliteClientBlockEntities(RegiliteBlockEntities regiliteBlockEntities) {
this.regiliteBlockEntities = regiliteBlockEntities;
public RegiliteClientBlockEntityTypes(RegiliteBlockEntityTypes regiliteBlockEntityTypes) {
this.regiliteBlockEntityTypes = regiliteBlockEntityTypes;
}

@SubscribeEvent
public void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
for (var blockEntity : regiliteBlockEntities.blockEntities) {
for (var blockEntity : regiliteBlockEntityTypes.blockEntities) {
registerRenderer(event, blockEntity);
}
}

private <T extends BlockEntity> void registerRenderer(EntityRenderersEvent.RegisterRenderers event, BlockEntityBuilder<T> builder) {
private <T extends BlockEntity> void registerRenderer(EntityRenderersEvent.RegisterRenderers event, BlockEntityTypeBuilder<T> builder) {
if (builder.rendererFactory != null) {
event.registerBlockEntityRenderer(builder.get(), ctx -> builder.rendererFactory.get().apply(ctx));
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/enderio/regilite/blocks/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ public final BlockBuilder<T> tags(TagKey<Block>... tags) {

// TODO: more permutations, based on those available in RegiliteItems.
public BlockBuilder<T> createSimpleBlockItem() {
return withBlockItem(b -> new BlockItem(b, new Item.Properties()), i -> {});
return createBlockItem(b -> new BlockItem(b, new Item.Properties()), i -> {});
}

public BlockBuilder<T> createSimpleBlockItem(Consumer<ItemBuilder<BlockItem>> itemConfigure) {
return withBlockItem(b -> new BlockItem(b, new Item.Properties()), itemConfigure);
return createBlockItem(b -> new BlockItem(b, new Item.Properties()), itemConfigure);
}

public BlockBuilder<T> createSimpleBlockItem(Item.Properties properties, Consumer<ItemBuilder<BlockItem>> itemConfigure) {
return withBlockItem(b -> new BlockItem(b, properties), itemConfigure);
return createBlockItem(b -> new BlockItem(b, properties), itemConfigure);
}

public <I extends BlockItem> BlockBuilder<T> withBlockItem(Function<T, I> function, Consumer<ItemBuilder<I>> itemConfigure) {
public <I extends BlockItem> BlockBuilder<T> createBlockItem(Function<T, I> function, Consumer<ItemBuilder<I>> itemConfigure) {
var item = itemsModule.create(getId().getPath(), () -> function.apply(this.get()));
itemConfigure.accept(item.removeTranslation());
return this;
Expand All @@ -97,7 +97,7 @@ public BlockBuilder<T> lootTable(BiConsumer<RegiliteBlockLootProvider, T> lootTa
return this;
}

public BlockBuilder<T> blockStateProvider(BiConsumer<BlockStateProvider, DataGenContext<Block, T>> blockStateProvider) {
public BlockBuilder<T> blockState(BiConsumer<BlockStateProvider, DataGenContext<Block, T>> blockStateProvider) {
this.blockStateProvider = blockStateProvider;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.enderio.regilite.entities;

import com.enderio.regilite.RegiliteBuilder;
import com.enderio.regilite.fluids.FluidTypeBuilder;
import com.enderio.regilite.lang.RegiliteLang;
import com.enderio.regilite.tags.RegiliteTags;
import net.minecraft.client.renderer.entity.EntityRenderer;
Expand All @@ -19,7 +18,7 @@
import java.util.function.Function;
import java.util.function.Supplier;

public class EntityBuilder<T extends Entity> extends RegiliteBuilder<EntityBuilder<T>, EntityType<?>, EntityType<T>, DeferredHolder<EntityType<?>, EntityType<T>>> {
public class EntityTypeBuilder<T extends Entity> extends RegiliteBuilder<EntityTypeBuilder<T>, EntityType<?>, EntityType<T>, DeferredHolder<EntityType<?>, EntityType<T>>> {

private final RegiliteLang langModule;
private final RegiliteTags tagsModule;
Expand All @@ -28,34 +27,34 @@ public class EntityBuilder<T extends Entity> extends RegiliteBuilder<EntityBuild

private final List<AttachedCapability<T, ?, ?>> attachedCapabilityList = new ArrayList<>();

protected EntityBuilder(DeferredHolder<EntityType<?>, EntityType<T>> holder, RegiliteLang langModule, RegiliteTags tagsModule) {
protected EntityTypeBuilder(DeferredHolder<EntityType<?>, EntityType<T>> holder, RegiliteLang langModule, RegiliteTags tagsModule) {
super(holder);
this.langModule = langModule;
this.tagsModule = tagsModule;
}

public EntityBuilder<T> tag(TagKey<EntityType<?>> tag) {
public EntityTypeBuilder<T> tag(TagKey<EntityType<?>> tag) {
tagsModule.entityTypes().tag(tag).add(this::get);
return this;
}

@SafeVarargs
public final EntityBuilder<T> tags(TagKey<EntityType<?>>... tags) {
public final EntityTypeBuilder<T> tags(TagKey<EntityType<?>>... tags) {
tagsModule.entityTypes().addToTags(this::get, tags);
return this;
}

public EntityBuilder<T> translation(String translation) {
public EntityTypeBuilder<T> translation(String translation) {
langModule.addEntity(this::get, translation);
return this;
}

public EntityBuilder<T> renderer(Supplier<Function<EntityRendererProvider.Context, EntityRenderer<? super T>>> rendererFactory) {
public EntityTypeBuilder<T> renderer(Supplier<Function<EntityRendererProvider.Context, EntityRenderer<? super T>>> rendererFactory) {
this.rendererFactory = rendererFactory;
return this;
}

public <TCap, TContext> EntityBuilder<T> capability(EntityCapability<TCap, TContext> capability, ICapabilityProvider<? super T, TContext, TCap> provider) {
public <TCap, TContext> EntityTypeBuilder<T> capability(EntityCapability<TCap, TContext> capability, ICapabilityProvider<? super T, TContext, TCap> provider) {
attachedCapabilityList.add(new AttachedCapability<>(capability, provider));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;

class RegiliteClientEntities {
private final RegiliteEntities regiliteEntities;
class RegiliteClientEntityTypes {
private final RegiliteEntityTypes regiliteEntityTypes;

public RegiliteClientEntities(RegiliteEntities regiliteEntities) {
this.regiliteEntities = regiliteEntities;
public RegiliteClientEntityTypes(RegiliteEntityTypes regiliteEntityTypes) {
this.regiliteEntityTypes = regiliteEntityTypes;
}

@SubscribeEvent
public void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
for (var entity : regiliteEntities.entities) {
for (var entity : regiliteEntityTypes.entities) {
registerRenderer(event, entity);
}
}

private <T extends Entity> void registerRenderer(EntityRenderersEvent.RegisterRenderers event, EntityBuilder<T> builder) {
private <T extends Entity> void registerRenderer(EntityRenderersEvent.RegisterRenderers event, EntityTypeBuilder<T> builder) {
if (builder.rendererFactory != null) {
event.registerEntityRenderer(builder.get(), ctx -> builder.rendererFactory.get().apply(ctx));
}
Expand Down
Loading

0 comments on commit 79217f5

Please sign in to comment.