Skip to content

Commit

Permalink
fix(flesh-mound): fix unintentional MoundShape removal when the Cradl…
Browse files Browse the repository at this point in the history
…e BlockEntity is unloaded
  • Loading branch information
Elenterius committed Nov 29, 2023
1 parent 2680d0e commit a5cb46b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.elenterius.biomancy.styles.TextStyles;
import com.github.elenterius.biomancy.util.ComponentUtil;
import com.github.elenterius.biomancy.util.SoundUtil;
import com.github.elenterius.biomancy.world.RegionManager;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -107,6 +108,16 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return ModBlockEntities.PRIMORDIAL_CRADLE.get().create(pos, state);
}

@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
if (!state.is(newState.getBlock())) {
if (level instanceof ServerLevel serverLevel) {
RegionManager.remove(serverLevel, pos); //removes mound shape from level
}
super.onRemove(state, level, pos, newState, isMoving);
}
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,24 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Primo
@Override
public void onLoad() {
super.onLoad();
if (level instanceof ServerLevel serverLevel && !serverLevel.isClientSide) {
if (level instanceof ServerLevel serverLevel) {
Shape shape = RegionManager.getOrCreateShapeRegion(serverLevel, worldPosition, () -> {
if (procGenValues != null) {
return MoundGenerator.constructShape(worldPosition, procGenValues);
}
return MoundGenerator.constructShape(level, worldPosition, level.random.nextLong());
});

if (shape instanceof MoundShape moundShape) {
procGenValues = moundShape.getProcGenValues();
MoundShape.ProcGenValues values = moundShape.getProcGenValues();
if (!values.equals(procGenValues)) {
procGenValues = values;
setChangedSilent();
}
}
}
}

@Override
public void setRemoved() {
if (level instanceof ServerLevel serverLevel && !serverLevel.isClientSide) {
RegionManager.remove(serverLevel, worldPosition);
}
super.setRemoved();
}

/**
* modifies the stack
*/
Expand Down

0 comments on commit a5cb46b

Please sign in to comment.