-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for vertical slabs #79
- Loading branch information
1 parent
817c3f2
commit f5e085d
Showing
17 changed files
with
256 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
common/src/main/java/net/blay09/mods/kleeslabs/converter/HorizontalSlabConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.blay09.mods.kleeslabs.converter; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.SlabType; | ||
|
||
public interface HorizontalSlabConverter extends SlabConverter { | ||
BlockState getSingleSlab(BlockState state, Level level, BlockPos pos, Player player, SlabType slabType); | ||
} |
46 changes: 46 additions & 0 deletions
46
common/src/main/java/net/blay09/mods/kleeslabs/converter/QuarkVerticalSlabConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.blay09.mods.kleeslabs.converter; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.util.StringRepresentable; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.Property; | ||
|
||
import java.util.Optional; | ||
|
||
public class QuarkVerticalSlabConverter implements VerticalSlabConverter { | ||
|
||
@Override | ||
public BlockState getSingleSlab(BlockState state, Level level, BlockPos pos, Player player, Direction direction) { | ||
if (direction.getAxis() == Direction.Axis.Y) { | ||
return state; | ||
} | ||
|
||
return locateProperty(state, "type") | ||
.flatMap(property -> withLocateValue(state, property, direction.getSerializedName())) | ||
.orElse(state); | ||
} | ||
|
||
private <T extends Comparable<T>> Optional<BlockState> withLocateValue(BlockState state, Property<T> property, String valueName) { | ||
return property.getValue(valueName).map(value -> state.setValue(property, value)); | ||
} | ||
|
||
private Optional<Property<?>> locateProperty(BlockState state, String name) { | ||
for (final var property : state.getProperties()) { | ||
if (property.getName().equals(name) && StringRepresentable.class.isAssignableFrom(property.getValueClass())) { | ||
return Optional.of(property); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean isDoubleSlab(BlockState state) { | ||
return locateProperty(state, "type").map(state::getValue) | ||
.map(value -> ((StringRepresentable) value).getSerializedName()) | ||
.map(name -> name.equals("double")) | ||
.orElse(false); | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
common/src/main/java/net/blay09/mods/kleeslabs/converter/SimpleSlabConverter.java
This file was deleted.
Oops, something went wrong.
11 changes: 1 addition & 10 deletions
11
common/src/main/java/net/blay09/mods/kleeslabs/converter/SlabConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
package net.blay09.mods.kleeslabs.converter; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.SlabType; | ||
|
||
public interface SlabConverter { | ||
BlockState getSingleSlab(BlockState state, Level level, BlockPos pos, Player player, SlabType slabType); | ||
|
||
default boolean isDoubleSlab(BlockState state) { | ||
return true; | ||
} | ||
|
||
boolean isDoubleSlab(BlockState state); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
common/src/main/java/net/blay09/mods/kleeslabs/converter/SmarterSlabConverter.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
common/src/main/java/net/blay09/mods/kleeslabs/converter/VerticalSlabConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.blay09.mods.kleeslabs.converter; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public interface VerticalSlabConverter extends SlabConverter { | ||
BlockState getSingleSlab(BlockState state, Level level, BlockPos pos, Player player, Direction direction); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.