Skip to content

Commit

Permalink
Port to deferred registration
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jul 13, 2024
1 parent 0d3ca7b commit 06c3786
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 124 deletions.
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ run {

versionCatalogs {
create("libs") {
version("neoforge", "21.0.13-beta")
version("neoforge", "21.0.87-beta")

version("ae2", "19.0.5-alpha")
version("ae2", "19.0.11-alpha")
library("ae2", "appeng", "appliedenergistics2").versionRef("ae2")

version("requester", "1.20.4-1.1.6")
Expand Down
6 changes: 3 additions & 3 deletions src/data/java/gripe/_90/fulleng/datagen/FullDropProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public void generate(@NotNull BiConsumer<ResourceKey<LootTable>, LootTable.Build

@Override
public void generate() {
for (var block : FullEngBlocks.getBlocks()) {
for (var block : FullEngBlocks.BLOCKS.getEntries()) {
add(
block.block(),
block.get(),
LootTable.lootTable()
.withPool(LootPool.lootPool()
.setRolls(ConstantValue.exactly(1))
.add(LootItem.lootTableItem(block))
.add(LootItem.lootTableItem(block.get()))
.when(ExplosionCondition.survivesExplosion())));
}
}
Expand Down
23 changes: 13 additions & 10 deletions src/data/java/gripe/_90/fulleng/datagen/FullModelProvider.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package gripe._90.fulleng.datagen;

import net.minecraft.data.PackOutput;
import net.minecraft.data.models.blockstates.MultiVariantGenerator;
import net.minecraft.data.models.blockstates.PropertyDispatch;
import net.minecraft.data.models.blockstates.Variant;
import net.minecraft.data.models.blockstates.VariantProperties;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.client.model.generators.ModelProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.registries.DeferredBlock;

import appeng.core.definitions.BlockDefinition;
import appeng.datagen.providers.models.AE2BlockStateProvider;

import gripe._90.fulleng.FullblockEnergistics;
Expand Down Expand Up @@ -36,49 +37,50 @@ protected void registerStatesAndModels() {
terminal(FullEngBlocks.REQUESTER_TERMINAL, "merequester:part/requester_terminal");
}

private void terminal(BlockDefinition<?> terminal, String texturePrefix) {
private void terminal(DeferredBlock<?> terminal, String texturePrefix) {
var existing = models().existingFileHelper;
existing.trackGenerated(ResourceLocation.parse(texturePrefix + "_bright"), ModelProvider.TEXTURE);
existing.trackGenerated(ResourceLocation.parse(texturePrefix + "_medium"), ModelProvider.TEXTURE);
existing.trackGenerated(ResourceLocation.parse(texturePrefix + "_dark"), ModelProvider.TEXTURE);

var onModel = terminal != FullEngBlocks.TERMINAL
? models().withExistingParent(
"block/" + terminal.id().getPath(), FullblockEnergistics.MODID + ":block/terminal")
"block/" + terminal.getId().getPath(), FullblockEnergistics.MODID + ":block/terminal")
.texture("lightsBright", texturePrefix + "_bright")
.texture("lightsMedium", texturePrefix + "_medium")
.texture("lightsDark", texturePrefix + "_dark")
.renderType("cutout")
: models().getExistingFile(FullblockEnergistics.makeId("block/terminal"));

multiVariantGenerator(terminal, Variant.variant())
var builder = MultiVariantGenerator.multiVariant(terminal.get())
.with(createFacingSpinDispatch())
.with(PropertyDispatch.property(FullBlock.POWERED).generate(powered -> Variant.variant()
.with(VariantProperties.MODEL, powered ? onModel.getLocation() : TERMINAL_OFF)));
simpleBlockItem(terminal.block(), onModel);
registeredBlocks.put(terminal.get(), () -> builder.get().getAsJsonObject());
simpleBlockItem(terminal.get(), onModel);
}

private void monitor(BlockDefinition<?> monitor, String texturePrefix) {
private void monitor(DeferredBlock<?> monitor, String texturePrefix) {
var existing = models().existingFileHelper;
existing.trackGenerated(ResourceLocation.parse(texturePrefix + "_bright"), ModelProvider.TEXTURE);
existing.trackGenerated(ResourceLocation.parse(texturePrefix + "_medium"), ModelProvider.TEXTURE);
existing.trackGenerated(ResourceLocation.parse(texturePrefix + "_dark"), ModelProvider.TEXTURE);
existing.trackGenerated(ResourceLocation.parse(texturePrefix + "_dark_locked"), ModelProvider.TEXTURE);

var unlockedModel = models().withExistingParent(
"block/" + monitor.id().getPath(), FullblockEnergistics.MODID + ":block/terminal")
"block/" + monitor.getId().getPath(), FullblockEnergistics.MODID + ":block/terminal")
.texture("lightsBright", texturePrefix + "_bright")
.texture("lightsMedium", texturePrefix + "_medium")
.texture("lightsDark", texturePrefix + "_dark")
.renderType("cutout");
var lockedModel = models().withExistingParent(
"block/" + monitor.id().getPath(), FullblockEnergistics.MODID + ":block/terminal")
"block/" + monitor.getId().getPath(), FullblockEnergistics.MODID + ":block/terminal")
.texture("lightsBright", texturePrefix + "_bright")
.texture("lightsMedium", texturePrefix + "_medium")
.texture("lightsDark", texturePrefix + "_dark_locked")
.renderType("cutout");

multiVariantGenerator(monitor, Variant.variant())
var builder = MultiVariantGenerator.multiVariant(monitor.get())
.with(createFacingSpinDispatch())
.with(PropertyDispatch.properties(FullBlock.POWERED, MonitorBlock.LOCKED)
.generate((powered, locked) -> Variant.variant()
Expand All @@ -87,7 +89,8 @@ private void monitor(BlockDefinition<?> monitor, String texturePrefix) {
!powered
? TERMINAL_OFF
: locked ? lockedModel.getLocation() : unlockedModel.getLocation())));
simpleBlockItem(monitor.block(), unlockedModel);
registeredBlocks.put(monitor.get(), () -> builder.get().getAsJsonObject());
simpleBlockItem(monitor.get(), unlockedModel);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.data.recipes.ShapelessRecipeBuilder;

import appeng.core.definitions.BlockDefinition;
import net.neoforged.neoforge.registries.DeferredBlock;

import gripe._90.fulleng.FullblockEnergistics;
import gripe._90.fulleng.block.FullBlock;
Expand All @@ -39,8 +38,8 @@ public void buildRecipes(@NotNull RecipeOutput output) {
}
}

private void block(RecipeOutput output, BlockDefinition<? extends FullBlock<?>> block) {
var part = block.block().getEquivalentPart();
private void block(RecipeOutput output, DeferredBlock<? extends FullBlock<?>> block) {
var part = block.get().getEquivalentPart();
var partId = BuiltInRegistries.ITEM.getKey(part.asItem()).getPath();

ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, block)
Expand Down
4 changes: 2 additions & 2 deletions src/data/java/gripe/_90/fulleng/datagen/FullTagProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public FullTagProvider(PackOutput output, CompletableFuture<HolderLookup.Provide

@Override
protected void addTags(@NotNull HolderLookup.Provider provider) {
FullEngBlocks.getBlocks().forEach(b -> tag(BlockTags.MINEABLE_WITH_PICKAXE)
.add(BuiltInRegistries.BLOCK.getResourceKey(b.block()).orElseThrow()));
FullEngBlocks.BLOCKS.getEntries().forEach(b -> tag(BlockTags.MINEABLE_WITH_PICKAXE)
.add(BuiltInRegistries.BLOCK.getResourceKey(b.get()).orElseThrow()));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21 2024-07-11T19:11:25.597674337 Block States / Models
// 1.21 2024-07-13T13:19:04.18803467 Block States / Models
39f3a7fbd9af83227152e49f0f7d28ba69532c1b assets/fulleng/blockstates/conversion_monitor.json
48d2853ffde2d08b63407795966ee8b9c28831b2 assets/fulleng/blockstates/crafting_terminal.json
a4f2d912b855982d7cc54e3ec6dbf81935cd1f9d assets/fulleng/blockstates/pattern_access_terminal.json
Expand Down
37 changes: 16 additions & 21 deletions src/main/java/gripe/_90/fulleng/FullblockEnergistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import gripe._90.fulleng.block.entity.monitor.ConversionMonitorBlockEntity;
import gripe._90.fulleng.client.MonitorBlockEntityRenderer;
import gripe._90.fulleng.definition.FullEngBlockEntities;
import gripe._90.fulleng.definition.FullEngBEs;
import gripe._90.fulleng.definition.FullEngBlocks;
import gripe._90.fulleng.integration.Addons;
import gripe._90.fulleng.integration.requester.RequesterIntegration;
Expand All @@ -49,7 +49,10 @@ public static ResourceLocation makeId(String path) {
}

public FullblockEnergistics(IEventBus modEventBus) {
modEventBus.addListener(this::registerAll);
FullEngBlocks.register(modEventBus);
FullEngBEs.DR.register(modEventBus);

modEventBus.addListener(this::register);
modEventBus.addListener(this::registerCapabilities);
modEventBus.addListener(this::addToCreativeTab);

Expand All @@ -58,38 +61,30 @@ public FullblockEnergistics(IEventBus modEventBus) {
}
}

private void registerAll(RegisterEvent event) {
FullEngBlocks.getBlocks().forEach(block -> {
event.register(Registries.BLOCK, block.id(), block::block);
event.register(Registries.ITEM, block.id(), block::asItem);
});

event.register(Registries.BLOCK_ENTITY_TYPE, helper -> FullEngBlockEntities.getBlockEntities()
.forEach(helper::register));

private void register(RegisterEvent event) {
if (Addons.MEREQUESTER.isLoaded()) {
event.register(
Registries.MENU, AppEng.makeId("requester_terminal_f"), () -> RequesterTerminalMenu.TYPE_FULLBLOCK);
}
}

private void registerCapabilities(RegisterCapabilitiesEvent event) {
for (var type : FullEngBlockEntities.getBlockEntities().values()) {
for (var type : FullEngBEs.DR.getEntries()) {
event.registerBlockEntity(
AECapabilities.IN_WORLD_GRID_NODE_HOST, type, (be, context) -> (IInWorldGridNodeHost) be);
AECapabilities.IN_WORLD_GRID_NODE_HOST, type.get(), (be, context) -> (IInWorldGridNodeHost) be);
}

event.registerBlockEntity(
Capabilities.ItemHandler.BLOCK,
FullEngBlockEntities.PATTERN_ENCODING_TERMINAL,
FullEngBEs.PATTERN_ENCODING_TERMINAL.get(),
(be, context) -> context != Direction.NORTH
? be.getLogic().getBlankPatternInv().toItemHandler()
: null);
}

private void addToCreativeTab(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey().equals(AECreativeTabIds.MAIN)) {
FullEngBlocks.getBlocks().forEach(event::accept);
FullEngBlocks.BLOCKS.getEntries().forEach(b -> event.accept(b.get()));
}
}

Expand All @@ -109,19 +104,19 @@ private void initScreens(RegisterMenuScreensEvent event) {
}

private void initBlockEntityRenders(ModelEvent.RegisterGeometryLoaders ignoredEvent) {
BlockEntityRenderers.register(FullEngBlockEntities.STORAGE_MONITOR, MonitorBlockEntityRenderer::new);
BlockEntityRenderers.register(FullEngBlockEntities.CONVERSION_MONITOR, MonitorBlockEntityRenderer::new);
BlockEntityRenderers.register(FullEngBEs.STORAGE_MONITOR.get(), MonitorBlockEntityRenderer::new);
BlockEntityRenderers.register(FullEngBEs.CONVERSION_MONITOR.get(), MonitorBlockEntityRenderer::new);
}

private void registerBlockColourProviders(RegisterColorHandlersEvent.Block event) {
for (var block : FullEngBlocks.getBlocks()) {
event.register(new ColorableBlockEntityBlockColor(), block.block());
for (var block : FullEngBlocks.BLOCKS.getEntries()) {
event.register(new ColorableBlockEntityBlockColor(), block.get());
}
}

private void registerItemColourProviders(RegisterColorHandlersEvent.Item event) {
for (var block : FullEngBlocks.getBlocks()) {
event.register(new StaticItemColor(AEColor.TRANSPARENT), block.asItem());
for (var block : FullEngBlocks.BLOCKS.getEntries()) {
event.register(new StaticItemColor(AEColor.TRANSPARENT), block.get());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gripe/_90/fulleng/block/TerminalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public InteractionResult useWithoutItem(

@Override
public boolean hasAnalogOutputSignal(BlockState state) {
return state.is(FullEngBlocks.PATTERN_ENCODING_TERMINAL.block());
return state.is(FullEngBlocks.PATTERN_ENCODING_TERMINAL.get());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import appeng.api.networking.IGridNodeListener;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.blockentity.grid.AENetworkBlockEntity;
import appeng.blockentity.grid.AENetworkedBlockEntity;

public abstract class FullBlockEntity extends AENetworkBlockEntity implements IColorableBlockEntity {
public abstract class FullBlockEntity extends AENetworkedBlockEntity implements IColorableBlockEntity {
private AEColor paintedColour = AEColor.TRANSPARENT;
private boolean isActive = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import appeng.menu.me.crafting.CraftAmountMenu;
import appeng.util.inv.PlayerInternalInventory;

import gripe._90.fulleng.definition.FullEngBlockEntities;
import gripe._90.fulleng.definition.FullEngBEs;

public class ConversionMonitorBlockEntity extends StorageMonitorBlockEntity implements ISubMenuHost {
public ConversionMonitorBlockEntity(BlockPos pos, BlockState state) {
super(FullEngBlockEntities.CONVERSION_MONITOR, pos, state);
super(FullEngBEs.CONVERSION_MONITOR.get(), pos, state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import appeng.core.localization.PlayerMessages;

import gripe._90.fulleng.block.entity.FullBlockEntity;
import gripe._90.fulleng.definition.FullEngBlockEntities;
import gripe._90.fulleng.definition.FullEngBEs;

@SuppressWarnings("UnstableApiUsage")
public class StorageMonitorBlockEntity extends FullBlockEntity implements INetworkToolAware {
Expand All @@ -39,7 +39,7 @@ public class StorageMonitorBlockEntity extends FullBlockEntity implements INetwo
private IStackWatcher craftingWatcher;

public StorageMonitorBlockEntity(BlockPos pos, BlockState state) {
this(FullEngBlockEntities.STORAGE_MONITOR, pos, state);
this(FullEngBEs.STORAGE_MONITOR.get(), pos, state);
}

public StorageMonitorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import appeng.parts.reporting.CraftingTerminalPart;
import appeng.util.inv.AppEngInternalInventory;

import gripe._90.fulleng.definition.FullEngBlockEntities;
import gripe._90.fulleng.definition.FullEngBEs;

public class CraftingTerminalBlockEntity extends StorageTerminalBlockEntity {
private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory(this, 9);

public CraftingTerminalBlockEntity(BlockPos pos, BlockState blockState) {
super(FullEngBlockEntities.CRAFTING_TERMINAL, pos, blockState);
super(FullEngBEs.CRAFTING_TERMINAL.get(), pos, blockState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import appeng.api.util.IConfigManagerBuilder;
import appeng.menu.implementations.PatternAccessTermMenu;

import gripe._90.fulleng.definition.FullEngBlockEntities;
import gripe._90.fulleng.definition.FullEngBEs;

public class PatternAccessTerminalBlockEntity extends TerminalBlockEntity implements IPatternAccessTermMenuHost {
public PatternAccessTerminalBlockEntity(BlockPos pos, BlockState blockState) {
super(FullEngBlockEntities.PATTERN_ACCESS_TERMINAL, pos, blockState);
super(FullEngBEs.PATTERN_ACCESS_TERMINAL.get(), pos, blockState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import appeng.parts.encoding.PatternEncodingLogic;
import appeng.util.inv.AppEngInternalInventory;

import gripe._90.fulleng.definition.FullEngBlockEntities;
import gripe._90.fulleng.definition.FullEngBEs;

public class PatternEncodingTerminalBlockEntity extends StorageTerminalBlockEntity
implements IPatternTerminalLogicHost, IPatternTerminalMenuHost {
private final PatternEncodingLogic logic = new PatternEncodingLogic(this);

public PatternEncodingTerminalBlockEntity(BlockPos pos, BlockState blockState) {
super(FullEngBlockEntities.PATTERN_ENCODING_TERMINAL, pos, blockState);
super(FullEngBEs.PATTERN_ENCODING_TERMINAL.get(), pos, blockState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import appeng.util.inv.AppEngInternalInventory;
import appeng.util.inv.InternalInventoryHost;

import gripe._90.fulleng.definition.FullEngBlockEntities;
import gripe._90.fulleng.definition.FullEngBEs;

public class StorageTerminalBlockEntity extends TerminalBlockEntity
implements ITerminalHost, IViewCellStorage, InternalInventoryHost {
private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5);

public StorageTerminalBlockEntity(BlockPos pos, BlockState state) {
this(FullEngBlockEntities.TERMINAL, pos, state);
this(FullEngBEs.TERMINAL.get(), pos, state);
}

public StorageTerminalBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
Expand Down
Loading

0 comments on commit 06c3786

Please sign in to comment.