Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import com.ldtteam.structurize.client.gui.util.InputFilters;
import com.ldtteam.structurize.client.gui.util.ItemPositionsStorage;
import com.ldtteam.structurize.network.messages.*;
import com.ldtteam.structurize.placement.SimplePlacementContext;
import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
import com.ldtteam.structurize.placement.handlers.placement.PlacementHandlers;
import com.ldtteam.structurize.storage.rendering.RenderingCache;
import com.ldtteam.structurize.storage.rendering.types.BoxPreviewData;
import com.ldtteam.structurize.util.PlacementSettings;
import com.ldtteam.structurize.util.ScanToolData;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
Expand Down Expand Up @@ -514,7 +516,7 @@ private void updateResources()
else
{
final IPlacementHandler handler = PlacementHandlers.getHandler(world, BlockPos.ZERO, blockState);
final List<ItemStack> itemList = handler.getRequiredItems(world, here, blockState, tileEntity == null ? null : tileEntity.saveWithFullMetadata(), true);
final List<ItemStack> itemList = handler.getRequiredItems(world, here, blockState, tileEntity == null ? null : tileEntity.saveWithFullMetadata(), new SimplePlacementContext(false, new PlacementSettings()));
for (final ItemStack stack : itemList)
{
addNeededResource(stack, visible, here);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ldtteam.structurize.placement;

import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
import com.ldtteam.structurize.placement.structure.IStructureHandler;
import com.ldtteam.structurize.util.BlockUtils;
import com.ldtteam.structurize.util.BlueprintPositionInfo;
import net.minecraft.core.BlockPos;
import net.minecraftforge.common.util.TriPredicate;
Expand Down Expand Up @@ -106,9 +106,7 @@ private Result iterateWithCondition(final TriPredicate<BlueprintPositionInfo, Bl
{
continue;
}
else if (!isRemoving() && BlockUtils.areBlockStatesEqual(info.getBlockInfo().getState(), structureHandler.getWorld().getBlockState(worldPos), structureHandler::replaceWithSolidBlock, structureHandler.fancyPlacement(), structureHandler::shouldBlocksBeConsideredEqual,
info.getBlockInfo().getTileEntityData(),
info.getBlockInfo().getTileEntityData() == null ? null : structureHandler.getWorld().getBlockEntity(worldPos)) && info.getEntities().length == 0)
else if (!isRemoving() && IPlacementHandler.doesWorldStateMatchBlueprintState(info.getBlockInfo(), worldPos, structureHandler) && info.getEntities().length == 0)
{
structureHandler.triggerSuccess(progressPos, Collections.emptyList(), false);
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.ldtteam.structurize.placement;

import com.ldtteam.structurize.blueprints.v1.Blueprint;
import com.ldtteam.structurize.util.PlacementSettings;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

public interface IPlacementContext
{
/**
* Getter for the placement settings.
* @return the settings object.
*/
PlacementSettings getRotationMirror();

/**
* If this is supposed to be fancy placement (player facing) or builder facing (complete).
* @return true if fancy placement.
*/
boolean fancyPlacement();

/**
* Get the solid worldgen block for given pos while using data from handler.
*
* @param worldPos the world pos.
* @param virtualBlocks blueprint blocks, fnc may return null if virtual block is not available (then use level instead for getting surrounding block states), pos argument is using world coords
* @return the solid worldgen block (classically biome dependent).
*/
BlockState getSolidBlockForPos(BlockPos worldPos, Function<BlockPos, @Nullable BlockState> virtualBlocks);

/**
* Get the world position this is placed at.
* @return the position.
*/
BlockPos getCenterPos();

/**
* Get the bluerint from the handler.
* @return the blueprint
*/
Blueprint getBluePrint();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.ldtteam.structurize.placement;

import com.ldtteam.structurize.blueprints.v1.Blueprint;
import com.ldtteam.structurize.util.PlacementSettings;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

/**
* Simple placement context for non blueprint handling.
*/
public class SimplePlacementContext implements IPlacementContext
{
/**
* If placement should be fancy or complete.
*/
private final boolean fancyPlacement;

/**
* Rotation mirror.
*/
private final PlacementSettings rotationMirror;

public SimplePlacementContext(final boolean fancyPlacement, final PlacementSettings rotationMirror)
{
this.fancyPlacement = fancyPlacement;
this.rotationMirror = rotationMirror;
}

@Override
public PlacementSettings getRotationMirror()
{
return rotationMirror;
}

@Override
public boolean fancyPlacement()
{
return fancyPlacement;
}

@Override
public BlockState getSolidBlockForPos(final BlockPos worldPos, final Function<BlockPos, @Nullable BlockState> virtualBlocks)
{
return Blocks.DIRT.defaultBlockState();
}

@Override
public BlockPos getCenterPos()
{
return BlockPos.ZERO;
}

@Override
public Blueprint getBluePrint()
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
import com.ldtteam.structurize.placement.handlers.placement.PlacementHandlers;
import com.ldtteam.structurize.placement.structure.IStructureHandler;
import com.ldtteam.structurize.util.BlockInfo;
import com.ldtteam.structurize.util.BlockUtils;
import com.ldtteam.structurize.util.ChangeStorage;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -169,7 +170,7 @@ public StructurePhasePlacementResult executeStructureStep(
result = handleEntitySpawn(world, worldPos, localPos, storage);
break;
default:
result = handleBlockPlacement(world, worldPos, localPos, storage, localState, handler.getBluePrint().getTileEntityData(worldPos, localPos));
result = handleBlockPlacement(world, worldPos, storage, new BlockInfo(localPos, localState, handler.getBluePrint().getTileEntityData(worldPos, localPos)));
}
count++;

Expand Down Expand Up @@ -208,19 +209,19 @@ public StructurePhasePlacementResult executeStructureStep(
* When we extract this into another mod, we have to override the method.
* @param world the world.
* @param worldPos the world position.
* @param localPos the local pos
* @param storage the change storage.
* @param localState the local state.
* @param tileEntityData the tileEntity.
* @param blockInfo the tileEntity.
*/
public BlockPlacementResult handleBlockPlacement(
final Level world,
final BlockPos worldPos,
final BlockPos localPos,
final ChangeStorage storage,
BlockState localState,
CompoundTag tileEntityData)
final BlockInfo blockInfo)
{
BlockState localState = blockInfo.getState();
CompoundTag tileEntityData = blockInfo.getTileEntityData();
final BlockPos localPos = blockInfo.getPos();

final BlockState worldState = world.getBlockState(worldPos);
boolean sameBlockInWorld = false;
if (worldState.getBlock() == localState.getBlock() && tileEntityData == null)
Expand All @@ -243,7 +244,7 @@ public BlockPlacementResult handleBlockPlacement(
{
try
{
final BlockPos pos = this.handler.getWorldPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());
final BlockPos pos = this.handler.getCenterPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());

final Optional<EntityType<?>> type = EntityType.by(compound);
if (type.isPresent())
Expand Down Expand Up @@ -314,16 +315,6 @@ else if (requiredItems == null)
}
}

BlockEntity worldEntity = null;
if (tileEntityData != null)
{
worldEntity = world.getBlockEntity(worldPos);
}

if (localState.getBlock() == ModBlocks.blockSolidSubstitution.get() && handler.fancyPlacement())
{
localState = this.handler.getSolidBlockForPos(worldPos, handler.getBluePrint().getRawBlockStateFunction().compose(handler::getStructurePosFromWorld));
}
if (localState.getBlock() == ModBlocks.blockTagSubstitution.get() && handler.fancyPlacement())
{
if (tileEntityData != null && BlockEntity.loadStatic(localPos, localState, tileEntityData) instanceof BlockEntityTagSubstitution tagEntity)
Expand All @@ -337,7 +328,7 @@ else if (requiredItems == null)
}
}

if (BlockUtils.areBlockStatesEqual(localState, worldState, handler::replaceWithSolidBlock, handler.fancyPlacement(), handler::shouldBlocksBeConsideredEqual, tileEntityData, worldEntity))
if (IPlacementHandler.doesWorldStateMatchBlueprintState(blockInfo, worldPos, this.handler))
{
return new BlockPlacementResult(worldPos, BlockPlacementResult.Result.SUCCESS);
}
Expand All @@ -349,7 +340,7 @@ else if (requiredItems == null)

if (!sameBlockInWorld && !this.handler.isCreative())
{
for (final ItemStack stack : placementHandler.getRequiredItems(world, worldPos, localState, tileEntityData, false))
for (final ItemStack stack : placementHandler.getRequiredItems(world, worldPos, localState, tileEntityData, handler))
{
if (!stack.isEmpty() && !this.handler.isStackFree(stack))
{
Expand All @@ -375,7 +366,7 @@ else if (requiredItems == null)

this.handler.prePlacementLogic(worldPos, localState, requiredItems);

final IPlacementHandler.ActionProcessingResult result = placementHandler.handle(getHandler().getBluePrint(), world, worldPos, localState, tileEntityData, !this.handler.fancyPlacement(), this.handler.getWorldPos(), this.handler.getSettings());
final IPlacementHandler.ActionProcessingResult result = placementHandler.handle(world, worldPos, localState, tileEntityData, this.handler);
if (result == IPlacementHandler.ActionProcessingResult.DENY)
{
placementHandler.handleRemoval(handler, world, worldPos, tileEntityData);
Expand Down Expand Up @@ -417,7 +408,7 @@ public BlockPlacementResult handleEntitySpawn(
{
try
{
final BlockPos pos = this.handler.getWorldPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());
final BlockPos pos = this.handler.getCenterPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());

final Optional<EntityType<?>> type = EntityType.by(compound);
if (type.isPresent())
Expand Down Expand Up @@ -584,7 +575,7 @@ public BlockPlacementResult getResourceRequirements(
{
try
{
final BlockPos pos = this.handler.getWorldPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());
final BlockPos pos = this.handler.getCenterPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());

final Optional<EntityType<?>> type = EntityType.by(compound);
if (type.isPresent())
Expand Down Expand Up @@ -622,15 +613,6 @@ public BlockPlacementResult getResourceRequirements(
}
}

BlockEntity worldEntity = null;
if (tileEntityData != null)
{
worldEntity = world.getBlockEntity(worldPos);
}
if (localState.getBlock() == ModBlocks.blockSolidSubstitution.get() && handler.fancyPlacement())
{
localState = this.handler.getSolidBlockForPos(worldPos, handler.getBluePrint().getRawBlockStateFunction().compose(handler::getStructurePosFromWorld));
}
if (localState.getBlock() == ModBlocks.blockTagSubstitution.get() && handler.fancyPlacement())
{
if (tileEntityData != null && BlockEntity.loadStatic(localPos, localState, tileEntityData) instanceof BlockEntityTagSubstitution tagEntity)
Expand All @@ -644,15 +626,19 @@ public BlockPlacementResult getResourceRequirements(
}
}

if (BlockUtils.areBlockStatesEqual(localState, worldState, handler::replaceWithSolidBlock, handler.fancyPlacement(), handler::shouldBlocksBeConsideredEqual, tileEntityData, worldEntity))
if (IPlacementHandler.doesWorldStateMatchBlueprintState(new BlockInfo(localPos, localState, handler.getBluePrint().getTileEntityData(worldPos, localPos)), worldPos, this.handler))
{
if (requiredItems.isEmpty())
{
return new BlockPlacementResult(worldPos, BlockPlacementResult.Result.SUCCESS);
}
return new BlockPlacementResult(worldPos, BlockPlacementResult.Result.MISSING_ITEMS, requiredItems);
}

final IPlacementHandler placementHandler = PlacementHandlers.getHandler(world, worldPos, localState);
if (!sameBlockInWorld)
{
for (final ItemStack stack : placementHandler.getRequiredItems(world, worldPos, localState, tileEntityData, false))
for (final ItemStack stack : placementHandler.getRequiredItems(world, worldPos, localState, tileEntityData, handler))
{
if (!stack.isEmpty() && !this.handler.isStackFree(stack))
{
Expand Down
Loading