mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-18 19:29:32 +00:00
Add more methods to the item registry adapter that make use of default props
Also make default props parameter optional and add some missing javadocs
This commit is contained in:
1 parent
fe0f3297d9
commit
eafa8da4b7
6 files changed
+76
No files matched your search
@@ -23,10 +23,12 @@ import java.util.function.Supplier;
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class BlockRegistryAdapter extends EnumRegistryAdapter<Block> {
|
||||
|
||||
/** @inheritDoc */
|
||||
public BlockRegistryAdapter(IForgeRegistry<Block> registry) {
|
||||
super(registry);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public BlockRegistryAdapter(IForgeRegistry<Block> registry, String modid) {
|
||||
super(registry, modid);
|
||||
}
|
||||
|
||||
+2
@@ -7,10 +7,12 @@ import net.minecraftforge.fml.network.IContainerFactory;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
public class ContainerTypeRegistryAdapter extends RegistryAdapter<ContainerType<?>> {
|
||||
/** @inheritDoc */
|
||||
public ContainerTypeRegistryAdapter(IForgeRegistry<ContainerType<?>> registry, String modId) {
|
||||
super(registry, modId);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public ContainerTypeRegistryAdapter(IForgeRegistry<ContainerType<?>> registry) {
|
||||
super(registry);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,12 @@ import net.minecraftforge.registries.IForgeRegistry;
|
||||
* Registry adapter for registering entity types
|
||||
*/
|
||||
public class EntityTypeRegistryAdapter extends RegistryAdapter<EntityType<?>> {
|
||||
/** @inheritDoc */
|
||||
public EntityTypeRegistryAdapter(IForgeRegistry<EntityType<?>> registry, String modId) {
|
||||
super(registry, modId);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public EntityTypeRegistryAdapter(IForgeRegistry<EntityType<?>> registry) {
|
||||
super(registry);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ import java.util.function.Function;
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class EnumRegistryAdapter<T extends ForgeRegistryEntry<T>> extends RegistryAdapter<T> {
|
||||
|
||||
/** @inheritDoc */
|
||||
public EnumRegistryAdapter(IForgeRegistry<T> registry) {
|
||||
super(registry);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public EnumRegistryAdapter(IForgeRegistry<T> registry, String modId) {
|
||||
super(registry, modId);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ import java.util.function.Function;
|
||||
* Registry adapter for registering fluids
|
||||
*/
|
||||
public class FluidRegistryAdapter extends RegistryAdapter<Fluid> {
|
||||
/** @inheritDoc */
|
||||
public FluidRegistryAdapter(IForgeRegistry<Fluid> registry) {
|
||||
super(registry);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public FluidRegistryAdapter(IForgeRegistry<Fluid> registry, String modId) {
|
||||
super(registry, modId);
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@ import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.BucketItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Item.Properties;
|
||||
import net.minecraft.item.SpawnEggItem;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import slimeknights.mantle.item.BlockTooltipItem;
|
||||
import slimeknights.mantle.item.TooltipItem;
|
||||
import slimeknights.mantle.registration.ItemProperties;
|
||||
import slimeknights.mantle.registration.object.BuildingBlockObject;
|
||||
import slimeknights.mantle.registration.object.EnumObject;
|
||||
@@ -16,6 +18,8 @@ import slimeknights.mantle.registration.object.FenceBuildingBlockObject;
|
||||
import slimeknights.mantle.registration.object.WallBuildingBlockObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -25,6 +29,19 @@ import java.util.function.Supplier;
|
||||
public class ItemRegistryAdapter extends EnumRegistryAdapter<Item> {
|
||||
private final Item.Properties defaultProps;
|
||||
|
||||
/**
|
||||
* Registers a new item registry adapter with default mod ID and item properties
|
||||
* @param registry Item registry instance
|
||||
*/
|
||||
public ItemRegistryAdapter(IForgeRegistry<Item> registry) {
|
||||
this(registry, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new item registry adapter with default mod ID
|
||||
* @param registry Item registry instance
|
||||
* @param defaultProps Default item properties
|
||||
*/
|
||||
public ItemRegistryAdapter(IForgeRegistry<Item> registry, @Nullable Item.Properties defaultProps) {
|
||||
super(registry);
|
||||
if (defaultProps == null) {
|
||||
@@ -34,6 +51,12 @@ public class ItemRegistryAdapter extends EnumRegistryAdapter<Item> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new item registry adapter with a specific mod ID
|
||||
* @param registry Item registry instance
|
||||
* @param modid Mod ID override
|
||||
* @param defaultProps Default item properties
|
||||
*/
|
||||
public ItemRegistryAdapter(IForgeRegistry<Item> registry, String modid, @Nullable Item.Properties defaultProps) {
|
||||
super(registry, modid);
|
||||
if (defaultProps == null) {
|
||||
@@ -43,6 +66,38 @@ public class ItemRegistryAdapter extends EnumRegistryAdapter<Item> {
|
||||
}
|
||||
}
|
||||
|
||||
/* Item helpers */
|
||||
|
||||
/**
|
||||
* Registers a generic tooltip item using the default props
|
||||
* @param name Item name
|
||||
* @return Registered item
|
||||
*/
|
||||
public TooltipItem register(String name) {
|
||||
return register(defaultProps, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a generic tooltip item from the given props
|
||||
* @param props Item properties
|
||||
* @param name Item name
|
||||
* @return Registered item
|
||||
*/
|
||||
public TooltipItem register(Item.Properties props, String name) {
|
||||
return register(new TooltipItem(props), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an item with the default properties
|
||||
* @param constructor Item constructor
|
||||
* @param name Item name
|
||||
* @param <T> Item type
|
||||
* @return Registered item
|
||||
*/
|
||||
public <T extends Item> T register(Function<Properties,T> constructor, String name) {
|
||||
return register(constructor.apply(defaultProps), name);
|
||||
}
|
||||
|
||||
|
||||
/* Standard block items */
|
||||
|
||||
@@ -60,6 +115,17 @@ public class ItemRegistryAdapter extends EnumRegistryAdapter<Item> {
|
||||
return registerBlockItem(block, defaultProps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a block item with default properties using the given constructor
|
||||
* @param block Block instance
|
||||
* @param constructor Constructor
|
||||
* @param <T> Result block item type
|
||||
* @return Registered block item
|
||||
*/
|
||||
public <T extends BlockItem> T registerBlockItem(Block block, BiFunction<Block,Properties,T> constructor) {
|
||||
return register(constructor.apply(block, defaultProps), block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as the variant without ItemGroup, but registers it for the given itemgroup.
|
||||
* @param block The block you want to have an item for
|
||||
|
||||
Reference in new issue
Block a user