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 insert(MultipartState state);
void remove(MultipartState state); void remove(MultipartView view);
boolean breakPart(MultipartState state); boolean breakPart(MultipartView view);
void schedulePartSave(); void schedulePartSave();

View File

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

View File

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