Tweak container API
This commit is contained in:
parent
5759262d07
commit
42413ebfae
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue