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 ;
@@ -169,7 +170,7 @@ public StructurePhasePlacementResult executeStructureStep(
169170 result = handleEntitySpawn (world , worldPos , localPos , storage );
170171 break ;
171172 default :
172- result = handleBlockPlacement (world , worldPos , localPos , storage , localState , handler .getBluePrint ().getTileEntityData (worldPos , localPos ));
173+ result = handleBlockPlacement (world , worldPos , storage , new BlockInfo ( localPos , localState , handler .getBluePrint ().getTileEntityData (worldPos , localPos ) ));
173174 }
174175 count ++;
175176
@@ -208,19 +209,19 @@ public StructurePhasePlacementResult executeStructureStep(
208209 * When we extract this into another mod, we have to override the method.
209210 * @param world the world.
210211 * @param worldPos the world position.
211- * @param localPos the local pos
212212 * @param storage the change storage.
213- * @param localState the local state.
214- * @param tileEntityData the tileEntity.
213+ * @param blockInfo the tileEntity.
215214 */
216215 public BlockPlacementResult handleBlockPlacement (
217216 final Level world ,
218217 final BlockPos worldPos ,
219- final BlockPos localPos ,
220218 final ChangeStorage storage ,
221- BlockState localState ,
222- CompoundTag tileEntityData )
219+ final BlockInfo blockInfo )
223220 {
221+ BlockState localState = blockInfo .getState ();
222+ CompoundTag tileEntityData = blockInfo .getTileEntityData ();
223+ final BlockPos localPos = blockInfo .getPos ();
224+
224225 final BlockState worldState = world .getBlockState (worldPos );
225226 boolean sameBlockInWorld = false ;
226227 if (worldState .getBlock () == localState .getBlock () && tileEntityData == null )
@@ -243,7 +244,7 @@ public BlockPlacementResult handleBlockPlacement(
243244 {
244245 try
245246 {
246- final BlockPos pos = this .handler .getWorldPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
247+ final BlockPos pos = this .handler .getCenterPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
247248
248249 final Optional <EntityType <?>> type = EntityType .by (compound );
249250 if (type .isPresent ())
@@ -314,16 +315,6 @@ else if (requiredItems == null)
314315 }
315316 }
316317
317- BlockEntity worldEntity = null ;
318- if (tileEntityData != null )
319- {
320- worldEntity = world .getBlockEntity (worldPos );
321- }
322-
323- if (localState .getBlock () == ModBlocks .blockSolidSubstitution .get () && handler .fancyPlacement ())
324- {
325- localState = this .handler .getSolidBlockForPos (worldPos , handler .getBluePrint ().getRawBlockStateFunction ().compose (handler ::getStructurePosFromWorld ));
326- }
327318 if (localState .getBlock () == ModBlocks .blockTagSubstitution .get () && handler .fancyPlacement ())
328319 {
329320 if (tileEntityData != null && BlockEntity .loadStatic (localPos , localState , tileEntityData ) instanceof BlockEntityTagSubstitution tagEntity )
@@ -337,7 +328,7 @@ else if (requiredItems == null)
337328 }
338329 }
339330
340- if (BlockUtils . areBlockStatesEqual ( localState , worldState , handler :: replaceWithSolidBlock , handler . fancyPlacement (), handler :: shouldBlocksBeConsideredEqual , tileEntityData , worldEntity ))
331+ if (IPlacementHandler . doesWorldStateMatchBlueprintState ( blockInfo , worldPos , this . handler ))
341332 {
342333 return new BlockPlacementResult (worldPos , BlockPlacementResult .Result .SUCCESS );
343334 }
@@ -349,7 +340,7 @@ else if (requiredItems == null)
349340
350341 if (!sameBlockInWorld && !this .handler .isCreative ())
351342 {
352- for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , false ))
343+ for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , handler ))
353344 {
354345 if (!stack .isEmpty () && !this .handler .isStackFree (stack ))
355346 {
@@ -375,7 +366,7 @@ else if (requiredItems == null)
375366
376367 this .handler .prePlacementLogic (worldPos , localState , requiredItems );
377368
378- final IPlacementHandler .ActionProcessingResult result = placementHandler .handle (getHandler (). getBluePrint (), world , worldPos , localState , tileEntityData , ! this .handler . fancyPlacement (), this . handler . getWorldPos (), this . handler . getSettings () );
369+ final IPlacementHandler .ActionProcessingResult result = placementHandler .handle (world , worldPos , localState , tileEntityData , this .handler );
379370 if (result == IPlacementHandler .ActionProcessingResult .DENY )
380371 {
381372 placementHandler .handleRemoval (handler , world , worldPos , tileEntityData );
@@ -417,7 +408,7 @@ public BlockPlacementResult handleEntitySpawn(
417408 {
418409 try
419410 {
420- final BlockPos pos = this .handler .getWorldPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
411+ final BlockPos pos = this .handler .getCenterPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
421412
422413 final Optional <EntityType <?>> type = EntityType .by (compound );
423414 if (type .isPresent ())
@@ -584,7 +575,7 @@ public BlockPlacementResult getResourceRequirements(
584575 {
585576 try
586577 {
587- final BlockPos pos = this .handler .getWorldPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
578+ final BlockPos pos = this .handler .getCenterPos ().subtract (handler .getBluePrint ().getPrimaryBlockOffset ());
588579
589580 final Optional <EntityType <?>> type = EntityType .by (compound );
590581 if (type .isPresent ())
@@ -622,15 +613,6 @@ public BlockPlacementResult getResourceRequirements(
622613 }
623614 }
624615
625- BlockEntity worldEntity = null ;
626- if (tileEntityData != null )
627- {
628- worldEntity = world .getBlockEntity (worldPos );
629- }
630- if (localState .getBlock () == ModBlocks .blockSolidSubstitution .get () && handler .fancyPlacement ())
631- {
632- localState = this .handler .getSolidBlockForPos (worldPos , handler .getBluePrint ().getRawBlockStateFunction ().compose (handler ::getStructurePosFromWorld ));
633- }
634616 if (localState .getBlock () == ModBlocks .blockTagSubstitution .get () && handler .fancyPlacement ())
635617 {
636618 if (tileEntityData != null && BlockEntity .loadStatic (localPos , localState , tileEntityData ) instanceof BlockEntityTagSubstitution tagEntity )
@@ -644,15 +626,19 @@ public BlockPlacementResult getResourceRequirements(
644626 }
645627 }
646628
647- if (BlockUtils . areBlockStatesEqual ( localState , worldState , handler :: replaceWithSolidBlock , handler .fancyPlacement (), handler :: shouldBlocksBeConsideredEqual , tileEntityData , worldEntity ))
629+ if (IPlacementHandler . doesWorldStateMatchBlueprintState ( new BlockInfo ( localPos , localState , handler .getBluePrint (). getTileEntityData ( worldPos , localPos )), worldPos , this . handler ))
648630 {
631+ if (requiredItems .isEmpty ())
632+ {
633+ return new BlockPlacementResult (worldPos , BlockPlacementResult .Result .SUCCESS );
634+ }
649635 return new BlockPlacementResult (worldPos , BlockPlacementResult .Result .MISSING_ITEMS , requiredItems );
650636 }
651637
652638 final IPlacementHandler placementHandler = PlacementHandlers .getHandler (world , worldPos , localState );
653639 if (!sameBlockInWorld )
654640 {
655- for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , false ))
641+ for (final ItemStack stack : placementHandler .getRequiredItems (world , worldPos , localState , tileEntityData , handler ))
656642 {
657643 if (!stack .isEmpty () && !this .handler .isStackFree (stack ))
658644 {
0 commit comments