Skip to content

Commit

Permalink
use resloc helpers where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Jun 28, 2024
1 parent 386b513 commit 9985048
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.init.BCSoundEvents;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.common.data.SoundDefinition;
import net.neoforged.neoforge.common.data.SoundDefinitionsProvider;
Expand All @@ -16,10 +16,10 @@ public BCSoundDefinitionsProvider(PackOutput output, ExistingFileHelper helper)
@Override
public void registerSounds() {
add(BCSoundEvents.DESK_BELL.value(), SoundDefinition.definition().with(
sound(ResourceLocation.fromNamespaceAndPath(BibliocraftApi.MOD_ID, "desk_bell_1")),
sound(ResourceLocation.fromNamespaceAndPath(BibliocraftApi.MOD_ID, "desk_bell_2")),
sound(ResourceLocation.fromNamespaceAndPath(BibliocraftApi.MOD_ID, "desk_bell_3")),
sound(ResourceLocation.fromNamespaceAndPath(BibliocraftApi.MOD_ID, "desk_bell_4"))
sound(BCUtil.modLoc("desk_bell_1")),
sound(BCUtil.modLoc("desk_bell_2")),
sound(BCUtil.modLoc("desk_bell_3")),
sound(BCUtil.modLoc("desk_bell_4"))
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import com.github.minecraftschurlimods.bibliocraft.content.clipboard.ClipboardItemSyncPacket;
import com.github.minecraftschurlimods.bibliocraft.init.BCEntities;
import com.github.minecraftschurlimods.bibliocraft.init.BCRegistries;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.data.BlockFamilies;
import net.minecraft.data.BlockFamily;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModList;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.event.lifecycle.FMLConstructModEvent;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;

Expand Down Expand Up @@ -61,16 +59,11 @@ private static void registerBibliocraftWoodTypes(RegisterBibliocraftWoodTypesEve
registerVanilla(event, WoodType.CHERRY, Blocks.CHERRY_PLANKS, BlockFamilies.CHERRY_PLANKS);
}

@SubscribeEvent
private static void registerCapabilities(RegisterCapabilitiesEvent event) {
//event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, BCBlockEntities.BOOKCASE.get(), (be, dir) -> be.getBlockState().getValue(BookcaseBlock.FACING) != dir ? new InvWrapper(be) : null);
}

/**
* Private helper for registering the vanilla variants.
*/
private static void registerVanilla(RegisterBibliocraftWoodTypesEvent event, WoodType woodType, Block planks, BlockFamily family) {
event.register(ResourceLocation.fromNamespaceAndPath("minecraft", woodType.name()), woodType, () -> BlockBehaviour.Properties.ofFullCopy(planks), ResourceLocation.fromNamespaceAndPath("minecraft", "block/" + woodType.name() + "_planks"), family);
event.register(BCUtil.mcLoc(woodType.name()), woodType, () -> BlockBehaviour.Properties.ofFullCopy(planks), BCUtil.mcLoc("block/" + woodType.name() + "_planks"), family);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void generateRecipesFor(RecipeOutput output, BibliocraftWoodType woodType
.define('#', Tags.Items.INGOTS_IRON)
.save(output, ResourceLocation.fromNamespaceAndPath(modId, prefix + "tool_rack"));
for (DyeColor color : DyeColor.values()) {
Item wool = BuiltInRegistries.ITEM.get(ResourceLocation.withDefaultNamespace(color.getName() + "_wool"));
Item wool = BuiltInRegistries.ITEM.get(BCUtil.mcLoc(color.getName() + "_wool"));
prefix = "color/" + color.getSerializedName() + "/wood/" + woodType.getRegistrationPrefix() + "/";
shapedRecipe(BCItems.DISPLAY_CASE.get(woodType, color), woodType)
.pattern("SGS")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.github.minecraftschurlimods.bibliocraft.client;

import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;

public class EmptyEntityRenderer extends EntityRenderer<Entity> {
private static final ResourceLocation TEXTURE = ResourceLocation.withDefaultNamespace("missingno");
private static final ResourceLocation TEXTURE = BCUtil.mcLoc("missingno");

public EmptyEntityRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeColor;
Expand All @@ -34,8 +33,8 @@
import java.util.Objects;

public class TableBER implements BlockEntityRenderer<TableBlockEntity> {
private static final RenderType MAP_BACKGROUND = RenderType.text(ResourceLocation.withDefaultNamespace("textures/map/map_background.png"));
private static final RenderType MAP_BACKGROUND_CHECKERBOARD = RenderType.text(ResourceLocation.withDefaultNamespace("textures/map/map_background_checkerboard.png"));
private static final RenderType MAP_BACKGROUND = RenderType.text(BCUtil.mcLoc("textures/map/map_background.png"));
private static final RenderType MAP_BACKGROUND_CHECKERBOARD = RenderType.text(BCUtil.mcLoc("textures/map/map_background_checkerboard.png"));
private static final Map<TableBlock.Type, Map<DyeColor, BakedModel>> CLOTH_MAP = new HashMap<>();
private static final RandomSource RANDOM = RandomSource.create();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.minecraftschurlimods.bibliocraft.init;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
Expand All @@ -16,7 +16,7 @@
@SuppressWarnings("unused")
public interface BCCreativeTabs {
Supplier<CreativeModeTab> BIBLIOCRAFT = BCRegistries.CREATIVE_TABS.register(BibliocraftApi.MOD_ID, () -> CreativeModeTab.builder()
.icon(() -> new ItemStack(BCItems.BOOKCASE.get(BibliocraftApi.getWoodTypeRegistry().get(ResourceLocation.fromNamespaceAndPath("minecraft", "oak"))))) //fixme
.icon(() -> new ItemStack(BCItems.BOOKCASE.get(BibliocraftApi.getWoodTypeRegistry().get(BCUtil.mcLoc("oak")))))
.title(Component.translatable("itemGroup." + BibliocraftApi.MOD_ID))
.withSearchBar()
.displayItems((display, output) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class BCUtil {
* @return A {@link ResourceLocation} with the "minecraft" namespace and the given path.
*/
public static ResourceLocation mcLoc(String path) {
return ResourceLocation.fromNamespaceAndPath("minecraft", path);
return ResourceLocation.withDefaultNamespace(path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
* Utility class holding various helper methods specifically for datagen.
*/
public final class DatagenUtil {
public static final Map<DyeColor, ResourceLocation> GLASS_TEXTURES = Util.make(new HashMap<>(), map -> Arrays.stream(DyeColor.values()).forEach(color -> map.put(color, ResourceLocation.withDefaultNamespace("block/" + color.getName() + "_stained_glass"))));
public static final Map<DyeColor, ResourceLocation> WOOL_TEXTURES = Util.make(new HashMap<>(), map -> Arrays.stream(DyeColor.values()).forEach(color -> map.put(color, ResourceLocation.withDefaultNamespace("block/" + color.getName() + "_wool"))));
public static final Map<DyeColor, ResourceLocation> GLASS_TEXTURES = Util.make(new HashMap<>(), map -> Arrays.stream(DyeColor.values()).forEach(color -> map.put(color, BCUtil.mcLoc("block/" + color.getName() + "_stained_glass"))));
public static final Map<DyeColor, ResourceLocation> WOOL_TEXTURES = Util.make(new HashMap<>(), map -> Arrays.stream(DyeColor.values()).forEach(color -> map.put(color, BCUtil.mcLoc("block/" + color.getName() + "_wool"))));

/**
* @param s The string to create a translation for.
Expand Down

0 comments on commit 9985048

Please sign in to comment.