SimpleMultipart/src/main/java/net/shadowfacts/simplemultipart/multipart/MultipartView.java

79 lines
2.0 KiB
Java
Raw Normal View History

2018-12-28 02:55:51 +00:00
package net.shadowfacts.simplemultipart.multipart;
2018-12-25 15:20:44 +00:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2018-12-28 02:55:51 +00:00
import net.shadowfacts.simplemultipart.container.MultipartContainer;
2018-12-25 15:20:44 +00:00
import net.shadowfacts.simplemultipart.multipart.Multipart;
import net.shadowfacts.simplemultipart.multipart.MultipartState;
import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntity;
/**
2018-12-28 18:10:59 +00:00
* A view of a multipart and its (optional) associated entity.
*
2018-12-25 15:20:44 +00:00
* @author shadowfacts
2018-12-28 18:10:59 +00:00
* @since 0.1.0
2018-12-25 15:20:44 +00:00
*/
// TODO: better name for this
public interface MultipartView {
2018-12-28 18:10:59 +00:00
/**
* @return The container holding this part.
*/
MultipartContainer getContainer();
2018-12-25 15:20:44 +00:00
2018-12-28 18:10:59 +00:00
/**
* @return The current state of this multipart.
*/
2018-12-25 15:20:44 +00:00
MultipartState getState();
2018-12-28 18:10:59 +00:00
/**
* Sets the new state of this multipart.
*
* Note: This should only be used to change the state of the current {@link Multipart}.
* Changing to a different multipart should be done by removing/breaking the part in the container and then
* inserting the new one.
*
* Setting the state of a multipart will <b>not</b> cause the associated entity to change.
*
* @param state The new state.
*/
2018-12-28 02:55:51 +00:00
void setState(MultipartState state);
2018-12-28 18:10:59 +00:00
/**
* @return The entity associated with this part.
*/
/*@Nullable*/ MultipartEntity getEntity();
/**
* Sets the entity associated with this part.
*
* This should not usually be called. The associated multipart entity will be created/set by {@link MultipartContainer#insert(MultipartState)}
*
* @param entity The new entity.
*/
2018-12-28 02:55:51 +00:00
void setEntity(MultipartEntity entity);
2018-12-28 18:10:59 +00:00
/**
* Helper method for retrieving the multipart object for the current state.
* @return The current multipart.
*/
2018-12-25 15:20:44 +00:00
default Multipart getMultipart() {
return getState().getMultipart();
}
/**
* @return The world that this part's container is in.
*/
default World getWorld() {
return getContainer().getContainerWorld();
}
/**
* @return The position of this part's container.
*/
default BlockPos getPos() {
return getContainer().getContainerPos();
}
2018-12-25 15:20:44 +00:00
}