Change MultipartEntity container to a view
This commit is contained in:
parent
271bb0165e
commit
53b0db1cc4
|
@ -69,11 +69,13 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
|
|||
return;
|
||||
}
|
||||
|
||||
MultipartEntity entity = null;
|
||||
|
||||
Entry e = new Entry(this, partState, null);
|
||||
if (partState.getMultipart() instanceof MultipartEntityProvider) {
|
||||
entity = ((MultipartEntityProvider)partState.getMultipart()).createMultipartEntity(partState, this);
|
||||
e.entity = ((MultipartEntityProvider)partState.getMultipart()).createMultipartEntity(partState, this);
|
||||
e.entity.view = e;
|
||||
}
|
||||
parts.add(new Entry(this, partState, entity));
|
||||
parts.add(e);
|
||||
|
||||
updateWorld();
|
||||
}
|
||||
|
@ -128,7 +130,7 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
|
|||
newContainer.parts = parts.stream()
|
||||
.map(e -> new Entry(newContainer, e.state, e.entity))
|
||||
.collect(Collectors.toSet());
|
||||
newContainer.parts.stream().filter(e -> e.entity != null).forEach(e -> e.entity.container = newContainer);
|
||||
newContainer.parts.stream().filter(e -> e.entity != null).forEach(e -> e.entity.view = e);
|
||||
}
|
||||
|
||||
world.markDirty(pos, world.getBlockEntity(pos));
|
||||
|
@ -163,12 +165,14 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
|
|||
for (Tag tag : list) {
|
||||
CompoundTag compound = (CompoundTag)tag;
|
||||
MultipartState state = MultipartHelper.deserializeMultipartState(compound.getCompound("part"));
|
||||
MultipartEntity entity = null;
|
||||
|
||||
Entry e = new Entry(this, state, null);
|
||||
if (state.getMultipart() instanceof MultipartEntityProvider && compound.containsKey("entity", NbtType.COMPOUND)) {
|
||||
entity = ((MultipartEntityProvider)state.getMultipart()).createMultipartEntity(state, this);
|
||||
entity.fromTag(compound.getCompound("entity"));
|
||||
e.entity = ((MultipartEntityProvider)state.getMultipart()).createMultipartEntity(state, this);
|
||||
e.entity.view = e;
|
||||
e.entity.fromTag(compound.getCompound("entity"));
|
||||
}
|
||||
parts.add(new Entry(this, state, entity));
|
||||
parts.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.shadowfacts.simplemultipart.multipart.entity;
|
|||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.shadowfacts.simplemultipart.container.MultipartContainer;
|
||||
import net.shadowfacts.simplemultipart.multipart.MultipartView;
|
||||
|
||||
/**
|
||||
* An entity associated with multiparts placed in the world. An instance of the part's entity exists for every in-world
|
||||
|
@ -17,20 +18,15 @@ import net.shadowfacts.simplemultipart.container.MultipartContainer;
|
|||
public abstract class MultipartEntity {
|
||||
|
||||
/**
|
||||
* The container holding this multipart entity.
|
||||
* The view of this multipart.
|
||||
*/
|
||||
// TODO: change this to a view?
|
||||
public MultipartContainer container;
|
||||
|
||||
public MultipartEntity(MultipartContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
public MultipartView view;
|
||||
|
||||
/**
|
||||
* Calling this indicates that something about this entity has changed that necessitates saving it to disk.
|
||||
*/
|
||||
protected void scheduleSave() {
|
||||
container.schedulePartSave();
|
||||
view.getContainer().schedulePartSave();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,16 +35,12 @@ public class EntityTestPart extends Multipart implements MultipartEntityProvider
|
|||
|
||||
@Override
|
||||
public MultipartEntity createMultipartEntity(MultipartState state, MultipartContainer container) {
|
||||
return new Entity(container);
|
||||
return new Entity();
|
||||
}
|
||||
|
||||
public static class Entity extends MultipartEntity {
|
||||
public Entity(MultipartContainer container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return ((AbstractContainerBlockEntity)container).getPos();
|
||||
return ((AbstractContainerBlockEntity)view.getContainer()).getPos();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,16 +34,12 @@ public class TickableEntityTestPart extends Multipart implements MultipartEntity
|
|||
|
||||
@Override
|
||||
public MultipartEntity createMultipartEntity(MultipartState state, MultipartContainer container) {
|
||||
return new Entity(container);
|
||||
return new Entity();
|
||||
}
|
||||
|
||||
public static class Entity extends MultipartEntity implements Tickable {
|
||||
public int timer = 0;
|
||||
|
||||
public Entity(MultipartContainer container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
timer++;
|
||||
|
|
Loading…
Reference in New Issue