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] Implement These Improvements For Sign Support #35

Open
SmushyTaco opened this issue Jul 17, 2021 · 1 comment
Open

[Suggestion] Implement These Improvements For Sign Support #35

SmushyTaco opened this issue Jul 17, 2021 · 1 comment

Comments

@SmushyTaco
Copy link

So I noticed you guys kind of overcomplicated the sign API with a registry of some sort so I'd like to share my solution here for you guys because I think it would be much easier to use. To get rid of the need for a registry you can do:

class CustomSignType(val namespace: String, name: String): SignType(name)

and

class CustomSignBlock(settings: Settings, signType: SignType, val namespace: String, val baseName: String): SignBlock(settings, signType)

That's the only Kotlin code you'll see sorry about that lol

Once you've done that you'll need to fix the sign's loot table with:

@Mixin(AbstractBlock.class)
@SuppressWarnings("ConstantConditions")
public abstract class SignLootTableFixMixin {
    @Shadow
    @Nullable
    protected Identifier lootTableId;
    @Inject(method = "getLootTableId", at = @At("HEAD"), cancellable = true)
    private void hookGetLootTableId(CallbackInfoReturnable<Identifier> cir) {
        AbstractBlock abstractBlock = (AbstractBlock) (Object) this;
        if (!(abstractBlock instanceof CustomSignBlock customSignBlock)) return;
        Identifier correctLootTableId = new Identifier(customSignBlock.getNamespace(), "blocks/" + customSignBlock.getBaseName() + "_sign");
        if (!Objects.equals(lootTableId, correctLootTableId)) lootTableId = correctLootTableId;
        cir.setReturnValue(lootTableId);
    }
}

and then you'll need:

@Mixin(BlockEntityType.class)
@SuppressWarnings("EqualsBetweenInconvertibleTypes")
public abstract class SignFixMixin {
    @Inject(method = "supports", at = @At("HEAD"), cancellable = true)
    private void hookSupports(BlockState state, CallbackInfoReturnable<Boolean> info) {
        if (!BlockEntityType.SIGN.equals(this) || (!(state.getBlock() instanceof SignBlock) && !(state.getBlock() instanceof WallSignBlock))) return;
        info.setReturnValue(true);
    }
}

and after that all you need is:

@Mixin(TexturedRenderLayers.class)
@Environment(EnvType.CLIENT)
public abstract class SignEntityNamespaceFix {
    @Inject(method = "createSignTextureId", at = @At("HEAD"), cancellable = true)
    private static void hookCreateSignTextureId(SignType type, CallbackInfoReturnable<SpriteIdentifier> cir) {
        if (type instanceof CustomSignType customType) cir.setReturnValue(new SpriteIdentifier(TexturedRenderLayers.SIGNS_ATLAS_TEXTURE, new Identifier(customType.getNamespace(), "entity/signs/" + type.getName())));
    }
}

To get the proper namespace to be used for the sign texture's location.

Hope this helps!

@SmushyTaco
Copy link
Author

SmushyTaco commented Jul 17, 2021

If you guys want a solution to be able to use vanilla boats so it's functionality is always 1:1 too let me know, mind you that Fabric ASM will be needed for creating new boat types as of now since BoatEntity$Type is an enum.

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

No branches or pull requests

1 participant