mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-13 15:56:07 +01:00
Get reset visual
- Remove Visual#shouldReset and associated logic - Instead, delete and add visuals when the level renderer is notified of a block state change (that has a block entity) - This does remove some control from BEVs, but it greatly simplifies the API and API contract
This commit is contained in:
parent
f0cbce0ae4
commit
183ea1f0f8
7 changed files with 22 additions and 39 deletions
|
@ -8,6 +8,17 @@ import com.jozufozu.flywheel.api.instance.Instance;
|
|||
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
/**
|
||||
* A visual associated with a specific block entity.
|
||||
*
|
||||
* <p>BlockEntityVisuals exist for at most the lifetime of the block entity they are associated with.</p>
|
||||
*
|
||||
* <p>If the block state at your BlockEntityVisual's position changes without removing the block entity,
|
||||
* the visual will be deleted and recreated. Therefore, it is also safe to assume than the block state
|
||||
* is constant for the lifetime of the visual.</p>
|
||||
*
|
||||
* @param <T> The block entity type.
|
||||
*/
|
||||
public interface BlockEntityVisual<T extends BlockEntity> extends Visual {
|
||||
/**
|
||||
* Collect all instances that should render with a crumbling overlay
|
||||
|
|
|
@ -24,18 +24,6 @@ public interface Visual {
|
|||
*/
|
||||
void update(float partialTick);
|
||||
|
||||
/**
|
||||
* When a visual is reset, the visual is deleted and re-created.
|
||||
* <br>
|
||||
* Just before {@link #update)} would be called, {@code shouldReset} is checked.
|
||||
* If this function returns {@code true}, then this visual will be {@link #delete deleted},
|
||||
* and another visual will be constructed to replace it. This allows for more sane resource
|
||||
* acquisition compared to trying to update everything within the lifetime of a visual.
|
||||
*
|
||||
* @return {@code true} if this visual should be discarded and refreshed.
|
||||
*/
|
||||
boolean shouldReset();
|
||||
|
||||
/**
|
||||
* Free any acquired resources.
|
||||
*/
|
||||
|
|
|
@ -34,6 +34,13 @@ abstract class LevelRendererMixin {
|
|||
return;
|
||||
}
|
||||
|
||||
manager.getBlockEntities().queueUpdate(blockEntity);
|
||||
var blockEntities = manager.getBlockEntities();
|
||||
if (oldState != newState) {
|
||||
blockEntities.queueRemove(blockEntity);
|
||||
blockEntities.queueAdd(blockEntity);
|
||||
} else {
|
||||
// I don't think this is possible to reach in vanilla
|
||||
blockEntities.queueUpdate(blockEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,15 +84,7 @@ public abstract class Storage<T> {
|
|||
return;
|
||||
}
|
||||
|
||||
// resetting visuals is by default used to handle block state changes.
|
||||
if (visual.shouldReset()) {
|
||||
// delete and re-create the visual.
|
||||
// resetting a visual supersedes updating it.
|
||||
remove(obj);
|
||||
create(obj, partialTick);
|
||||
} else {
|
||||
visual.update(partialTick);
|
||||
}
|
||||
visual.update(partialTick);
|
||||
}
|
||||
|
||||
public void recreateAll(float partialTick) {
|
||||
|
|
|
@ -65,11 +65,6 @@ public abstract class AbstractBlockEntityVisual<T extends BlockEntity> extends A
|
|||
this.notifier = notifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldReset() {
|
||||
return blockEntity.getBlockState() != blockState;
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to accommodate for floating point precision errors at high coordinates,
|
||||
* {@link VisualManager}s are allowed to arbitrarily adjust the origin, and
|
||||
|
|
|
@ -39,12 +39,7 @@ public abstract class AbstractVisual implements Visual {
|
|||
public void update(float partialTick) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldReset() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract void _delete();
|
||||
protected abstract void _delete();
|
||||
|
||||
@Override
|
||||
public final void delete() {
|
||||
|
|
|
@ -140,12 +140,7 @@ public class ExampleEffect implements Effect {
|
|||
public void update(float partialTick) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldReset() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void delete() {
|
||||
effects.forEach(BoidVisual::_delete);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue