Skip to content

Instantly share code, notes, and snippets.

@Drullkus
Created December 23, 2019 19:22
Show Gist options
  • Save Drullkus/c3374b41dfc6fa6c307daaec0eb924fa to your computer and use it in GitHub Desktop.
Save Drullkus/c3374b41dfc6fa6c307daaec0eb924fa to your computer and use it in GitHub Desktop.
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.GlazedTerracottaBlock;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
// Example implementation using Deferred Registries on 1.14
public class BasicDeferredRegistry {
public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, "mod_id");
public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, "mod_id");
public static final RegistryObject<GlazedTerracottaBlock> newBlock = BLOCKS.register("aNewBlock", () -> new GlazedTerracottaBlock(Block.Properties.create(Material.CAKE)));
public static final RegistryObject<? extends Block> anonBlock = BLOCKS.register("aAnonymousBeaconBase",
() -> new Block(Block.Properties.create(Material.ANVIL, MaterialColor.DIAMOND)) {
@Override
public boolean isBeaconBase(BlockState state, IWorldReader world, BlockPos pos, BlockPos beacon) {
return true;
}
}
);
public static final RegistryObject<BlockItem> newItem = ITEMS.register("aNewItem", () -> new BlockItem(newBlock.get(), new Item.Properties()));
public static void registerAll() {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
BLOCKS.register(bus);
ITEMS.register(bus);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment