77import net .minecraft .core .registries .BuiltInRegistries ;
88import net .minecraft .core .registries .Registries ;
99import net .minecraft .network .chat .Component ;
10+ import net .minecraft .resources .Identifier ;
1011import net .minecraft .resources .ResourceKey ;
1112import net .minecraft .world .item .ItemStack ;
1213import net .minecraft .world .item .Items ;
13- import net .minecraft .world .item .component .CustomModelData ;
1414import net .minecraft .world .level .block .Block ;
1515import net .minecraft .world .level .block .Blocks ;
1616import net .minecraft .world .level .block .state .BlockState ;
@@ -37,6 +37,7 @@ public class ParallelBlockRegistry {
3737 private final HashMap <BlockState , Integer > availableStates ;
3838
3939 private final HashMap <Integer , List <ItemStack >> dropMap ;
40+ private final HashMap <Integer , BlockState > placeMap ;
4041
4142 private boolean frozen = false ;
4243
@@ -56,6 +57,7 @@ private ParallelBlockRegistry() throws RuntimeException, NoSuchMethodException {
5657 stateMap = new HashMap <>();
5758 availableStates = new HashMap <>();
5859 dropMap = new HashMap <>();
60+ placeMap = new HashMap <>();
5961
6062 // TODO: Fill available states
6163 for (BlockState state : Blocks .NOTE_BLOCK .getStateDefinition ().getPossibleStates ()) {
@@ -111,18 +113,18 @@ public void freeze() {
111113 return null ;
112114 }
113115
114- public boolean registerBlock (ResourceKey <@ NotNull Block > key , Block block , BlockState targetBlockstate , Component name , float customModelData ) {
115- ItemStack stack = Items .PAPER .getDefaultInstance ();
116+ public boolean registerBlock (ResourceKey <@ NotNull Block > key , Block block , BlockState targetBlockstate , Component name ) {
117+ ItemStack stack = Items .DIRT .getDefaultInstance ();
116118
117119 stack .applyComponentsAndValidate (
118120 DataComponentPatch .builder ()
119- .set (TypedDataComponent .createUnchecked (DataComponents .CUSTOM_MODEL_DATA , new CustomModelData ( List . of ( customModelData ), List . of (), List . of (), List . of () )))
121+ .set (TypedDataComponent .createUnchecked (DataComponents .ITEM_MODEL , Identifier . fromNamespaceAndPath ( "minecraft" , "sand" )))
120122 .set (TypedDataComponent .createUnchecked (DataComponents .ITEM_NAME , name )).build ());
121123
122- return registerBlock (key , block , targetBlockstate , List .of (stack ));
124+ return registerBlock (key , block , targetBlockstate , List .of (stack ), stack );
123125 }
124126
125- public boolean registerBlock (ResourceKey <@ NotNull Block > key , Block block , BlockState targetBlockstate , List <ItemStack > item ) {
127+ public boolean registerBlock (ResourceKey <@ NotNull Block > key , Block block , BlockState targetBlockstate , List <ItemStack > item , ItemStack placeBlock ) {
126128 if (frozen ) return false ;
127129
128130 if (!availableStates .containsKey (targetBlockstate )) throw new IllegalStateException ("Block state is already used or does not exist" );
@@ -136,6 +138,7 @@ public boolean registerBlock(ResourceKey<@NotNull Block> key, Block block, Block
136138
137139 stateMap .put (Block .BLOCK_STATE_REGISTRY .size (), stateId ); // Map the new block state to an unused state
138140 dropMap .put (Block .BLOCK_STATE_REGISTRY .size (), item );
141+ placeMap .put (ItemStack .hashItemAndComponents (placeBlock ), blockState );
139142
140143 Block .BLOCK_STATE_REGISTRY .add (blockState );
141144
@@ -158,4 +161,9 @@ public Integer getMappedState(int state) {
158161 public List <ItemStack > getDrops (int state ) {
159162 return dropMap .get (state );
160163 }
164+
165+ @ Nullable
166+ public BlockState getBlockState (@ NotNull ItemStack item ) {
167+ return placeMap .get (ItemStack .hashItemAndComponents (item ));
168+ }
161169}
0 commit comments