Extract MultipartContainer into its own interface
This commit is contained in:
parent
d167b53931
commit
b334e6987e
|
@ -0,0 +1,22 @@
|
|||
package net.shadowfacts.simplemultipart.api;
|
||||
|
||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
public interface MultipartContainer {
|
||||
|
||||
Set<MultipartView> getParts();
|
||||
|
||||
boolean canInsert(MultipartState state);
|
||||
|
||||
void insert(MultipartState state);
|
||||
|
||||
void remove(MultipartState state);
|
||||
|
||||
boolean breakPart(MultipartState state);
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package net.shadowfacts.simplemultipart.api;
|
||||
|
||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
||||
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||
import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntity;
|
||||
|
@ -11,7 +10,7 @@ import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntity;
|
|||
// TODO: better name for this
|
||||
public interface MultipartView {
|
||||
|
||||
MultipartContainerBlockEntity getContainer();
|
||||
MultipartContainer getContainer();
|
||||
|
||||
MultipartState getState();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.util.shape.VoxelShape;
|
|||
import net.minecraft.world.loot.context.LootContext;
|
||||
import net.minecraft.world.loot.context.Parameters;
|
||||
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
||||
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||
import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntity;
|
||||
import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntityProvider;
|
||||
|
@ -29,7 +30,7 @@ import java.util.*;
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
public class MultipartContainerBlockEntity extends BlockEntity implements ClientSerializable {
|
||||
public class MultipartContainerBlockEntity extends BlockEntity implements MultipartContainer, ClientSerializable {
|
||||
|
||||
private Set<Entry> parts = new HashSet<>();
|
||||
|
||||
|
@ -37,10 +38,12 @@ public class MultipartContainerBlockEntity extends BlockEntity implements Client
|
|||
super(SimpleMultipart.containerBlockEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<MultipartView> getParts() {
|
||||
return ImmutableSet.copyOf(parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(MultipartState partState) {
|
||||
VoxelShape newShape = partState.getBoundingShape(null);
|
||||
for (Entry e : parts) {
|
||||
|
@ -53,7 +56,12 @@ public class MultipartContainerBlockEntity extends BlockEntity implements Client
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(MultipartState partState) {
|
||||
if (!canInsert(partState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MultipartEntity entity = null;
|
||||
if (partState.getMultipart() instanceof MultipartEntityProvider) {
|
||||
entity = ((MultipartEntityProvider)partState.getMultipart()).createMultipartEntity(partState, this);
|
||||
|
@ -63,6 +71,7 @@ public class MultipartContainerBlockEntity extends BlockEntity implements Client
|
|||
world.scheduleBlockRender(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(MultipartState partState) {
|
||||
parts.removeIf(e -> e.state == partState);
|
||||
|
||||
|
@ -71,6 +80,7 @@ public class MultipartContainerBlockEntity extends BlockEntity implements Client
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakPart(MultipartState partState) {
|
||||
Optional<Entry> entry = parts.stream().filter(e -> e.state == partState).findFirst();
|
||||
if (!entry.isPresent()) {
|
||||
|
|
|
@ -13,14 +13,13 @@ import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntity;
|
|||
import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntityProvider;
|
||||
import net.shadowfacts.simplemultipart.api.MultipartView;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
public class EntityTestPart extends Multipart implements MultipartEntityProvider<EntityTestPart.Entity> {
|
||||
public class EntityTestPart extends Multipart implements MultipartEntityProvider {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public VoxelShape getBoundingShape(MultipartState state, MultipartView view) {
|
||||
return VoxelShapes.cube(6/16f, 6/16f, 6/16f, 10/16f, 10/16f, 10/16f);
|
||||
}
|
||||
|
@ -34,8 +33,8 @@ public class EntityTestPart extends Multipart implements MultipartEntityProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public Function<MultipartContainerBlockEntity, Entity> getMultipartEntityFactory() {
|
||||
return Entity::new;
|
||||
public MultipartEntity createMultipartEntity(MultipartState state, MultipartContainerBlockEntity container) {
|
||||
return new Entity(container);
|
||||
}
|
||||
|
||||
public static class Entity extends MultipartEntity {
|
||||
|
|
Loading…
Reference in New Issue