Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion]: radial decay #441

Open
1 task done
LizzieSpace opened this issue Sep 18, 2024 · 1 comment
Open
1 task done

[Suggestion]: radial decay #441

LizzieSpace opened this issue Sep 18, 2024 · 1 comment
Assignees

Comments

@LizzieSpace
Copy link

This suggestion is unique

  • I have searched the issue tracker and did not find an issue describing my suggestion

Use the editor below to elaborate.

The applySpreadDecay method from the DetachedRiftBlockEntity class uses the raw output of the BlockPos.randomInCube method, which causes a cubic decay pattern far too regular.

image

A simple check comparing the radius with the distance between the rift block and the randomly selected block would suffice to fix the problem and make the decay pattern grow far better and less regular.

The code addition below would add such check

public void applySpreadDecay(ServerLevel world, BlockPos pos) {
    float chance = this.size / 100.0F;
    if (random.nextFloat() <= chance) {
        BlockPos selected = (BlockPos)BlockPos.randomInCube(world.getRandom(), 1, pos, (int)chance).iterator().next();
++      if (pos.getCenter().distanceTo(selected.getCenter()) >= (int) chance) {return}
        Decay.decayBlock(world, selected, world.getBlockState(selected), DecaySource.RIFT);
    }
}

Resulting in the following effect

Screenshot 2024-09-18 185201

@LizzieSpace
Copy link
Author

LizzieSpace commented Sep 18, 2024

Wrote a mixin that fixes the issue as well. I am using it for a personal mod pack.

Uses official Mojang mappings

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.phys.Vec3;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(DetachedRiftBlockEntity.class)
public class DetachedRiftBlockEntityMixin {

    @Inject(method = "applySpreadDecay",cancellable = true , at = @At(value = "INVOKE", target = "Lorg/dimdev/dimdoors/world/decay/Decay;decayBlock(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lorg/dimdev/dimdoors/world/decay/DecaySource;)V"))
    private void injectBreak(ServerLevel world, BlockPos pos, CallbackInfo ci, @Local(ordinal = 1) BlockPos selected, @Local float radius) {
        Vec3 targetCenter = selected.getCenter();
        Vec3 posCenter = pos.getCenter();
        if ( posCenter.distanceTo(targetCenter) >= (int) radius) {ci.cancel();}
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants