Skip to content

Commit

Permalink
Printing in water fixed, bug fixed regarding slabs
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Dec 5, 2022
1 parent 3cc5746 commit 25e6fdc
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public SchematicBlockState(World world, WorldSchematic schematic, BlockPos block
this.currentState = world.getBlockState(blockPos);
}

public SchematicBlockState getNeighbor(Direction side) {
return new SchematicBlockState(world, schematic, blockPos.offset(side));
}

public SchematicBlockState offset(Direction direction) {
return new SchematicBlockState(world, schematic, blockPos.offset(direction));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import me.aleksilassila.litematica.printer.v1_19.actions.AbstractAction;
import net.minecraft.block.BlockState;
import net.minecraft.block.CoralBlock;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -58,7 +60,7 @@ public boolean canExecute(ClientPlayerEntity player) {
BlockState targetState = state.targetState;
BlockState currentState = state.currentState;

return !targetState.equals(currentState);
return !statesEqual(targetState, currentState);
}

abstract public List<AbstractAction> execute(ClientPlayerEntity player);
Expand Down Expand Up @@ -88,6 +90,8 @@ protected boolean statesEqualIgnoreProperties(BlockState state1, BlockState stat

loop:
for (Property<?> property : state1.getProperties()) {
if (property == Properties.WATERLOGGED && !(state1.getBlock() instanceof CoralBlock)) continue;

for (Property<?> ignoredProperty : propertiesToIgnore) {
if (property == ignoredProperty) continue loop;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected static void registerGuide(Class<? extends Guide> guideClass, Class<? e
DoorBlock.class, FenceGateBlock.class, TrapdoorBlock.class,
LeverBlock.class,
RepeaterBlock.class, ComparatorBlock.class, NoteBlock.class);
registerGuide(BlockReplacementGuide.class, SnowBlock.class, SeaPickleBlock.class, CandleBlock.class);
registerGuide(BlockReplacementGuide.class, SnowBlock.class, SeaPickleBlock.class, CandleBlock.class, SlabBlock.class);
registerGuide(LogGuide.class);
registerGuide(LogStrippingGuide.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import net.minecraft.block.*;
import net.minecraft.block.enums.SlabType;

public class BlockIndifferentGuesserGuide extends GuesserGuide {
public BlockIndifferentGuesserGuide(SchematicBlockState state) {
Expand Down Expand Up @@ -37,6 +38,10 @@ protected boolean statesEqual(BlockState resultState, BlockState targetState) {
TripwireBlock.EAST, TripwireBlock.SOUTH, TripwireBlock.WEST);
}

// if (getProperty(targetState, SlabBlock.TYPE).orElse(null) == SlabType.DOUBLE && resultBlock instanceof SlabBlock) {
// return statesEqualIgnoreProperties(resultState, targetState, SlabBlock.TYPE);
// }

return super.statesEqual(resultState, targetState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,30 @@ private Optional<Direction> getValidSide(SchematicBlockState state) {
if (printInAir && !getRequiresSupport()) {
return Optional.of(side);
} else {
SchematicBlockState neighborState = state.getNeighbor(side);
SchematicBlockState neighborState = state.offset(side);

// If neighbor is half slab
if (neighborState.currentState.contains(SlabBlock.TYPE)
&& neighborState.currentState.get(SlabBlock.TYPE) != SlabType.DOUBLE) {
if (getProperty(neighborState.currentState, SlabBlock.TYPE).orElse(null) == SlabType.DOUBLE) {
validSides.add(side);
continue;
}

// if (getProperty(neighborState.currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE) != SlabType.DOUBLE)
// continue;
//
// // If neighbor is half slab
// if (!(state.targetState.getBlock() instanceof SlabBlock)
// && getProperty(neighborState.currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE) != SlabType.DOUBLE) {
// continue;
// }

if (canBeClicked(neighborState.world, neighborState.blockPos) && // Handle unclickable grass for example
!neighborState.currentState.getMaterial().isReplaceable())
validSides.add(side);
}
}

for (Direction validSide : validSides) {
if (!isInteractive(state.getNeighbor(validSide).currentState.getBlock())) {
if (!isInteractive(state.offset(validSide).currentState.getBlock())) {
return Optional.of(validSide);
}
}
Expand All @@ -92,7 +100,7 @@ protected boolean getUseShift(SchematicBlockState state) {
// if (interactionDir == null) return false;
Direction clickSide = getValidSide(state).orElse(null);
if (clickSide == null) return false;
return isInteractive(state.getNeighbor(clickSide).currentState.getBlock());
return isInteractive(state.offset(clickSide).currentState.getBlock());
}

private Optional<Vec3d> getHitVector(SchematicBlockState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import net.minecraft.block.CandleBlock;
import net.minecraft.block.SeaPickleBlock;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.SnowBlock;
import net.minecraft.block.enums.SlabType;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -64,6 +66,10 @@ protected boolean getUseShift(SchematicBlockState state) {

@Override
public boolean canExecute(ClientPlayerEntity player) {
if (getProperty(targetState, SlabBlock.TYPE).orElse(null) == SlabType.DOUBLE && getProperty(currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE) != SlabType.DOUBLE) {
return super.canExecute(player);
}

if (currentLevel == null || targetLevel == null || increasingProperty == null) return false;
if (!statesEqualIgnoreProperties(currentState, targetState, increasingProperty)) return false;
if (currentLevel >= targetLevel) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.enums.ChestType;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -87,8 +88,10 @@ public PrinterPlacementContext getPlacementContext(ClientPlayerEntity player) {
}

@Override
protected boolean statesEqual(BlockState resultState, BlockState targetState) {
return super.statesEqual(resultState, targetState);
public boolean canExecute(ClientPlayerEntity player) {
if (targetState.getBlock() instanceof SlabBlock) return false; // Slabs are a special case

return super.canExecute(player);
}

private boolean correctChestPlacement(BlockState targetState, BlockState result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
Expand Down Expand Up @@ -78,7 +79,15 @@ public boolean canExecute(ClientPlayerEntity player) {
BlockState resultState = getRequiredItemAsBlock(player)
.orElse(targetState.getBlock())
.getPlacementState(ctx);
return resultState != null && resultState.canPlaceAt(state.world, state.blockPos);

// if (resultState != null && !canPlaceInWater(resultState)) return false;

if (resultState != null) {
if (!resultState.canPlaceAt(state.world, state.blockPos)) return false;
return !(currentState.getBlock() instanceof FluidBlock) || canPlaceInWater(resultState);
} else {
return false;
}
}

@Override
Expand Down Expand Up @@ -113,6 +122,22 @@ public static boolean isInteractive(Block block) {
return false;
}

private boolean canPlaceInWater(BlockState blockState) {
Block block = blockState.getBlock();
if (block instanceof FluidFillable) {
return true;
} else if (!(block instanceof DoorBlock) && !blockState.isIn(BlockTags.SIGNS) && !blockState.isOf(Blocks.LADDER) && !blockState.isOf(Blocks.SUGAR_CANE) && !blockState.isOf(Blocks.BUBBLE_COLUMN)) {
Material material = blockState.getMaterial();
if (material != Material.PORTAL && material != Material.STRUCTURE_VOID && material != Material.UNDERWATER_PLANT && material != Material.REPLACEABLE_UNDERWATER_PLANT) {
return material.blocksMovement();
} else {
return true;
}
}

return true;
}

public static Class<?>[] interactiveBlocks = new Class[]{
AbstractChestBlock.class, AbstractFurnaceBlock.class, CraftingTableBlock.class,
AbstractButtonBlock.class, LeverBlock.class, DoorBlock.class, TrapdoorBlock.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.enums.SlabType;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

Expand All @@ -15,9 +16,17 @@ public SlabGuide(SchematicBlockState state) {
super(state);
}

@Override
public boolean skipOtherGuides() {
return false;
}

@Override
protected List<Direction> getPossibleSides() {
return Arrays.stream(Direction.values()).filter(d -> d != (getRequiredHalf(state).getOpposite())).toList();
return Arrays.stream(Direction.values())
.filter(d -> d != (getRequiredHalf(state).getOpposite()) &&
getProperty(state.offset(d).currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE) == SlabType.DOUBLE)
.toList();
}

@Override
Expand Down

0 comments on commit 25e6fdc

Please sign in to comment.