Skip to content

Commit

Permalink
Add overrides for builder accessors (#2620)
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg authored Dec 22, 2024
1 parent 6ac81a3 commit 6f54826
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.tterrag.registrate.builders.BlockBuilder;
import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.providers.ProviderType;
import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.nullness.NonNullBiConsumer;
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
Expand Down Expand Up @@ -320,22 +321,7 @@ protected DEFINITION createDefinition() {
public DEFINITION register() {
var definition = createDefinition();

var blockBuilder = registrate.block(name, properties -> {
RotationState.set(rotationState);
MachineDefinition.setBuilt(definition);
var b = blockFactory.apply(properties, definition);
RotationState.clear();
MachineDefinition.clearBuilt();
return b.self();
})
.color(() -> () -> IMachineBlock::colorTinted)
.initialProperties(() -> Blocks.DISPENSER)
.properties(BlockBehaviour.Properties::noLootTable)
.addLayer(() -> RenderType::cutoutMipped)
// .tag(GTToolType.WRENCH.harvestTag)
.blockstate(NonNullBiConsumer.noop())
.properties(blockProp)
.onRegister(b -> Arrays.stream(abilities).forEach(a -> a.register(tier, b)));
var blockBuilder = BlockBuilderWrapper.makeBlockBuilder(this, definition);
if (this.langValue != null) {
blockBuilder.lang(langValue);
definition.setLangValue(langValue);
Expand All @@ -345,12 +331,7 @@ public DEFINITION register() {
}
var block = blockBuilder.register();

var itemBuilder = registrate
.item(name, properties -> itemFactory.apply((IMachineBlock) block.get(), properties))
.setData(ProviderType.LANG, NonNullBiConsumer.noop()) // do not gen any lang keys
.model(NonNullBiConsumer.noop())
.color(() -> () -> itemColor::apply)
.properties(itemProp);
var itemBuilder = ItemBuilderWrapper.makeItemBuilder(this, block);
if (this.itemBuilder != null) {
this.itemBuilder.accept(itemBuilder);
}
Expand Down Expand Up @@ -407,4 +388,43 @@ public DEFINITION register() {
GTRegistries.MACHINES.register(definition.getId(), definition);
return definition;
}

static class BlockBuilderWrapper {

public static <
DEFINITION extends MachineDefinition> BlockBuilder<Block, Registrate> makeBlockBuilder(MachineBuilder<DEFINITION> builder,
DEFINITION definition) {
return builder.registrate.block(builder.name, properties -> {
RotationState.set(builder.rotationState);
MachineDefinition.setBuilt(definition);
var b = builder.blockFactory.apply(properties, definition);
RotationState.clear();
MachineDefinition.clearBuilt();
return b.self();
})
.color(() -> () -> IMachineBlock::colorTinted)
.initialProperties(() -> Blocks.DISPENSER)
.properties(BlockBehaviour.Properties::noLootTable)
.addLayer(() -> RenderType::cutoutMipped)
// .tag(GTToolType.WRENCH.harvestTag)
.blockstate(NonNullBiConsumer.noop())
.properties(builder.blockProp)
.onRegister(b -> Arrays.stream(builder.abilities).forEach(a -> a.register(builder.tier, b)));
}
}

static class ItemBuilderWrapper {

public static <
DEFINITION extends MachineDefinition> ItemBuilder<MetaMachineItem, Registrate> makeItemBuilder(MachineBuilder<DEFINITION> builder,
BlockEntry<Block> block) {
return builder.registrate
.item(builder.name,
properties -> builder.itemFactory.apply((IMachineBlock) block.get(), properties))
.setData(ProviderType.LANG, NonNullBiConsumer.noop()) // do not gen any lang keys
.model(NonNullBiConsumer.noop())
.color(() -> () -> builder.itemColor::apply)
.properties(builder.itemProp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gregtechceu.gtceu.api.gui.editor.EditableMachineUI;
import com.gregtechceu.gtceu.api.item.MetaMachineItem;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.machine.MultiblockMachineDefinition;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiController;
Expand Down Expand Up @@ -41,6 +42,7 @@
import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import dev.latvian.mods.rhino.util.HideFromJS;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -126,6 +128,16 @@ public MultiblockMachineBuilder recoveryStacks(Supplier<ItemStack[]> stacks) {
return this;
}

@Override
public MultiblockMachineBuilder definition(Function<ResourceLocation, MultiblockMachineDefinition> definition) {
return (MultiblockMachineBuilder) super.definition(definition);
}

@Override
public MultiblockMachineBuilder machine(Function<IMachineBlockEntity, MetaMachine> machine) {
return (MultiblockMachineBuilder) super.machine(machine);
}

@Override
public MultiblockMachineBuilder renderer(@Nullable Supplier<IRenderer> renderer) {
return (MultiblockMachineBuilder) super.renderer(renderer);
Expand Down Expand Up @@ -365,6 +377,7 @@ public MultiblockMachineBuilder onBlockEntityRegister(NonNullConsumer<BlockEntit
}

@Override
@HideFromJS
public MultiblockMachineDefinition register() {
var definition = (MultiblockMachineDefinition) super.register();
definition.setGenerator(generator);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.integration.kjs.builders;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory;
import com.gregtechceu.gtceu.api.registry.registrate.BuilderBase;
Expand Down Expand Up @@ -53,7 +54,7 @@ public GTRecipeCategoryBuilder setItemIcon(ItemStack... stacks) {
public void generateLang(LangEventJS lang) {
super.generateLang(lang);
if (langValue != null) lang.add(value.getLanguageKey(), langValue);
else lang.add(value.getLanguageKey(), FormattingUtil.toEnglishName(value.name));
else lang.add(GTCEu.MOD_ID, value.getLanguageKey(), FormattingUtil.toEnglishName(value.name));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.integration.kjs.builders.machine;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MachineDefinition;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void generateLang(LangEventJS lang) {
super.generateLang(lang);
lang.add(value.getDescriptionId(), value.getLangValue());
if (hp != null) {
lang.add(hp.getDescriptionId(), hp.getLangValue());
lang.add(GTCEu.MOD_ID, hp.getDescriptionId(), hp.getLangValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.integration.kjs.builders.machine;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.gui.editor.EditableMachineUI;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void generateLang(LangEventJS lang) {
super.generateLang(lang);
for (int tier : tiers) {
MachineDefinition def = value[tier];
lang.add(def.getDescriptionId(), def.getLangValue());
lang.add(GTCEu.MOD_ID, def.getDescriptionId(), def.getLangValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.integration.kjs.builders.machine;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MachineDefinition;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void generateLang(LangEventJS lang) {
super.generateLang(lang);
for (int tier : tiers) {
MachineDefinition def = value[tier];
lang.add(def.getDescriptionId(), def.getLangValue());
lang.add(GTCEu.MOD_ID, def.getDescriptionId(), def.getLangValue());
}
}

Expand Down

0 comments on commit 6f54826

Please sign in to comment.