Add multipart placement context isOffset
This commit is contained in:
parent
5173175668
commit
b601cdb516
|
@ -55,6 +55,7 @@ public class MultipartItem extends Item {
|
|||
*
|
||||
* If the player clicked an existing multipart container, it will attempt to insert into that one, falling back on
|
||||
* creating a new container.
|
||||
* Which container the placement is being attempted in can be determined from {@link MultipartPlacementContext#isOffset()}.
|
||||
*
|
||||
* @param context The item usage context.
|
||||
* @return The result of the placement.
|
||||
|
@ -62,7 +63,7 @@ public class MultipartItem extends Item {
|
|||
protected ActionResult tryPlace(ItemUsageContext context) {
|
||||
// If a multipart inside an existing container was clicked, try inserting into that
|
||||
MultipartContainer hitContainer = getContainer(context);
|
||||
if (hitContainer != null && tryPlace(new MultipartPlacementContext(hitContainer, context))) {
|
||||
if (hitContainer != null && tryPlace(new MultipartPlacementContext(hitContainer, false, context))) {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ public class MultipartItem extends Item {
|
|||
ItemUsageContext offsetContext = new ItemUsageContext(context.getPlayer(), context.getItemStack(), context.getPos().offset(context.getFacing()), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
|
||||
MultipartContainer offsetContainer = getOrCreateContainer(offsetContext);
|
||||
if (offsetContainer != null) {
|
||||
if (tryPlace(new MultipartPlacementContext(offsetContainer, offsetContext))) {
|
||||
if (tryPlace(new MultipartPlacementContext(offsetContainer, true, offsetContext))) {
|
||||
return ActionResult.SUCCESS;
|
||||
} else {
|
||||
// if the a new container was created, and no part was inserted, remove the empty container
|
||||
|
|
|
@ -18,14 +18,16 @@ import net.shadowfacts.simplemultipart.container.MultipartContainer;
|
|||
public class MultipartPlacementContext extends ItemUsageContext {
|
||||
|
||||
private final MultipartContainer container;
|
||||
private final boolean isOffset;
|
||||
|
||||
public MultipartPlacementContext(MultipartContainer container, PlayerEntity player, ItemStack stack, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) {
|
||||
public MultipartPlacementContext(MultipartContainer container, boolean isOffset, PlayerEntity player, ItemStack stack, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) {
|
||||
super(player, stack, pos, side, hitX, hitY, hitZ);
|
||||
this.container = container;
|
||||
this.isOffset = isOffset;
|
||||
}
|
||||
|
||||
public MultipartPlacementContext(MultipartContainer container, ItemUsageContext context) {
|
||||
this(container, context.getPlayer(), context.getItemStack(), context.getPos(), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
|
||||
public MultipartPlacementContext(MultipartContainer container, boolean isOffset, ItemUsageContext context) {
|
||||
this(container, isOffset, context.getPlayer(), context.getItemStack(), context.getPos(), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,4 +37,11 @@ public class MultipartPlacementContext extends ItemUsageContext {
|
|||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code false} if this container is the one clicked, {@code true} if this container is a newly created one offset from the block clicked.
|
||||
* @since 0.1.2
|
||||
*/
|
||||
public boolean isOffset() {
|
||||
return isOffset;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue