88import com .ldtteam .structurize .placement .handlers .placement .IPlacementHandler ;
99import com .ldtteam .structurize .placement .handlers .placement .PlacementHandlers ;
1010import com .ldtteam .structurize .placement .structure .IStructureHandler ;
11+ import com .ldtteam .structurize .util .BlockInfo ;
1112import com .ldtteam .structurize .util .BlockUtils ;
1213import com .ldtteam .structurize .util .ChangeStorage ;
1314import net .minecraft .core .BlockPos ;
@@ -174,7 +175,7 @@ public StructurePhasePlacementResult executeStructureStep(
174175 result = handleEntitySpawn (world , worldPos , localPos , storage , false );
175176 break ;
176177 default :
177- result = handleBlockPlacement (world , worldPos , localPos , storage , localState , handler .getBluePrint ().getTileEntityData (worldPos , localPos ));
178+ result = handleBlockPlacement (world , worldPos , storage , new BlockInfo ( localPos , localState , handler .getBluePrint ().getTileEntityData (worldPos , localPos ) ));
178179 }
179180 count ++;
180181
@@ -213,19 +214,19 @@ public StructurePhasePlacementResult executeStructureStep(
213214 * When we extract this into another mod, we have to override the method.
214215 * @param world the world.
215216 * @param worldPos the world position.
216- * @param localPos the local pos
217217 * @param storage the change storage.
218- * @param localState the local state.
219- * @param tileEntityData the tileEntity.
218+ * @param blockInfo the tileEntity.
220219 */
221220 public BlockPlacementResult handleBlockPlacement (
222221 final Level world ,
223222 final BlockPos worldPos ,
224- final BlockPos localPos ,
225223 final ChangeStorage storage ,
226- BlockState localState ,
227- CompoundTag tileEntityData )
224+ final BlockInfo blockInfo )
228225 {
226+ BlockState localState = blockInfo .getState ();
227+ CompoundTag tileEntityData = blockInfo .getTileEntityData ();
228+ final BlockPos localPos = blockInfo .getPos ();
229+
229230 final BlockState worldState = world .getBlockState (worldPos );
230231 boolean sameBlockInWorld = false ;
231232 if (worldState .getBlock () == localState .getBlock () && tileEntityData == null )
@@ -248,16 +249,6 @@ public BlockPlacementResult handleBlockPlacement(
248249 return entityResult ;
249250 }
250251
251- BlockEntity worldEntity = null ;
252- if (tileEntityData != null )
253- {
254- worldEntity = world .getBlockEntity (worldPos );
255- }
256-
257- if (localState .getBlock () == ModBlocks .blockSolidSubstitution .get () && handler .fancyPlacement ())
258- {
259- localState = this .handler .getSolidBlockForPos (worldPos , handler .getBluePrint ().getRawBlockStateFunction ().compose (handler ::getStructurePosFromWorld ));
260- }
261252 if (localState .getBlock () == ModBlocks .blockTagSubstitution .get () && handler .fancyPlacement ())
262253 {
263254 if (tileEntityData != null && BlockEntity .loadStatic (localPos , localState , tileEntityData , world .registryAccess ()) instanceof BlockEntityTagSubstitution tagEntity )
@@ -271,7 +262,7 @@ public BlockPlacementResult handleBlockPlacement(
271262 }
272263 }
273264
274- if (BlockUtils . areBlockStatesEqual ( localState , worldState , handler :: replaceWithSolidBlock , handler . fancyPlacement (), handler :: shouldBlocksBeConsideredEqual , tileEntityData , worldEntity ))
265+ if (IPlacementHandler . doesWorldStateMatchBlueprintState ( blockInfo , worldPos , this . handler ))
275266 {
276267 return new BlockPlacementResult (worldPos , BlockPlacementResult .Result .SUCCESS );
277268 }
@@ -283,7 +274,7 @@ public BlockPlacementResult handleBlockPlacement(
283274
284275 if (!sameBlockInWorld && !this .handler .isCreative ())
285276 {
286- for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , false ))
277+ for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , handler ))
287278 {
288279 if (!stack .isEmpty () && !this .handler .isStackFree (stack ))
289280 {
@@ -309,7 +300,7 @@ public BlockPlacementResult handleBlockPlacement(
309300
310301 this .handler .prePlacementLogic (worldPos , localState , requiredItems );
311302
312- final IPlacementHandler .ActionProcessingResult result = placementHandler .handle (getHandler (). getBluePrint (), world , worldPos , localState , tileEntityData , ! this .handler . fancyPlacement (), this . handler . getWorldPos (), this . handler . getRotationMirror () );
303+ final IPlacementHandler .ActionProcessingResult result = placementHandler .handle (world , worldPos , localState , tileEntityData , this .handler );
313304 if (result == IPlacementHandler .ActionProcessingResult .DENY )
314305 {
315306 placementHandler .handleRemoval (handler , world , worldPos , tileEntityData );
@@ -352,7 +343,7 @@ public BlockPlacementResult handleEntitySpawn(
352343 {
353344 try
354345 {
355- final BlockPos pos = this .handler .getWorldPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
346+ final BlockPos pos = this .handler .getCenterPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
356347
357348 final Optional <EntityType <?>> type = EntityType .by (compound );
358349 if (type .isPresent ())
@@ -526,10 +517,7 @@ public BlockPlacementResult getResourceRequirements(
526517 {
527518 worldEntity = world .getBlockEntity (worldPos );
528519 }
529- if (localState .getBlock () == ModBlocks .blockSolidSubstitution .get () && handler .fancyPlacement ())
530- {
531- localState = this .handler .getSolidBlockForPos (worldPos , handler .getBluePrint ().getRawBlockStateFunction ().compose (handler ::getStructurePosFromWorld ));
532- }
520+
533521 if (localState .getBlock () == ModBlocks .blockTagSubstitution .get () && handler .fancyPlacement ())
534522 {
535523 if (tileEntityData != null && BlockEntity .loadStatic (localPos , localState , tileEntityData , world .registryAccess ()) instanceof BlockEntityTagSubstitution tagEntity )
@@ -551,7 +539,7 @@ public BlockPlacementResult getResourceRequirements(
551539 final IPlacementHandler placementHandler = PlacementHandlers .getHandler (world , worldPos , localState );
552540 if (!sameBlockInWorld )
553541 {
554- for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , false ))
542+ for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , handler ))
555543 {
556544 if (!stack .isEmpty () && !this .handler .isStackFree (stack ))
557545 {
0 commit comments