mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 12:33:57 +01:00
Update Registrate, use onRegister function instead of CreateBlockBuilder
This commit is contained in:
parent
deb03d10de
commit
c3cdf346f7
@ -97,7 +97,7 @@ configurations {
|
||||
dependencies {
|
||||
minecraft 'net.minecraftforge:forge:1.15.2-31.1.36'
|
||||
|
||||
def registrate = "com.tterrag.registrate:Registrate:MC1.15.2-0.0.3.9"
|
||||
def registrate = "com.tterrag.registrate:Registrate:MC1.15.2-0.0.3.11"
|
||||
implementation fg.deobf(registrate)
|
||||
shade registrate
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class AllBlocksNew {
|
||||
}
|
||||
|
||||
public static final BlockEntry<SchematicannonBlock> SCHEMATICANNON =
|
||||
REGISTRATE.createBlock("schematicannon", SchematicannonBlock::new)
|
||||
REGISTRATE.block("schematicannon", SchematicannonBlock::new)
|
||||
.initialProperties(() -> Blocks.DISPENSER)
|
||||
.blockstate((ctx, prov) -> prov.simpleBlock(ctx.getEntry(), AssetLookup.partialBaseModel(ctx, prov)))
|
||||
.item()
|
||||
@ -38,7 +38,7 @@ public class AllBlocksNew {
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<SchematicTableBlock> SCHEMATIC_TABLE =
|
||||
REGISTRATE.createBlock("schematic_table", SchematicTableBlock::new)
|
||||
REGISTRATE.block("schematic_table", SchematicTableBlock::new)
|
||||
.initialProperties(() -> Blocks.LECTERN)
|
||||
.blockstate((ctx, prov) -> prov.horizontalBlock(ctx.getEntry(), prov.models()
|
||||
.getExistingFile(ctx.getId()), 0))
|
||||
@ -49,13 +49,13 @@ public class AllBlocksNew {
|
||||
REGISTRATE.startSection(Sections.KINETICS);
|
||||
}
|
||||
|
||||
public static final BlockEntry<ShaftBlock> SHAFT = REGISTRATE.createBlock("shaft", ShaftBlock::new)
|
||||
public static final BlockEntry<ShaftBlock> SHAFT = REGISTRATE.block("shaft", ShaftBlock::new)
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.blockstate(BlockStateGen.axisBlockProvider(false))
|
||||
.simpleItem()
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<CogWheelBlock> COGWHEEL = REGISTRATE.createBlock("cogwheel", CogWheelBlock::small)
|
||||
public static final BlockEntry<CogWheelBlock> COGWHEEL = REGISTRATE.block("cogwheel", CogWheelBlock::small)
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.properties(p -> p.sound(SoundType.WOOD))
|
||||
.blockstate(BlockStateGen.axisBlockProvider(false))
|
||||
@ -64,7 +64,7 @@ public class AllBlocksNew {
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<CogWheelBlock> LARGE_COGWHEEL =
|
||||
REGISTRATE.createBlock("large_cogwheel", CogWheelBlock::large)
|
||||
REGISTRATE.block("large_cogwheel", CogWheelBlock::large)
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.properties(p -> p.sound(SoundType.WOOD))
|
||||
.blockstate(BlockStateGen.axisBlockProvider(false))
|
||||
@ -73,7 +73,7 @@ public class AllBlocksNew {
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<EncasedShaftBlock> ENCASED_SHAFT =
|
||||
REGISTRATE.createBlock("encased_shaft", EncasedShaftBlock::new)
|
||||
REGISTRATE.block("encased_shaft", EncasedShaftBlock::new)
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.blockstate(BlockStateGen.axisBlockProvider(true))
|
||||
.item()
|
||||
@ -81,7 +81,7 @@ public class AllBlocksNew {
|
||||
.build()
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<GearboxBlock> GEARBOX = REGISTRATE.createBlock("gearbox", GearboxBlock::new)
|
||||
public static final BlockEntry<GearboxBlock> GEARBOX = REGISTRATE.block("gearbox", GearboxBlock::new)
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.blockstate(BlockStateGen.axisBlockProvider(true))
|
||||
.item()
|
||||
@ -89,7 +89,7 @@ public class AllBlocksNew {
|
||||
.build()
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<ClutchBlock> CLUTCH = REGISTRATE.createBlock("clutch", ClutchBlock::new)
|
||||
public static final BlockEntry<ClutchBlock> CLUTCH = REGISTRATE.block("clutch", ClutchBlock::new)
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p)))
|
||||
.item()
|
||||
@ -97,7 +97,7 @@ public class AllBlocksNew {
|
||||
.build()
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<GearshiftBlock> GEARSHIFT = REGISTRATE.createBlock("gearshift", GearshiftBlock::new)
|
||||
public static final BlockEntry<GearshiftBlock> GEARSHIFT = REGISTRATE.block("gearshift", GearshiftBlock::new)
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p)))
|
||||
.item()
|
||||
|
@ -1,70 +0,0 @@
|
||||
package com.simibubi.create.foundation.registrate;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.block.connected.CTModel;
|
||||
import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour;
|
||||
import com.tterrag.registrate.AbstractRegistrate;
|
||||
import com.tterrag.registrate.builders.BlockBuilder;
|
||||
import com.tterrag.registrate.builders.BuilderCallback;
|
||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||
import com.tterrag.registrate.util.nullness.NonNullConsumer;
|
||||
import com.tterrag.registrate.util.nullness.NonNullFunction;
|
||||
import com.tterrag.registrate.util.nullness.NonNullSupplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Block.Properties;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
|
||||
public class CreateBlockBuilder<T extends Block, P> extends BlockBuilder<T, P> {
|
||||
|
||||
private List<NonNullConsumer<BlockEntry<T>>> registerCallbacks;
|
||||
|
||||
protected CreateBlockBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback,
|
||||
NonNullFunction<Properties, T> factory, NonNullSupplier<Properties> initialProperties) {
|
||||
super(owner, parent, name, callback, factory, initialProperties);
|
||||
registerCallbacks = new LinkedList<>();
|
||||
}
|
||||
|
||||
public static <T extends Block, P> CreateBlockBuilder<T, P> create(AbstractRegistrate<?> owner, P parent,
|
||||
String name, BuilderCallback callback, NonNullFunction<Block.Properties, T> factory, Material material) {
|
||||
return (CreateBlockBuilder<T, P>) new CreateBlockBuilder<>(owner, parent, name, callback, factory,
|
||||
() -> Block.Properties.create(material)).defaultBlockstate()
|
||||
.defaultLoot()
|
||||
.defaultLang();
|
||||
}
|
||||
|
||||
public CreateBlockBuilder<T, P> connectedTextures(ConnectedTextureBehaviour behaviour) {
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> registerConnectedTexture(behaviour));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreateBlockBuilder<T, P> onRegister(NonNullConsumer<BlockEntry<T>> callback) {
|
||||
registerCallbacks.add(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntry<T> register() {
|
||||
BlockEntry<T> register = super.register();
|
||||
registerCallbacks.forEach(func -> func.accept(register));
|
||||
return register;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void registerConnectedTexture(ConnectedTextureBehaviour behaviour) {
|
||||
registerModelSwap(model -> new CTModel(model, behaviour));
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void registerModelSwap(NonNullFunction<IBakedModel, ? extends IBakedModel> modelFunc) {
|
||||
onRegister(entry -> CreateClient.getCustomBlockModels().register(entry, modelFunc));
|
||||
}
|
||||
|
||||
}
|
@ -11,13 +11,12 @@ import com.tterrag.registrate.util.entry.RegistryEntry;
|
||||
import com.tterrag.registrate.util.nullness.NonNullFunction;
|
||||
import com.tterrag.registrate.util.nullness.NonNullSupplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
public class CreateRegistrateBase<C extends AbstractRegistrate<C>> extends AbstractRegistrate<C> {
|
||||
public class CreateRegistrateBase<S extends CreateRegistrateBase<S>> extends AbstractRegistrate<S> {
|
||||
|
||||
protected CreateRegistrateBase(String modid, NonNullSupplier<ItemGroup> creativeTab) {
|
||||
super(modid);
|
||||
@ -25,6 +24,8 @@ public class CreateRegistrateBase<C extends AbstractRegistrate<C>> extends Abstr
|
||||
.getModEventBus());
|
||||
itemGroup(creativeTab);
|
||||
}
|
||||
|
||||
/* Section Tracking */
|
||||
|
||||
private static Map<RegistryEntry<?>, Sections> sectionLookup = new IdentityHashMap<>();
|
||||
private Sections section;
|
||||
@ -39,24 +40,13 @@ public class CreateRegistrateBase<C extends AbstractRegistrate<C>> extends Abstr
|
||||
|
||||
@Override
|
||||
protected <R extends IForgeRegistryEntry<R>, T extends R> RegistryEntry<T> accept(String name,
|
||||
Class<? super R> type, Builder<R, T, ?, ?> builder, NonNullSupplier<? extends T> creator) {
|
||||
RegistryEntry<T> ret = super.accept(name, type, builder, creator);
|
||||
Class<? super R> type, Builder<R, T, ?, ?> builder, NonNullSupplier<? extends T> creator,
|
||||
NonNullFunction<RegistryObject<T>, ? extends RegistryEntry<T>> entryFactory) {
|
||||
RegistryEntry<T> ret = super.accept(name, type, builder, creator, entryFactory);
|
||||
sectionLookup.put(ret, currentSection());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Block, P> CreateBlockBuilder<T, P> createBlock(String name,
|
||||
NonNullFunction<Block.Properties, T> factory) {
|
||||
return (CreateBlockBuilder<T, P>) super.block(name, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Block, P> CreateBlockBuilder<T, P> block(P parent, String name,
|
||||
NonNullFunction<Block.Properties, T> factory, Material material) {
|
||||
return CreateBlockBuilder.create(this, parent, name, this::accept, factory, material);
|
||||
}
|
||||
|
||||
public void addToSection(RegistryEntry<?> entry, Sections section) {
|
||||
sectionLookup.put(entry, section);
|
||||
}
|
||||
@ -74,5 +64,4 @@ public class CreateRegistrateBase<C extends AbstractRegistrate<C>> extends Abstr
|
||||
.findFirst()
|
||||
.orElse(Sections.UNASSIGNED);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class AllPaletteBlocks {
|
||||
// Create stone variants
|
||||
|
||||
public static final BlockEntry<SandBlock> LIMESAND =
|
||||
REGISTRATE.createBlock("limesand", p -> new SandBlock(0xD7D7C7, p))
|
||||
REGISTRATE.block("limesand", p -> new SandBlock(0xD7D7C7, p))
|
||||
.initialProperties(() -> Blocks.SAND)
|
||||
.blockstate(palettesCubeAll())
|
||||
.register();
|
||||
@ -103,7 +103,7 @@ public class AllPaletteBlocks {
|
||||
.register());
|
||||
|
||||
public static final BlockEntry<ScoriaBlock> NATURAL_SCORIA =
|
||||
REGISTRATE.createBlock("natural_scoria", ScoriaBlock::new)
|
||||
REGISTRATE.block("natural_scoria", ScoriaBlock::new)
|
||||
.initialProperties(() -> Blocks.ANDESITE)
|
||||
.blockstate(palettesCubeAll())
|
||||
.simpleItem()
|
||||
|
@ -4,6 +4,8 @@ import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllCTs;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.block.connected.CTModel;
|
||||
import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour;
|
||||
import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour;
|
||||
import com.simibubi.create.foundation.registrate.CreateRegistrateBase;
|
||||
@ -14,12 +16,15 @@ import com.tterrag.registrate.util.NonNullLazyValue;
|
||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||
import com.tterrag.registrate.util.nullness.NonNullFunction;
|
||||
import com.tterrag.registrate.util.nullness.NonNullSupplier;
|
||||
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Block.Properties;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
|
||||
public class PalettesRegistrate extends CreateRegistrateBase<PalettesRegistrate> {
|
||||
|
||||
@ -72,7 +77,8 @@ public class PalettesRegistrate extends CreateRegistrateBase<PalettesRegistrate>
|
||||
|
||||
public BlockEntry<WindowBlock> windowBlock(String name, AllCTs ct, Supplier<Supplier<RenderType>> renderType,
|
||||
NonNullFunction<String, ResourceLocation> endTexture, NonNullFunction<String, ResourceLocation> sideTexture) {
|
||||
return createBlock(name, WindowBlock::new).connectedTextures(new HorizontalCTBehaviour(ct.get()))
|
||||
return block(name, WindowBlock::new)
|
||||
.transform(connectedTextures(new HorizontalCTBehaviour(ct.get())))
|
||||
.addLayer(renderType)
|
||||
.initialProperties(() -> Blocks.GLASS)
|
||||
.blockstate((c, p) -> p.simpleBlock(c.get(), p.models()
|
||||
@ -82,7 +88,8 @@ public class PalettesRegistrate extends CreateRegistrateBase<PalettesRegistrate>
|
||||
}
|
||||
|
||||
public BlockEntry<ConnectedGlassBlock> framedGlass(String name, ConnectedTextureBehaviour behaviour) {
|
||||
return createBlock(name, ConnectedGlassBlock::new).connectedTextures(behaviour)
|
||||
return block(name, ConnectedGlassBlock::new)
|
||||
.transform(connectedTextures(behaviour))
|
||||
.addLayer(() -> RenderType::getTranslucent)
|
||||
.initialProperties(() -> Blocks.GLASS)
|
||||
.blockstate((c, p) -> BlockStateGen.cubeAll(c, p, "palettes/", "framed_glass"))
|
||||
@ -90,7 +97,13 @@ public class PalettesRegistrate extends CreateRegistrateBase<PalettesRegistrate>
|
||||
.model((c, p) -> p.cubeColumn(c.getName(), p.modLoc("block/palettes/" + c.getName()),
|
||||
p.modLoc("block/palettes/framed_glass")))
|
||||
.build()
|
||||
.register();
|
||||
.register();
|
||||
}
|
||||
|
||||
private <T extends Block> NonNullUnaryOperator<BlockBuilder<T, PalettesRegistrate>> connectedTextures(
|
||||
ConnectedTextureBehaviour behavior) {
|
||||
return b -> b.onRegister(entry -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () ->
|
||||
CreateClient.getCustomBlockModels()
|
||||
.register(entry.delegate, model -> new CTModel(model, behavior))));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user