Add helper to registry adapters to copy name from another object

This commit is contained in:
KnightMiner committed 2020-07-27 21:44:57 -05:00
1 parent ae8bba0162
commit 812bbe23fd
3 files changed
+28 -4

No files matched your search

@@ -1,5 +1,6 @@
package slimeknights.mantle.registration.adapter;
import net.minecraft.block.AbstractBlock.Properties;
import net.minecraft.block.Block;
import net.minecraft.block.FenceBlock;
import net.minecraft.block.FlowingFluidBlock;
@@ -13,6 +14,7 @@ import slimeknights.mantle.registration.object.BuildingBlockObject;
import slimeknights.mantle.registration.object.FenceBuildingBlockObject;
import slimeknights.mantle.registration.object.WallBuildingBlockObject;
import java.util.function.Function;
import java.util.function.Supplier;
/**
@@ -29,6 +31,17 @@ public class BlockRegistryAdapter extends EnumRegistryAdapter<Block> {
super(registry, modid);
}
/**
* Registers a block override based on the given block
* @param constructor Override constructor
* @param base Base block
* @param <T> Block type
* @return Registered block
*/
public <T extends Block> T registerOverride(Function<Properties, T> constructor, Block base) {
return register(constructor.apply(Block.Properties.from(base)), base);
}
/* Building */
/**
@@ -16,7 +16,6 @@ import slimeknights.mantle.registration.object.FenceBuildingBlockObject;
import slimeknights.mantle.registration.object.WallBuildingBlockObject;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.function.Supplier;
/**
@@ -67,7 +66,7 @@ public class ItemRegistryAdapter extends EnumRegistryAdapter<Item> {
* @param props Item properties for the block
*/
public BlockItem registerBlockItem(Block block, Item.Properties props) {
return register(new BlockTooltipItem(block, props), Objects.requireNonNull(block.getRegistryName()));
return register(new BlockTooltipItem(block, props), block);
}
/**
@@ -76,7 +75,7 @@ public class ItemRegistryAdapter extends EnumRegistryAdapter<Item> {
* @return Registered item block, should be the same as teh one passed in.
*/
public <T extends BlockItem> T registerBlockItem(T blockItem) {
return register(blockItem, Objects.requireNonNull(blockItem.getBlock().getRegistryName()));
return register(blockItem, blockItem.getBlock());
}
/* Block wrappers */
@@ -6,6 +6,8 @@ import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import java.util.Objects;
/**
* A convenience wrapper for forge registries, to be used in combination with the {@link net.minecraftforge.event.RegistryEvent.Register} event.
* Simply put it allows you to register things by passing (thing, name) instead of having to set the name inline.
@@ -48,11 +50,21 @@ public class RegistryAdapter<T extends IForgeRegistryEntry<T>> {
* @param name Registry name
* @return Registry entry
*/
@SuppressWarnings("UnusedReturnValue")
public <I extends T> I register(I entry, String name) {
return this.register(entry, this.getResource(name));
}
/**
* Registers an entry using the name from another entry
* @param entry Entry to register
* @param name Entry name to copy
* @param <I> Value type
* @return Registered entry
*/
public <I extends T> I register(I entry, IForgeRegistryEntry<?> name) {
return this.register(entry, Objects.requireNonNull(name.getRegistryName()));
}
/**
* General purpose backup registration method. In case you want to set a very specific resource location.
* You should probably use the special purpose methods instead of this.