mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-27 15:23:12 +00:00
Allow an ItemObject name to be fetched before registry events fire
Also remove a few constructors provided because of "what if they are needed", as I really doubt anyone will be extending this system. They can make a PR if they need them later
This commit is contained in:
1 parent
9c5b8fb5af
commit
cbb0a52c18
4 files changed
+49
-36
No files matched your search
@@ -19,19 +19,31 @@ public class BuildingBlockObject extends ItemObject<Block> {
|
||||
private final Supplier<? extends StairsBlock> stairs;
|
||||
|
||||
/**
|
||||
* Creates a new object from a set of suppliers
|
||||
* Standard supplier method, expects the supplier to have resolved in order to call registry name.
|
||||
* @param block Base block
|
||||
* @param slab Slab block
|
||||
* @param stairs Stairs block
|
||||
*/
|
||||
public BuildingBlockObject(Supplier<? extends Block> block, Supplier<? extends SlabBlock> slab, Supplier<? extends StairsBlock> stairs) {
|
||||
protected BuildingBlockObject(Supplier<? extends Block> block, Supplier<? extends SlabBlock> slab, Supplier<? extends StairsBlock> stairs) {
|
||||
super(block);
|
||||
this.slab = slab;
|
||||
this.stairs = stairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new object from another building block object
|
||||
* Creates a new object from a ItemObject. Avoids an extra supplier wrapper
|
||||
* @param block Base block
|
||||
* @param slab Slab block
|
||||
* @param stairs Stairs block
|
||||
*/
|
||||
public BuildingBlockObject(ItemObject<? extends Block> block, Supplier<? extends SlabBlock> slab, Supplier<? extends StairsBlock> stairs) {
|
||||
super(block);
|
||||
this.slab = slab;
|
||||
this.stairs = stairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new object from another building block object, intended to be used in subclasses to copy properties
|
||||
* @param object Object to copy
|
||||
*/
|
||||
protected BuildingBlockObject(BuildingBlockObject object) {
|
||||
|
||||
+1
-16
@@ -2,8 +2,6 @@ package slimeknights.mantle.registration.object;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.FenceBlock;
|
||||
import net.minecraft.block.SlabBlock;
|
||||
import net.minecraft.block.StairsBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -16,20 +14,7 @@ public class FenceBuildingBlockObject extends BuildingBlockObject {
|
||||
private final Supplier<? extends FenceBlock> fence;
|
||||
|
||||
/**
|
||||
* Creates a new building block object with all parameters
|
||||
* @param block Block object
|
||||
* @param slab Slab object
|
||||
* @param stairs Stairs object
|
||||
* @param fence Fence object
|
||||
*/
|
||||
public FenceBuildingBlockObject(Supplier<? extends Block> block, Supplier<? extends SlabBlock> slab,
|
||||
Supplier<? extends StairsBlock> stairs, Supplier<? extends FenceBlock> fence) {
|
||||
super(block, slab, stairs);
|
||||
this.fence = fence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new object from a building block object plus a fence
|
||||
* Creates a new object from a building block object plus a fence.
|
||||
* @param object Previous building block object
|
||||
* @param fence Fence object
|
||||
*/
|
||||
|
||||
@@ -4,8 +4,10 @@ import lombok.AllArgsConstructor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.IItemProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -17,6 +19,35 @@ import java.util.function.Supplier;
|
||||
public class ItemObject<I extends IForgeRegistryEntry<? super I> & IItemProvider> implements Supplier<I>, IItemProvider {
|
||||
/** Supplier to the registry entry */
|
||||
private final Supplier<? extends I> entry;
|
||||
/** Supplier to the registry name for this entry, allows fetching the name before the entry resolves if registry object is used */
|
||||
private final Supplier<ResourceLocation> name;
|
||||
|
||||
/**
|
||||
* Creates a new item object from a supplier instance. Registry name will be fetched from the supplier entry, so the entry must be present to fetch
|
||||
* @param supplier Supplier instance
|
||||
*/
|
||||
public ItemObject(Supplier<? extends I> supplier) {
|
||||
this.entry = supplier;
|
||||
this.name = () -> Objects.requireNonNull(supplier.get().getRegistryName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new item object using the given registry object. This variant can resolve its name before the registry object entry resolves
|
||||
* @param object Object base
|
||||
*/
|
||||
public ItemObject(RegistryObject<? extends I> object) {
|
||||
this.entry = object;
|
||||
this.name = object::getId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new item object using another item object. Intended to be used in a subclass to avoid an extra wrapper
|
||||
* @param object Object base
|
||||
*/
|
||||
protected ItemObject(ItemObject<? extends I> object) {
|
||||
this.entry = object.entry;
|
||||
this.name = object.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public I get() {
|
||||
@@ -33,6 +64,6 @@ public class ItemObject<I extends IForgeRegistryEntry<? super I> & IItemProvider
|
||||
* @return Resource location for the given item
|
||||
*/
|
||||
public ResourceLocation getRegistryName() {
|
||||
return Objects.requireNonNull(item.get().getRegistryName());
|
||||
return name.get();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package slimeknights.mantle.registration.object;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SlabBlock;
|
||||
import net.minecraft.block.StairsBlock;
|
||||
import net.minecraft.block.WallBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -16,20 +14,7 @@ public class WallBuildingBlockObject extends BuildingBlockObject {
|
||||
private final Supplier<? extends WallBlock> wall;
|
||||
|
||||
/**
|
||||
* Creates a new building block object with all parameters
|
||||
* @param block Block supplier
|
||||
* @param slab Slab supplier
|
||||
* @param stairs Stairs supplier
|
||||
* @param wall Wall supplier
|
||||
*/
|
||||
public WallBuildingBlockObject(Supplier<? extends Block> block, Supplier<? extends SlabBlock> slab,
|
||||
Supplier<? extends StairsBlock> stairs, Supplier<? extends WallBlock> wall) {
|
||||
super(block, slab, stairs);
|
||||
this.wall = wall;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new object from a building block object plus a wall
|
||||
* Creates a new object from a building block object plus a wall.
|
||||
* @param object Previous building block object
|
||||
* @param wall Wall object
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user