Create your own registrate!

This commit is contained in:
rhysdh540 2023-07-18 08:50:28 -04:00
parent 7e4a084ec6
commit 5839a463cf
17 changed files with 66 additions and 43 deletions

View file

@ -0,0 +1,10 @@
package com.notsimibubi.badcreateaddon;
import com.simibubi.create.Create;
import com.simibubi.create.foundation.data.CreateRegistrate;
public class Test {
public static void test() {
CreateRegistrate plscrash = Create.registrate();
}
}

View file

@ -1,6 +1,5 @@
package com.simibubi.create;
import static com.simibubi.create.Create.REGISTRATE;
import static com.simibubi.create.content.redstone.displayLink.AllDisplayBehaviours.assignDataBehaviourBE;
import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsBlockEntity;
@ -214,10 +213,13 @@ import com.simibubi.create.content.trains.track.TrackInstance;
import com.simibubi.create.content.trains.track.TrackMaterial;
import com.simibubi.create.content.trains.track.TrackRenderer;
import com.simibubi.create.foundation.blockEntity.renderer.SmartBlockEntityRenderer;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.tterrag.registrate.util.entry.BlockEntityEntry;
public class AllBlockEntityTypes {
private static final CreateRegistrate REGISTRATE = Create.registrate();
// Schematics
public static final BlockEntityEntry<SchematicannonBlockEntity> SCHEMATICANNON = REGISTRATE
.blockEntity("schematicannon", SchematicannonBlockEntity::new)
@ -322,7 +324,7 @@ public class AllBlockEntityTypes {
.validBlocks(AllBlocks.HAND_CRANK)
.renderer(() -> HandCrankRenderer::new)
.register();
public static final BlockEntityEntry<ValveHandleBlockEntity> VALVE_HANDLE = REGISTRATE
.blockEntity("valve_handle", ValveHandleBlockEntity::new)
.instance(() -> HandCrankInstance::new)
@ -708,7 +710,7 @@ public class AllBlockEntityTypes {
.validBlocks(AllBlocks.ANALOG_LEVER)
.renderer(() -> AnalogLeverRenderer::new)
.register();
public static final BlockEntityEntry<PlacardBlockEntity> PLACARD = REGISTRATE
.blockEntity("placard", PlacardBlockEntity::new)
.validBlocks(AllBlocks.PLACARD)
@ -835,7 +837,7 @@ public class AllBlockEntityTypes {
.validBlocksDeferred(TrackMaterial::allBlocks)
.renderer(() -> TrackRenderer::new)
.register();
public static final BlockEntityEntry<FakeTrackBlockEntity> FAKE_TRACK = REGISTRATE
.blockEntity("fake_track", FakeTrackBlockEntity::new)
.validBlocks(AllBlocks.FAKE_TRACK)
@ -883,7 +885,7 @@ public class AllBlockEntityTypes {
.renderer(() -> TrackObserverRenderer::new)
.validBlocks(AllBlocks.TRACK_OBSERVER)
.register();
public static final BlockEntityEntry<ClipboardBlockEntity> CLIPBOARD = REGISTRATE
.blockEntity("clipboard", ClipboardBlockEntity::new)
.validBlocks(AllBlocks.CLIPBOARD)

View file

@ -2,7 +2,6 @@ package com.simibubi.create;
import static com.simibubi.create.AllInteractionBehaviours.interactionBehaviour;
import static com.simibubi.create.AllMovementBehaviours.movementBehaviour;
import static com.simibubi.create.Create.REGISTRATE;
import static com.simibubi.create.content.redstone.displayLink.AllDisplayBehaviours.assignDataBehaviour;
import static com.simibubi.create.foundation.data.BlockStateGen.axisBlock;
import static com.simibubi.create.foundation.data.BlockStateGen.simpleCubeAll;
@ -310,6 +309,8 @@ import net.minecraftforge.common.util.ForgeSoundType;
public class AllBlocks {
private static final CreateRegistrate REGISTRATE = Create.registrate();
static {
REGISTRATE.creativeModeTab(() -> AllCreativeModeTabs.BASE_CREATIVE_TAB);
}

View file

@ -1,9 +1,8 @@
package com.simibubi.create;
import static com.simibubi.create.Create.REGISTRATE;
import com.simibubi.create.content.equipment.armor.CapacityEnchantment;
import com.simibubi.create.content.equipment.potatoCannon.PotatoRecoveryEnchantment;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraft.world.entity.EquipmentSlot;
@ -12,13 +11,15 @@ import net.minecraft.world.item.enchantment.EnchantmentCategory;
public class AllEnchantments {
private static final CreateRegistrate REGISTRATE = Create.registrate();
public static final RegistryEntry<PotatoRecoveryEnchantment> POTATO_RECOVERY = REGISTRATE.object("potato_recovery")
.enchantment(EnchantmentCategory.BOW, PotatoRecoveryEnchantment::new)
.addSlots(EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND)
.lang("Potato Recovery")
.rarity(Rarity.UNCOMMON)
.register();
public static final RegistryEntry<CapacityEnchantment> CAPACITY = REGISTRATE.object("capacity")
.enchantment(EnchantmentCategory.ARMOR_CHEST, CapacityEnchantment::new)
.addSlots(EquipmentSlot.CHEST)

View file

@ -73,7 +73,7 @@ public class AllEntityTypes {
MobCategory group, int range, int updateFrequency, boolean sendVelocity, boolean immuneToFire,
NonNullConsumer<EntityType.Builder<T>> propertyBuilder) {
String id = Lang.asId(name);
return (CreateEntityBuilder<T, ?>) Create.REGISTRATE
return (CreateEntityBuilder<T, ?>) Create.registrate()
.entity(id, factory, group)
.properties(b -> b.setTrackingRange(range)
.setUpdateInterval(updateFrequency)

View file

@ -1,7 +1,5 @@
package com.simibubi.create;
import static com.simibubi.create.Create.REGISTRATE;
import javax.annotation.Nullable;
import com.simibubi.create.AllTags.AllFluidTags;
@ -9,6 +7,7 @@ import com.simibubi.create.content.decoration.palettes.AllPaletteStoneTypes;
import com.simibubi.create.content.fluids.VirtualFluid;
import com.simibubi.create.content.fluids.potion.PotionFluid;
import com.simibubi.create.content.fluids.potion.PotionFluid.PotionFluidAttributes;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.tterrag.registrate.util.entry.FluidEntry;
import net.minecraft.core.BlockPos;
@ -21,6 +20,8 @@ import net.minecraftforge.fluids.ForgeFlowingFluid;
public class AllFluids {
private static final CreateRegistrate REGISTRATE = Create.registrate();
public static final FluidEntry<PotionFluid> POTION =
REGISTRATE.virtualFluid("potion", PotionFluidAttributes::new, PotionFluid::new)
.lang("Potion")
@ -93,5 +94,5 @@ public class AllFluids {
}
}
}

View file

@ -4,7 +4,6 @@ import static com.simibubi.create.AllTags.forgeItemTag;
import static com.simibubi.create.AllTags.AllItemTags.CREATE_INGOTS;
import static com.simibubi.create.AllTags.AllItemTags.CRUSHED_RAW_MATERIALS;
import static com.simibubi.create.AllTags.AllItemTags.PLATES;
import static com.simibubi.create.Create.REGISTRATE;
import static com.simibubi.create.foundation.data.recipe.CompatMetals.ALUMINUM;
import static com.simibubi.create.foundation.data.recipe.CompatMetals.LEAD;
import static com.simibubi.create.foundation.data.recipe.CompatMetals.NICKEL;
@ -68,6 +67,8 @@ import net.minecraftforge.common.Tags;
public class AllItems {
private static final CreateRegistrate REGISTRATE = Create.registrate();
static {
REGISTRATE.creativeModeTab(() -> AllCreativeModeTabs.BASE_CREATIVE_TAB);
}

View file

@ -44,16 +44,16 @@ public class AllMenuTypes {
public static final MenuEntry<LinkedControllerMenu> LINKED_CONTROLLER =
register("linked_controller", LinkedControllerMenu::new, () -> LinkedControllerScreen::new);
public static final MenuEntry<ToolboxMenu> TOOLBOX =
register("toolbox", ToolboxMenu::new, () -> ToolboxScreen::new);
public static final MenuEntry<ScheduleMenu> SCHEDULE =
register("schedule", ScheduleMenu::new, () -> ScheduleScreen::new);
private static <C extends AbstractContainerMenu, S extends Screen & MenuAccess<C>> MenuEntry<C> register(
String name, ForgeMenuFactory<C> factory, NonNullSupplier<ScreenFactory<C, S>> screenFactory) {
return Create.REGISTRATE
return Create.registrate()
.menu(name, factory, screenFactory)
.register();
}

View file

@ -2,6 +2,8 @@ package com.simibubi.create;
import java.util.Random;
import com.notsimibubi.badcreateaddon.Test;
import org.slf4j.Logger;
import com.google.gson.Gson;
@ -81,13 +83,18 @@ public class Create {
@Deprecated
public static final Random RANDOM = new Random();
public static final CreateRegistrate REGISTRATE = CreateRegistrate.create(ID);
private static final CreateRegistrate REGISTRATE = CreateRegistrate.create(ID);
public static CreateRegistrate registrate() {
Class<?> callerClass = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass();
if(callerClass.getPackageName().contains("com.simibubi.create"))
return REGISTRATE;
throw new IllegalCallerException("Create your own registrate!");
}
static {
REGISTRATE.setTooltipModifierFactory(item -> {
return new ItemDescription.Modifier(item, Palette.STANDARD_CREATE)
.andThen(TooltipModifier.mapNull(KineticStats.create(item)));
});
REGISTRATE.setTooltipModifierFactory(item -> new ItemDescription.Modifier(item, Palette.STANDARD_CREATE)
.andThen(TooltipModifier.mapNull(KineticStats.create(item))));
}
public static final ServerSchematicLoader SCHEMATIC_RECEIVER = new ServerSchematicLoader();
@ -101,6 +108,7 @@ public class Create {
}
public static void onCtor() {
Test.test();
ModLoadingContext modLoadingContext = ModLoadingContext.get();
IEventBus modEventBus = FMLJavaModLoadingContext.get()

View file

@ -1,6 +1,5 @@
package com.simibubi.create.content.decoration.palettes;
import static com.simibubi.create.Create.REGISTRATE;
import static com.simibubi.create.foundation.data.WindowGen.customWindowBlock;
import static com.simibubi.create.foundation.data.WindowGen.customWindowPane;
import static com.simibubi.create.foundation.data.WindowGen.framedGlass;
@ -14,6 +13,7 @@ import com.simibubi.create.Create;
import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour;
import com.simibubi.create.foundation.block.connected.SimpleCTBehaviour;
import com.simibubi.create.foundation.data.BlockStateGen;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.simibubi.create.foundation.data.WindowGen;
import com.tterrag.registrate.util.DataIngredient;
import com.tterrag.registrate.util.entry.BlockEntry;
@ -30,6 +30,8 @@ import net.minecraftforge.common.Tags;
public class AllPaletteBlocks {
private static final CreateRegistrate REGISTRATE = Create.registrate();
static {
REGISTRATE.creativeModeTab(() -> AllCreativeModeTabs.PALETTES_CREATIVE_TAB);
}

View file

@ -54,7 +54,7 @@ public abstract class PaletteBlockPartial<B extends Block> {
String patternName = Lang.nonPluralId(pattern.createName(variantName));
String blockName = patternName + "_" + this.name;
BlockBuilder<B, CreateRegistrate> blockBuilder = Create.REGISTRATE
BlockBuilder<B, CreateRegistrate> blockBuilder = Create.registrate()
.block(blockName, p -> createBlock(block))
.blockstate((c, p) -> generateBlockState(c, p, variantName, pattern, block))
.recipe((c, p) -> createRecipes(variant, block, c, p))

View file

@ -1,6 +1,5 @@
package com.simibubi.create.content.decoration.palettes;
import static com.simibubi.create.Create.REGISTRATE;
import static com.simibubi.create.foundation.data.CreateRegistrate.connectedTextures;
import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly;
@ -32,7 +31,7 @@ public class PalettesVariantEntry {
for (PaletteBlockPattern pattern : paletteStoneVariants.variantTypes) {
BlockBuilder<? extends Block, CreateRegistrate> builder =
REGISTRATE.block(pattern.createName(name), pattern.getBlockFactory())
Create.registrate().block(pattern.createName(name), pattern.getBlockFactory())
.initialProperties(baseBlock)
.transform(pickaxeOnly())
.blockstate(pattern.getBlockStateGenerator()
@ -70,9 +69,9 @@ public class PalettesVariantEntry {
.register());
}
Create.REGISTRATE.addDataGenerator(ProviderType.RECIPE,
Create.registrate().addDataGenerator(ProviderType.RECIPE,
p -> p.stonecutting(DataIngredient.tag(paletteStoneVariants.materialTag), baseBlock));
Create.REGISTRATE.addDataGenerator(ProviderType.ITEM_TAGS, p -> p.tag(paletteStoneVariants.materialTag)
Create.registrate().addDataGenerator(ProviderType.ITEM_TAGS, p -> p.tag(paletteStoneVariants.materialTag)
.add(baseBlock.get()
.asItem()));

View file

@ -1,6 +1,5 @@
package com.simibubi.create.foundation.data;
import static com.simibubi.create.Create.REGISTRATE;
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.EAST;
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.NORTH;
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.SOUTH;
@ -123,7 +122,7 @@ public class MetalBarsGen {
public static BlockEntry<IronBarsBlock> createBars(String name, boolean specialEdge,
Supplier<DataIngredient> ingredient, MaterialColor color) {
return REGISTRATE.block(name + "_bars", IronBarsBlock::new)
return Create.registrate().block(name + "_bars", IronBarsBlock::new)
.addLayer(() -> RenderType::cutoutMipped)
.initialProperties(() -> Blocks.IRON_BARS)
.properties(p -> p.sound(SoundType.COPPER)

View file

@ -65,10 +65,10 @@ public class TagGen {
}
public static void datagen() {
Create.REGISTRATE.addDataGenerator(ProviderType.BLOCK_TAGS, TagGen::genBlockTags);
Create.REGISTRATE.addDataGenerator(ProviderType.ITEM_TAGS, TagGen::genItemTags);
Create.REGISTRATE.addDataGenerator(ProviderType.FLUID_TAGS, TagGen::genFluidTags);
Create.REGISTRATE.addDataGenerator(ProviderType.ENTITY_TAGS, TagGen::genEntityTags);
Create.registrate().addDataGenerator(ProviderType.BLOCK_TAGS, TagGen::genBlockTags);
Create.registrate().addDataGenerator(ProviderType.ITEM_TAGS, TagGen::genItemTags);
Create.registrate().addDataGenerator(ProviderType.FLUID_TAGS, TagGen::genFluidTags);
Create.registrate().addDataGenerator(ProviderType.ENTITY_TAGS, TagGen::genEntityTags);
}
private static void genBlockTags(RegistrateTagsProvider<Block> prov) {
@ -147,7 +147,7 @@ public class TagGen {
prov.tag(AllItemTags.STRIPPED_WOOD.tag)
.addTag(AllItemTags.VANILLA_STRIPPED_WOOD.tag)
.addTag(AllItemTags.MODDED_STRIPPED_WOOD.tag);
prov.tag(AllItemTags.DEPLOYABLE_DRINK.tag)
.add(Items.MILK_BUCKET, Items.POTION);
@ -230,7 +230,7 @@ public class TagGen {
}
private static void genEntityTags(RegistrateTagsProvider<EntityType<?>> prov) {
// VALIDATE
for (AllEntityTags tag : AllEntityTags.values()) {

View file

@ -1,6 +1,5 @@
package com.simibubi.create.foundation.data;
import static com.simibubi.create.Create.REGISTRATE;
import static com.simibubi.create.foundation.data.CreateRegistrate.connectedTextures;
import java.util.function.Function;
@ -86,7 +85,7 @@ public class WindowGen {
Supplier<CTSpriteShiftEntry> ct, Supplier<Supplier<RenderType>> renderType,
NonNullFunction<String, ResourceLocation> endTexture, NonNullFunction<String, ResourceLocation> sideTexture,
Supplier<MaterialColor> color) {
return REGISTRATE.block(name, WindowBlock::new)
return Create.registrate().block(name, WindowBlock::new)
.onRegister(connectedTextures(() -> new HorizontalCTBehaviour(ct.get())))
.addLayer(renderType)
.recipe((c, p) -> ShapedRecipeBuilder.shaped(c.get(), 2)
@ -109,7 +108,7 @@ public class WindowGen {
public static BlockEntry<ConnectedGlassBlock> framedGlass(String name,
Supplier<ConnectedTextureBehaviour> behaviour) {
return REGISTRATE.block(name, ConnectedGlassBlock::new)
return Create.registrate().block(name, ConnectedGlassBlock::new)
.onRegister(connectedTextures(behaviour))
.addLayer(() -> RenderType::cutout)
.initialProperties(() -> Blocks.GLASS)
@ -202,7 +201,7 @@ public class WindowGen {
NonNullBiConsumer<DataGenContext<Block, G>, RegistrateBlockstateProvider> stateProvider) {
name += "_pane";
return REGISTRATE.block(name, factory)
return Create.registrate().block(name, factory)
.onRegister(connectedTextures)
.addLayer(renderType)
.initialProperties(() -> Blocks.GLASS_PANE)

View file

@ -28,7 +28,7 @@ public abstract class CreateCreativeModeTab extends CreativeModeTab {
}
protected Collection<RegistryEntry<Item>> registeredItems() {
return Create.REGISTRATE.getAll(ForgeRegistries.ITEMS.getRegistryKey());
return Create.registrate().getAll(ForgeRegistries.ITEMS.getRegistryKey());
}
public void addBlocks(NonNullList<ItemStack> items) {

View file

@ -109,7 +109,7 @@ public class PonderIndex {
AllPonderTags.KINETIC_SOURCES);
HELPER.addStoryBoard(AllBlocks.LARGE_WATER_WHEEL, "large_water_wheel", KineticsScenes::largeWaterWheel,
AllPonderTags.KINETIC_SOURCES);
HELPER.addStoryBoard(AllBlocks.HAND_CRANK, "hand_crank", KineticsScenes::handCrank, AllPonderTags.KINETIC_SOURCES);
HELPER.addStoryBoard(AllBlocks.COPPER_VALVE_HANDLE, "valve_handle", KineticsScenes::valveHandle,
@ -355,7 +355,7 @@ public class PonderIndex {
.map((trackSupplier) -> new BlockEntry<TrackBlock>(
// note: these blocks probably WON'T be in the Create Registrate, but a simple
// code trace reveals the Entry's registrate isn't used
Create.REGISTRATE, RegistryObject.create(trackSupplier.get()
Create.registrate(), RegistryObject.create(trackSupplier.get()
.getRegistryName(), ForgeRegistries.BLOCKS)))
.toList())
.addStoryBoard("train_track/placement", TrackScenes::placement)