Skip to content

Commit

Permalink
RegistryUtil changes
Browse files Browse the repository at this point in the history
  • Loading branch information
melontini committed Jun 30, 2023
1 parent 1d844b0 commit 7236ecd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -75,6 +77,7 @@ public static <T extends Item> T asItem(Block block) {
return createItem(true, id, supplier);
}

@Contract("false, _, _ -> null")
public static @Nullable <T extends Item> T createItem(boolean shouldRegister, Identifier id, Supplier<T> supplier) {
if (shouldRegister) {
T item = supplier.get();
Expand Down Expand Up @@ -104,6 +107,7 @@ public static <T extends Entity> EntityType<T> createEntityType(Identifier id, E
return createBlock(true, id, supplier);
}

@Contract("false, _, _ -> null")
public static @Nullable <T extends Block> T createBlock(boolean shouldRegister, Identifier id, Supplier<T> supplier) {
if (shouldRegister) {
T block = supplier.get();
Expand All @@ -127,4 +131,16 @@ public static <T extends BlockEntity> BlockEntityType<T> createBlockEntity(Ident
}
return null;
}

public static <T extends ScreenHandler> ScreenHandlerType<T> createScreenHandler(Identifier id, Supplier<ScreenHandlerType.Factory<T>> factory) {
return createScreenHandler(true, id, factory);
}

@Contract("false, _, _ -> null")
public static <T extends ScreenHandler> ScreenHandlerType<T> createScreenHandler(boolean shouldRegister, Identifier id, Supplier<ScreenHandlerType.Factory<T>> factory) {
if (shouldRegister) {
Registry.register(Registry.SCREEN_HANDLER, id, new ScreenHandlerType<>(factory.get()));
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
accessWidener v2 named

transitive-accessible class net/minecraft/screen/ScreenHandlerType$Factory
transitive-accessible class net/minecraft/village/raid/Raid$Member
transitive-accessible class net/minecraft/recipe/Ingredient$TagEntry
transitive-accessible class net/minecraft/recipe/Ingredient$StackEntry
transitive-accessible class net/minecraft/recipe/Ingredient$Entry
transitive-accessible class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory

transitive-accessible method net/minecraft/screen/ScreenHandlerType <init> (Lnet/minecraft/screen/ScreenHandlerType$Factory;)V
transitive-accessible method net/minecraft/client/gui/screen/Screen renderTooltipFromComponents (Lnet/minecraft/client/util/math/MatrixStack;Ljava/util/List;II)V
transitive-accessible method net/minecraft/entity/projectile/ProjectileEntity <init> (Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V
transitive-accessible method net/minecraft/entity/FallingBlockEntity <init> (Lnet/minecraft/world/World;DDDLnet/minecraft/block/BlockState;)V
Expand Down

0 comments on commit 7236ecd

Please sign in to comment.