diff --git a/build.gradle b/build.gradle index 2a5bbd4..e67b026 100644 --- a/build.gradle +++ b/build.gradle @@ -20,8 +20,8 @@ repositories { dependencies { minecraft "com.mojang:minecraft:18w50a" -// mappings "net.fabricmc:yarn:18w50a.80" - mappings "net.fabricmc:yarn:18w50a.local" // temporary until yarn #369 + mappings "net.fabricmc:yarn:18w50a.82" +// mappings "net.fabricmc:yarn:18w50a.local" // temporary until yarn #369 modCompile "net.fabricmc:fabric-loader:0.3.1.80" // Fabric API. This is technically optional, but you probably want it anyway. diff --git a/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlock.java b/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlock.java index 3902768..d59f987 100644 --- a/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlock.java +++ b/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlock.java @@ -15,6 +15,7 @@ import net.shadowfacts.simplemultipart.client.util.RenderStateProvider; import net.shadowfacts.simplemultipart.util.MultipartHelper; import net.shadowfacts.simplemultipart.util.MultipartHitResult; import net.shadowfacts.simplemultipart.multipart.MultipartView; +import net.shadowfacts.simplemultipart.util.ShapeUtils; import java.util.Set; @@ -69,6 +70,21 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit return shape == null ? VoxelShapes.empty() : shape; } + @Override + @Deprecated + public boolean hasSolidTopSurface(BlockState state, BlockView world, BlockPos pos) { + MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos); + if (container == null) { + return false; + } + + return container.getParts().stream() + .anyMatch(view -> { + VoxelShape shape = view.getState().getBoundingShape(view); + return ShapeUtils.hasSolidSide(shape, Direction.UP); + }); + } + @Override public abstract AbstractContainerBlockEntity createBlockEntity(BlockView world); diff --git a/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlockEntity.java b/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlockEntity.java index 993d116..c6a18fa 100644 --- a/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlockEntity.java +++ b/src/main/java/net/shadowfacts/simplemultipart/container/AbstractContainerBlockEntity.java @@ -106,7 +106,7 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement VoxelShape newShape = partState.getBoundingShape(null); for (Entry e : parts) { VoxelShape existingShape = e.state.getBoundingShape(e); - if (ShapeUtils.intersect(newShape, existingShape)) { + if (ShapeUtils.intersect(newShape, existingShape) && !(partState.canIntersectWith(e.state) && e.state.canIntersectWith(partState))) { return false; } } diff --git a/src/main/java/net/shadowfacts/simplemultipart/item/MultipartItem.java b/src/main/java/net/shadowfacts/simplemultipart/item/MultipartItem.java index 655bc21..2f26ae7 100644 --- a/src/main/java/net/shadowfacts/simplemultipart/item/MultipartItem.java +++ b/src/main/java/net/shadowfacts/simplemultipart/item/MultipartItem.java @@ -18,16 +18,28 @@ import net.shadowfacts.simplemultipart.util.MultipartPlacementContext; * Analogous to {@link net.minecraft.item.block.BlockItem}. * * @author shadowfacts - * @since 0.1.0 + * @since 0.1.1 */ public class MultipartItem extends Item { protected Multipart part; + /** + * Creates a Multipart Item for the given part with. + * + * @param part The multipart. + */ public MultipartItem(Multipart part) { this(part, new Settings()); } + /** + * Creates a Multipart Item for the given part with the given item settings. + * + * @param part The multipart. + * @param settings The settings for this item. + * @since 0.1.2 + */ public MultipartItem(Multipart part, Settings settings) { super(settings); this.part = part; diff --git a/src/main/java/net/shadowfacts/simplemultipart/multipart/Multipart.java b/src/main/java/net/shadowfacts/simplemultipart/multipart/Multipart.java index 102f5ab..b337004 100644 --- a/src/main/java/net/shadowfacts/simplemultipart/multipart/Multipart.java +++ b/src/main/java/net/shadowfacts/simplemultipart/multipart/Multipart.java @@ -95,6 +95,21 @@ public abstract class Multipart { @Deprecated public abstract VoxelShape getBoundingShape(MultipartState state, /*@Nullable*/ MultipartView view); + /** + * Determines if this multipart can be placed in the same block as another part, even if their bounding boxes intersect. + * + * Can be overriden, should only be called via {@link MultipartState#canIntersectWith(MultipartState)} + * + * @param self The state for this part. + * @param other The other part that already exists. + * @return If the multiparts can coexist. + * @since 0.1.2 + */ + @Deprecated + public boolean canIntersectWith(MultipartState self, MultipartState other) { + return false; + } + /** * @return The loot table ID used for to determine the drops by the default {@link Multipart#getDroppedStacks(MultipartView, LootContext.Builder)} implementation. */ @@ -146,7 +161,11 @@ public abstract class Multipart { /** * Called after this multipart (and it's entity, if there is one) has been added to the container. + * + * Can be overriden, should only be called via {@link MultipartState#onPartAdded(MultipartView)} + * * @param view The view of this part. + * @since 0.1.1 */ @Deprecated public void onPartAdded(MultipartView view) { @@ -154,8 +173,12 @@ public abstract class Multipart { /** * Called after this part has been removed from its container. + * + * Can be overriden, should only be called via {@link MultipartState#onPartRemoved(MultipartView)} + * * @param view The view of this part. * The multipart entity and container in this view are still present, but the part is no longer in the container. + * @since 0.1.1 */ @Deprecated public void onPartRemoved(MultipartView view) { diff --git a/src/main/java/net/shadowfacts/simplemultipart/multipart/MultipartState.java b/src/main/java/net/shadowfacts/simplemultipart/multipart/MultipartState.java index b7adf3a..1cb3152 100644 --- a/src/main/java/net/shadowfacts/simplemultipart/multipart/MultipartState.java +++ b/src/main/java/net/shadowfacts/simplemultipart/multipart/MultipartState.java @@ -41,6 +41,14 @@ public class MultipartState extends AbstractPropertyContainer 0)) { + return false; + } + for (Direction.Axis axis : Direction.Axis.values()) { + if (axis == side.getAxis()) { + continue; + } + + if (shape.getMinimum(axis) > 0 || shape.getMaximum(axis) < 1) { + return false; + } + } + return true; + } + }