Cancelling a constructor [CandleCakeBlock] #1525
-
I have a mixin: @Mixin(CandleCakeBlock.class)
public class CandleCakeBlockMixin {
@Shadow
@Final
private static Map<Block, CandleCakeBlock> CANDLES_TO_CANDLE_CAKES;
@Inject(at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 0), method = "<init>", cancellable = true)
private void avoidMapInsertion(Block candle, AbstractBlock.Settings settings, CallbackInfo ci) {
if (CANDLES_TO_CANDLE_CAKES.containsKey(candle)) {
ci.cancel();
}
}
} that is meant to cancel my cakes getting added to this "CANDLES_TO_CANDLE_CAKES" map (as I do candle cake handling differently). However, I get this error:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It is intensional that constructors can't be cancelled, your mixin will need a little rethinking (perhaps adding after vanilla instead of before and preventing replacement) |
Beta Was this translation helpful? Give feedback.
-
The solution in this particular instance was to use a redirect at the invocation of the @Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
private <K, V> V put(Map<K, V> map, K key, V value) {
return value instanceof BasicCandleCakeBlock ? null : map.put(key, value);
} Credit to deirn on discord for this solution |
Beta Was this translation helpful? Give feedback.
The solution in this particular instance was to use a redirect at the invocation of the
.put
call. From there we can cancel the call on the condition that it's one of the cake blocks that I'm adding in. Which is exactly what I wanted.Credit to deirn on discord for this solution