Merge remote-tracking branch 'upstream/master' into item-settings
This commit is contained in:
commit
a21114989d
|
@ -20,8 +20,8 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "com.mojang:minecraft:18w50a"
|
minecraft "com.mojang:minecraft:18w50a"
|
||||||
// mappings "net.fabricmc:yarn:18w50a.80"
|
mappings "net.fabricmc:yarn:18w50a.82"
|
||||||
mappings "net.fabricmc:yarn:18w50a.local" // temporary until yarn #369
|
// mappings "net.fabricmc:yarn:18w50a.local" // temporary until yarn #369
|
||||||
modCompile "net.fabricmc:fabric-loader:0.3.1.80"
|
modCompile "net.fabricmc:fabric-loader:0.3.1.80"
|
||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
|
||||||
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
||||||
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartView;
|
import net.shadowfacts.simplemultipart.multipart.MultipartView;
|
||||||
|
import net.shadowfacts.simplemultipart.util.ShapeUtils;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -69,6 +70,21 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit
|
||||||
return shape == null ? VoxelShapes.empty() : shape;
|
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
|
@Override
|
||||||
public abstract AbstractContainerBlockEntity createBlockEntity(BlockView world);
|
public abstract AbstractContainerBlockEntity createBlockEntity(BlockView world);
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
|
||||||
VoxelShape newShape = partState.getBoundingShape(null);
|
VoxelShape newShape = partState.getBoundingShape(null);
|
||||||
for (Entry e : parts) {
|
for (Entry e : parts) {
|
||||||
VoxelShape existingShape = e.state.getBoundingShape(e);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,28 @@ import net.shadowfacts.simplemultipart.util.MultipartPlacementContext;
|
||||||
* Analogous to {@link net.minecraft.item.block.BlockItem}.
|
* Analogous to {@link net.minecraft.item.block.BlockItem}.
|
||||||
*
|
*
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
* @since 0.1.0
|
* @since 0.1.1
|
||||||
*/
|
*/
|
||||||
public class MultipartItem extends Item {
|
public class MultipartItem extends Item {
|
||||||
|
|
||||||
protected Multipart part;
|
protected Multipart part;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Multipart Item for the given part with.
|
||||||
|
*
|
||||||
|
* @param part The multipart.
|
||||||
|
*/
|
||||||
public MultipartItem(Multipart part) {
|
public MultipartItem(Multipart part) {
|
||||||
this(part, new Settings());
|
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) {
|
public MultipartItem(Multipart part, Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.part = part;
|
this.part = part;
|
||||||
|
|
|
@ -95,6 +95,21 @@ public abstract class Multipart {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract VoxelShape getBoundingShape(MultipartState state, /*@Nullable*/ MultipartView view);
|
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.
|
* @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.
|
* 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.
|
* @param view The view of this part.
|
||||||
|
* @since 0.1.1
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void onPartAdded(MultipartView view) {
|
public void onPartAdded(MultipartView view) {
|
||||||
|
@ -154,8 +173,12 @@ public abstract class Multipart {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called <b>after</b> this part has been removed from its container.
|
* Called <b>after</b> 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.
|
* @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.
|
* 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
|
@Deprecated
|
||||||
public void onPartRemoved(MultipartView view) {
|
public void onPartRemoved(MultipartView view) {
|
||||||
|
|
|
@ -41,6 +41,14 @@ public class MultipartState extends AbstractPropertyContainer<Multipart, Multipa
|
||||||
return owner.getBoundingShape(this, view);
|
return owner.getBoundingShape(this, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Multipart#canIntersectWith(MultipartState, MultipartState)
|
||||||
|
*/
|
||||||
|
public boolean canIntersectWith(MultipartState other) {
|
||||||
|
//noinspection deprecation
|
||||||
|
return owner.canIntersectWith(this, other);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Multipart#getDroppedStacks(MultipartView, LootContext.Builder)
|
* @see Multipart#getDroppedStacks(MultipartView, LootContext.Builder)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package net.shadowfacts.simplemultipart.util;
|
package net.shadowfacts.simplemultipart.util;
|
||||||
|
|
||||||
import net.minecraft.util.BooleanBiFunction;
|
import net.minecraft.util.BooleanBiFunction;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.util.shape.VoxelShapes;
|
import net.minecraft.util.shape.VoxelShapes;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.DoubleFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
|
@ -15,4 +19,20 @@ public class ShapeUtils {
|
||||||
return !overlap.isEmpty();
|
return !overlap.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasSolidSide(VoxelShape shape, Direction side) {
|
||||||
|
if ((side.getDirection() == Direction.AxisDirection.POSITIVE && shape.getMaximum(side.getAxis()) < 1) || (side.getDirection() == Direction.AxisDirection.NEGATIVE && shape.getMinimum(side.getAxis()) > 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue