mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-12 06:54:27 -04:00
[1.19.2] Implement custom SignTypes (#2585)
* Implement custom SingTypes * Update fabric-rendering-v1/src/testmod/resources/fabric-rendering-v1-testmod.mixins.json Co-authored-by: apple502j <33279053+apple502j@users.noreply.github.com> * Replace transitive access widener with SignTypeRegistry * Update fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/sign/SignTypeRegistry.java Co-authored-by: apple502j <33279053+apple502j@users.noreply.github.com> * Update fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/sign/SignTypeRegistry.java Co-authored-by: apple502j <33279053+apple502j@users.noreply.github.com> * Update fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/sign/SignTypeRegistry.java Co-authored-by: apple502j <33279053+apple502j@users.noreply.github.com> * Move sign types to object builder api * Make TexturedRenderLayersMixin more direct * Fix java doc * Fix test mod still using the rendering api namespace * Add teal sign item texture * Add lang for Teal Sign * Make checkstyle happy * Replace accessor with accesswidener * Apply suggestions from code review * Fix build * Rename local vars Co-authored-by: apple502j <33279053+apple502j@users.noreply.github.com> Co-authored-by: modmuss50 <modmuss50@gmail.com>
This commit is contained in:
parent
151944f27f
commit
d8ef6908eb
18 changed files with 314 additions and 2 deletions
fabric-object-builder-api-v1/src
client
java/net/fabricmc/fabric/mixin/object/builder/client
resources
main
java/net/fabricmc/fabric/api/object/builder/v1/sign
resources
testmod
java/net/fabricmc/fabric/test/object/builder
resources
assets/fabric-object-builder-api-v1-testmod
blockstates
lang
models
textures
fabric-rendering-v1
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.object.builder.client;
|
||||
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.client.render.entity.model.EntityModelLayer;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLayers;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.SignType;
|
||||
|
||||
@Mixin(EntityModelLayers.class)
|
||||
public class EntityModelLayersMixin {
|
||||
@Inject(method = "createSign", at = @At("HEAD"), cancellable = true)
|
||||
private static void fixSignNamespace(SignType type, CallbackInfoReturnable<EntityModelLayer> cir) {
|
||||
if (type.getName().indexOf(Identifier.NAMESPACE_SEPARATOR) != -1) {
|
||||
Identifier identifier = new Identifier(type.getName());
|
||||
cir.setReturnValue(new EntityModelLayer(new Identifier(identifier.getNamespace(), "sign/" + identifier.getPath()), "main"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.object.builder.client;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.SignType;
|
||||
|
||||
@Mixin(TexturedRenderLayers.class)
|
||||
public class TexturedRenderLayersMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
public static Identifier SIGNS_ATLAS_TEXTURE;
|
||||
|
||||
@Inject(method = "createSignTextureId", at = @At("HEAD"), cancellable = true)
|
||||
private static void modifyTextureId(SignType type, CallbackInfoReturnable<SpriteIdentifier> cir) {
|
||||
if (type.getName().indexOf(Identifier.NAMESPACE_SEPARATOR) != -1) {
|
||||
Identifier identifier = new Identifier(type.getName());
|
||||
cir.setReturnValue(new SpriteIdentifier(SIGNS_ATLAS_TEXTURE, new Identifier(identifier.getNamespace(), "entity/signs/" + identifier.getPath())));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,8 +3,10 @@
|
|||
"package": "net.fabricmc.fabric.mixin.object.builder.client",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"client": [
|
||||
"EntityModelLayersMixin",
|
||||
"ModelPredicateProviderRegistryAccessor",
|
||||
"ModelPredicateProviderRegistrySpecificAccessor"
|
||||
"ModelPredicateProviderRegistrySpecificAccessor",
|
||||
"TexturedRenderLayersMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.api.object.builder.v1.sign;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.SignType;
|
||||
|
||||
/**
|
||||
* This class allows registering {@link SignType}s.
|
||||
*
|
||||
* <p>A {@link SignType} is used to tell the game what texture a sign should use.
|
||||
*
|
||||
* <p>These textures are stored under {@code namespace/textures/entity/signs/}.
|
||||
*/
|
||||
public final class SignTypeRegistry {
|
||||
private SignTypeRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers a {@link SignType}.
|
||||
*
|
||||
* @param id the id of this {@link SignType}
|
||||
* @return a new {@link SignType}.
|
||||
*/
|
||||
public static SignType registerSignType(Identifier id) {
|
||||
return SignType.register(new SignType(id.toString()));
|
||||
}
|
||||
}
|
|
@ -12,3 +12,6 @@ accessible method net/minecraft/entity/SpawnRestriction register (Lnet/minecraft
|
|||
|
||||
accessible field net/minecraft/village/VillagerType BIOME_TO_TYPE Ljava/util/Map;
|
||||
accessible method net/minecraft/village/VillagerType <init> (Ljava/lang/String;)V
|
||||
|
||||
accessible method net/minecraft/util/SignType <init> (Ljava/lang/String;)V
|
||||
accessible method net/minecraft/util/SignType register (Lnet/minecraft/util/SignType;)Lnet/minecraft/util/SignType;
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.test.object.builder;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.SignBlock;
|
||||
import net.minecraft.block.WallSignBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.SignItem;
|
||||
import net.minecraft.util.SignType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.sign.SignTypeRegistry;
|
||||
|
||||
public class TealSignTest implements ModInitializer {
|
||||
public static final SignType TEAL_TYPE = SignTypeRegistry.registerSignType(ObjectBuilderTestConstants.id("teal"));
|
||||
public static final SignBlock TEAL_SIGN = new SignBlock(FabricBlockSettings.copy(Blocks.OAK_SIGN), TEAL_TYPE) {
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new TealSign(pos, state);
|
||||
}
|
||||
};
|
||||
public static final WallSignBlock TEAL_WALL_SIGN = new WallSignBlock(FabricBlockSettings.copy(Blocks.OAK_SIGN), TEAL_TYPE) {
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new TealSign(pos, state);
|
||||
}
|
||||
};
|
||||
public static final SignItem TEAL_SIGN_ITEM = new SignItem(new Item.Settings(), TEAL_SIGN, TEAL_WALL_SIGN);
|
||||
public static final BlockEntityType<TealSign> TEST_SIGN_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(TealSign::new, TEAL_SIGN, TEAL_WALL_SIGN).build();
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
Registry.register(Registry.BLOCK, ObjectBuilderTestConstants.id("teal_sign"), TEAL_SIGN);
|
||||
Registry.register(Registry.BLOCK, ObjectBuilderTestConstants.id("teal_wall_sign"), TEAL_WALL_SIGN);
|
||||
Registry.register(Registry.ITEM, ObjectBuilderTestConstants.id("teal_sign"), TEAL_SIGN_ITEM);
|
||||
Registry.register(Registry.BLOCK_ENTITY_TYPE, ObjectBuilderTestConstants.id("teal_sign"), TEST_SIGN_BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
public static class TealSign extends SignBlockEntity {
|
||||
public TealSign(BlockPos pos, BlockState state) {
|
||||
super(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<?> getType() {
|
||||
return TEST_SIGN_BLOCK_ENTITY;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.test.object.builder.client;
|
||||
|
||||
import net.minecraft.client.render.block.entity.SignBlockEntityRenderer;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.test.object.builder.TealSignTest;
|
||||
import net.fabricmc.fabric.test.object.builder.mixin.BlockEntityRendererFactoriesAccessor;
|
||||
|
||||
public class TealSignClientTest implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
BlockEntityRendererFactoriesAccessor.callRegister(TealSignTest.TEST_SIGN_BLOCK_ENTITY, SignBlockEntityRenderer::new);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.test.object.builder.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
|
||||
|
||||
@Mixin(BlockEntityRendererFactories.class)
|
||||
public interface BlockEntityRendererFactoriesAccessor {
|
||||
@Invoker
|
||||
static <T extends BlockEntity> void callRegister(BlockEntityType<? extends T> type, BlockEntityRendererFactory<T> factory) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "fabric-rendering-v1-testmod:block/teal_sign"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "fabric-rendering-v1-testmod:block/teal_sign"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,5 +3,6 @@
|
|||
"block.fabric-object-builder-api-v1-testmod.first_multi_betrayal_block": "First Multi Betrayal Block",
|
||||
"block.fabric-object-builder-api-v1-testmod.initial_betrayal_block": "Initial Betrayal Block",
|
||||
"block.fabric-object-builder-api-v1-testmod.second_multi_betrayal_block": "Second Multi Betrayal Block",
|
||||
"block.fabric-object-builder-api-v1-testmod.teal_sign": "Teal Sign",
|
||||
"text.fabric-object-builder-api-v1-testmod.block_entity_type_success": "Betrayal block at %s has correct block entity type: %s"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"textures": {
|
||||
"particle": "fabric-object-builder-api-v1-testmod:entity/signs/teal"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "fabric-object-builder-api-v1-testmod:item/teal_sign"
|
||||
}
|
||||
}
|
Binary file not shown.
After ![]() (image error) Size: 195 B |
Binary file not shown.
After ![]() (image error) Size: 221 B |
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "net.fabricmc.fabric.test.object.builder.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"BlockEntityRendererFactoriesAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
|
@ -20,12 +20,19 @@
|
|||
"fabric-object-builder-api-v1": "*"
|
||||
},
|
||||
"description": "Test mod for fabric object builder API v1.",
|
||||
"mixins": [
|
||||
"fabric-object-builder-api-v1-testmod.mixins.json"
|
||||
],
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.fabricmc.fabric.test.object.builder.BlockEntityTypeBuilderTest",
|
||||
"net.fabricmc.fabric.test.object.builder.CriterionRegistryTest::init",
|
||||
"net.fabricmc.fabric.test.object.builder.VillagerTypeTest1",
|
||||
"net.fabricmc.fabric.test.object.builder.VillagerTypeTest2"
|
||||
"net.fabricmc.fabric.test.object.builder.VillagerTypeTest2",
|
||||
"net.fabricmc.fabric.test.object.builder.TealSignTest"
|
||||
],
|
||||
"client": [
|
||||
"net.fabricmc.fabric.test.object.builder.client.TealSignClientTest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,3 +4,7 @@ version = getSubprojectVersion(project)
|
|||
moduleDependencies(project, [
|
||||
'fabric-api-base'
|
||||
])
|
||||
|
||||
testDependencies(project, [
|
||||
':fabric-object-builder-api-v1'
|
||||
])
|
||||
|
|
Loading…
Add table
Reference in a new issue