#Override bedrock block via mixin
92 messages · Page 1 of 1 (latest)
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
Or inject into Block class hardness if(this instadeof Blocks.BEDROCK) { return hardnes for bedrock}
Here is too many ways todo that
Ill try both of your guys idea
How do i incorporate this
I used this way to allow enchant shield
That is just example
ye but the hardness is stored in AbstractBlock.Settings
It just default value on init
Just mixin into this HEAD that return for bedrock your own hardness insteadof settings
@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?
`
//code
`
@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;
}
}```
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?
What do thse mean
so i remove value = "invoke"
i might use @Redirect to redirect the .strength(-1.0f, 3600000.0f) call on bedrock
I almost got it working but im having a hard time trying to specifiy the block
@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);
}
}
}
Don't compare over object
how do i fix this?
do you know any way to idenify a block by its abstractblock.settings
if ((Block) (Object) this == Blocks.BEDROCK) {
}
Should work
oh, you...
Alright I will do it myself
same issue as mine
ye but how do i still idenify the block from its settings?
it gives this error
ok, I admit that with the builder it’s a little more painstaking than I would like
I have to take a whole new approach
This mixin won’t work for blocks
Because you can’t select which block to modify
@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
I’ll test these when I’m home
And I will be think about optimization
Ye. Didn't find other way
Why the /1f /2f
That looks weird
Why not just /0.5
Just random value for speed. In real practice need take player hand item and pass it mining speed
Ah, makes sense
I just laze to give full result
Yea, checks out
thanks also can i check if it is being mined by a specific pickaxe to. I created a bedrock breaker pickaxer for it
Just add to if condition that player main hand hold it
Ok
cir..setReturnValue() returns the value correct?
where does it do the actul return
what?
where does it actully return the value
cir.setReturnValue(player.getBlockBreakingSpeed(state) / 1f / 2f);
here
ok
@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
Wow thanks for taking your time to come back to this old post
wait so that new mixin overrides this:
Just saw similar with items in friend code and adopted it to bedrock, my mod also require that but for else
Oh'
yes
And it does it before it actully reigsters the original settings
so before runtime
right
Ye it replace it
I tested before send
Ok great
now you can mark post as resolved and close it :)