Tweak container API

This commit is contained in:
Shadowfacts 2018-12-25 13:29:54 -05:00
parent 5759262d07
commit 42413ebfae
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 12 additions and 8 deletions

View File

@ -15,9 +15,9 @@ public interface MultipartContainer {
void insert(MultipartState state);
void remove(MultipartState state);
void remove(MultipartView view);
boolean breakPart(MultipartState state);
boolean breakPart(MultipartView view);
void schedulePartSave();

View File

@ -75,8 +75,12 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
}
@Override
public void remove(MultipartState partState) {
parts.removeIf(e -> e.state == partState);
public void remove(MultipartView view) {
if (view.getContainer() != this) {
return;
}
parts.removeIf(e -> e.state == view.getState() && e.entity == view.getEntity());
if (parts.isEmpty()) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
@ -86,8 +90,8 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
}
@Override
public boolean breakPart(MultipartState partState) {
Optional<Entry> entry = parts.stream().filter(e -> e.state == partState).findFirst();
public boolean breakPart(MultipartView view) {
Optional<Entry> entry = parts.stream().filter(e -> e.state == view.getState() && e.entity == view.getEntity()).findFirst();
if (!entry.isPresent()) {
return false;
}
@ -98,7 +102,7 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
// TODO: don't drop if player is creative
}
remove(partState);
remove(view);
updateWorld();

View File

@ -37,7 +37,7 @@ public class ContainerEventHandler {
return ActionResult.FAILURE;
}
boolean success = container.breakPart(hit.view.getState());
boolean success = container.breakPart(hit.view);
return success ? ActionResult.SUCCESS : ActionResult.FAILURE;
}