#Override bedrock block via mixin

92 messages · Page 1 of 1 (latest)

wintry citrus
#

if you just want to change the hardness, maybe use @ModifyConstant

#

but what you have will not work* because you did not specify how it should inject (@Inject for example)

#

I suggest using registryEdit instead

#

!!mr regedit

rough parcelBOT
deep lily
#

Or inject into Block class hardness if(this instadeof Blocks.BEDROCK) { return hardnes for bedrock}

#

Here is too many ways todo that

red crest
#

Ill try both of your guys idea

deep lily
red crest
#

Where do i put it?

#

Oh

deep lily
#

That is just example

red crest
#

ye but the hardness is stored in AbstractBlock.Settings

deep lily
#

It just default value on init

#

Just mixin into this HEAD that return for bedrock your own hardness insteadof settings

red crest
#

so i check if it is a bedrock then return my new one

#

alr

red crest
# deep lily

@Mixin(Block.class)
public class ModBedrockMixin {
@ModifyArg(method = "strength", at = @At(value = "INVOKE", target = "strength(FF)F
"), index = 0)
private float override(float y, float x) {
return 64.0F;
}
}

would this work ot?

deep lily
#

`

//code

`

red crest
#
@Mixin(Block.class)
public class ModBedrockMixin {
    @ModifyArg(method = "strength", at = @At(value = "INVOKE", target = "strength(FF)F
"), index = 0)
    private float override(float y, float x) {
        return 64.0F;
    }
}```
deep lily
#

Strength is combined value of hardness and resistance. I recommend to mixin they seperatly if required both

#
  • don't use infoke here and where you lost if?
deep lily
red crest
#

What do thse mean

deep lily
#

target of invoking is streanght(float, float) return float

#

But you not need INVOKE

red crest
#

so i remove value = "invoke"

deep lily
# deep lily

Read and realize what this do and how to transform it into your task form

red crest
#

i might use @Redirect to redirect the .strength(-1.0f, 3600000.0f) call on bedrock

red crest
#
@Mixin(AbstractBlock.Settings.class)
public class ModBedrockMixin {
    @Shadow
    private float hardness;
    @Shadow
    private float resistance;

    @Inject(method = "strength", at = @At("HEAD"), cancellable = true)
    private void overrideStrength(float hardness, float resistance, CallbackInfoReturnable<AbstractBlock.Settings> cir) {

        if (Objects.equals(((Block) (Object) this).getName().toString(), "BEDROCK")) {
            this.hardness = 5000000f;
            this.resistance = 3600000.0f;
            cir.setReturnValue((AbstractBlock.Settings)(Object)this);
        }
    }
}
red crest
#

how do i fix this?

red crest
deep lily
#
 if ((Block) (Object) this == Blocks.BEDROCK) {
                
}
#

Should work

#

oh, you...

#

Alright I will do it myself

red crest
#

im testing

#

why do we have to convert t Object?

red crest
deep lily
red crest
#

ye but how do i still idenify the block from its settings?

it gives this error

deep lily
#

ok, I admit that with the builder it’s a little more painstaking than I would like

red crest
#

I have to take a whole new approach

#

This mixin won’t work for blocks

#

Because you can’t select which block to modify

deep lily
#

@red crest

@Mixin(AbstractBlock.class)
abstract class AbstractBlockMixin {
    @Inject(at = @At(value = "JUMP", opcode = Opcodes.IFNE, shift = At.Shift.AFTER),
            method = "calcBlockBreakingDelta",
            cancellable = true,
            locals = LocalCapture.CAPTURE_FAILSOFT
    )
    public void allowBedrockBreaking(BlockState state, PlayerEntity player, BlockView world, BlockPos pos, CallbackInfoReturnable<Float> cir) {
        if (state.getHardness(world, pos) == -1.0F) {
            cir.setReturnValue(player.getBlockBreakingSpeed(state) / 1f / 2f);
        }
    }
}
#

That work, but have bugs

#

Oh, not bad, I don't notice expected bugs

red crest
#

I’ll test these when I’m home

deep lily
#

And I will be think about optimization

deep lily
#

Ye. Didn't find other way

night dove
#

That looks weird

#

Why not just /0.5

deep lily
deep lily
night dove
#

Yea, checks out

red crest
deep lily
red crest
#

Ok

red crest
deep lily
#

it return value that you want

#

There no correct answer

red crest
#

where does it do the actul return

deep lily
#

what?

red crest
#

where does it actully return the value

deep lily
#
cir.setReturnValue(player.getBlockBreakingSpeed(state) / 1f / 2f);

here

red crest
#

ok

deep lily
#

@red crest

@Mixin(Blocks.class)
public abstract class BlocksMixin {
    @Redirect(
            method = "<clinit>",
            slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=bedrock")),
            at = @At(value = "NEW", target = "(Lnet/minecraft/block/AbstractBlock$Settings;)Lnet/minecraft/block/Block;", ordinal = 0)
    )
    private static Block nemuelch$redirectBedrockBlockRegistration(AbstractBlock.Settings settings) {
        return new Block(AbstractBlock.Settings.create()
                .mapColor(MapColor.STONE_GRAY)
                .instrument(Instrument.BASEDRUM)
                .strength(5f, 3600000.0F)
                .allowsSpawning(Blocks::never));
    }
}

Redirect way. Work better, not break compatibility with other mods and simple to customize

You can do what ever by replace return new Block with our own class

red crest
#

wait so that new mixin overrides this:

deep lily
red crest
#

Oh'

deep lily
#

yes

red crest
#

And it does it before it actully reigsters the original settings

#

so before runtime

#

right

deep lily
#

Ye it replace it

red crest
#

Ok

#

Thanks

deep lily
#

I tested before send

red crest
#

Ok great

deep lily
#

now you can mark post as resolved and close it :)