Skip to content

Commit

Permalink
add BCUtil#modLoc and #mcLoc, optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Apr 9, 2024
1 parent 6839549 commit 1ca02a8
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.neoforged.fml.event.lifecycle.FMLConstructModEvent;
import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;

import java.util.Objects;

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

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftDatagenHelper;
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftWoodType;
import com.github.minecraftschurlimods.bibliocraft.client.model.TableModel;
Expand All @@ -11,6 +10,7 @@
import com.github.minecraftschurlimods.bibliocraft.init.BCBlocks;
import com.github.minecraftschurlimods.bibliocraft.init.BCItems;
import com.github.minecraftschurlimods.bibliocraft.init.BCTags;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import com.github.minecraftschurlimods.bibliocraft.util.DatagenUtil;
import com.github.minecraftschurlimods.bibliocraft.util.init.ColoredWoodTypeDeferredHolder;
import com.github.minecraftschurlimods.bibliocraft.util.init.WoodTypeDeferredHolder;
Expand Down Expand Up @@ -155,7 +155,7 @@ public void generateBlockStatesFor(BlockStateProvider provider, BibliocraftWoodT
.build());
DatagenUtil.horizontalBlockModel(provider, BCBlocks.SEAT_BACK.holder(woodType, color), state -> {
String suffix = state.getValue(SeatBackBlock.TYPE).getSerializedName() + "_seat_back";
return models.withExistingParent(color.getName() + "_" + woodType.getRegistrationPrefix() + "_" + suffix, new ResourceLocation(BibliocraftApi.MOD_ID, "block/template/seat/" + suffix)).texture("texture", woodType.texture()).texture("color", DatagenUtil.WOOL_TEXTURES.get(color));
return models.withExistingParent(color.getName() + "_" + woodType.getRegistrationPrefix() + "_" + suffix, BCUtil.modLoc("block/template/seat/" + suffix)).texture("texture", woodType.texture()).texture("color", DatagenUtil.WOOL_TEXTURES.get(color));
}, true);
}
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public void generateRecipesFor(RecipeOutput output, BibliocraftWoodType woodType
* @return A new {@link ResourceLocation} with Bibliocraft's namespace and the given path.
*/
private static ResourceLocation bcLoc(String path) {
return new ResourceLocation(BibliocraftApi.MOD_ID, path);
return BCUtil.modLoc(path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.github.minecraftschurlimods.bibliocraft.init.BCMenus;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.client.renderer.entity.ArmorStandRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
Expand Down Expand Up @@ -51,7 +50,7 @@ private static void registerMenuScreens(RegisterMenuScreensEvent event) {
private static void registerAdditional(ModelEvent.RegisterAdditional event) {
for (TableBlock.Type type : TableBlock.Type.values()) {
for (DyeColor color : DyeColor.values()) {
event.register(new ResourceLocation(BibliocraftApi.MOD_ID, "block/table_cloth_" + type.getSerializedName() + "_" + color.getSerializedName()));
event.register(BCUtil.modLoc("block/table_cloth_" + type.getSerializedName() + "_" + color.getSerializedName()));
}
}
}
Expand All @@ -63,8 +62,8 @@ private static void bakingCompleted(ModelEvent.BakingCompleted event) {

@SubscribeEvent
private static void registerGeometryLoaders(ModelEvent.RegisterGeometryLoaders event) {
event.register(new ResourceLocation(BibliocraftApi.MOD_ID, "bookcase"), BookcaseModel.LOADER);
event.register(new ResourceLocation(BibliocraftApi.MOD_ID, "table"), TableModel.LOADER);
event.register(BCUtil.modLoc("bookcase"), BookcaseModel.LOADER);
event.register(BCUtil.modLoc("table"), TableModel.LOADER);
}

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

import com.github.minecraftschurlimods.bibliocraft.content.bookcase.BookcaseBlockEntity;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.minecraftschurlimods.bibliocraft.client.model;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.content.table.TableBlock;
import com.github.minecraftschurlimods.bibliocraft.content.table.TableBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -62,7 +62,7 @@ public static void rebuildClothModelCache() {
for (TableBlock.Type type : TableBlock.Type.values()) {
Map<DyeColor, BakedModel> map = new HashMap<>();
for (DyeColor color : DyeColor.values()) {
map.put(color, models.getModel(new ResourceLocation(BibliocraftApi.MOD_ID, "block/table_cloth_" + type.getSerializedName() + "_" + color.getSerializedName())));
map.put(color, models.getModel(BCUtil.modLoc("block/table_cloth_" + type.getSerializedName() + "_" + color.getSerializedName())));
}
CLOTH_MAP.put(type, map);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public static class Builder extends CustomLoaderBuilder<BlockModelBuilder> {
private ResourceLocation particle;

public Builder(BlockModelBuilder parent, ExistingFileHelper existingFileHelper) {
super(new ResourceLocation(BibliocraftApi.MOD_ID, "table"), parent, existingFileHelper, false);
super(BCUtil.modLoc("table"), parent, existingFileHelper, false);
}

public Builder withModelForType(TableBlock.Type type, JsonObject model) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
package com.github.minecraftschurlimods.bibliocraft.client.screen;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.content.bookcase.BookcaseMenu;
import com.github.minecraftschurlimods.bibliocraft.content.cookiejar.CookieJarMenu;
import com.github.minecraftschurlimods.bibliocraft.content.fancyarmorstand.FancyArmorStandMenu;
import com.github.minecraftschurlimods.bibliocraft.content.label.LabelMenu;
import com.github.minecraftschurlimods.bibliocraft.content.potionshelf.PotionShelfMenu;
import com.github.minecraftschurlimods.bibliocraft.content.shelf.ShelfMenu;
import com.github.minecraftschurlimods.bibliocraft.content.toolrack.ToolRackMenu;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

public final class BCMenuScreens {
public static class Bookcase extends BCMenuScreen<BookcaseMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/bookcase.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/bookcase.png");

public Bookcase(BookcaseMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
}
}

public static class CookieJar extends BCMenuScreen<CookieJarMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/cookie_jar.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/cookie_jar.png");

public CookieJar(CookieJarMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
}
}

public static class FancyArmorStand extends BCMenuScreen<FancyArmorStandMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/fancy_armor_stand.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/fancy_armor_stand.png");

public FancyArmorStand(FancyArmorStandMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
}
}

public static class Label extends BCMenuScreen<LabelMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/label.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/label.png");

public Label(LabelMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
}
}

public static class PotionShelf extends BCMenuScreen<PotionShelfMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/potion_shelf.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/potion_shelf.png");

public PotionShelf(PotionShelfMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
}
}

public static class Shelf extends BCMenuScreen<ShelfMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/shelf.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/shelf.png");

public Shelf(ShelfMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
}
}

public static class ToolRack extends BCMenuScreen<ToolRackMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/shelf.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/shelf.png");

public ToolRack(ToolRackMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.minecraftschurlimods.bibliocraft.client.screen;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.content.clipboard.CheckboxState;
import com.github.minecraftschurlimods.bibliocraft.content.clipboard.ClipboardAttachment;
import com.github.minecraftschurlimods.bibliocraft.content.clipboard.ClipboardItemSyncPacket;
import com.github.minecraftschurlimods.bibliocraft.content.clipboard.ClipboardPage;
import com.github.minecraftschurlimods.bibliocraft.init.BCAttachments;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
Expand All @@ -26,7 +26,7 @@
import java.util.function.Consumer;

public class ClipboardScreen extends Screen {
private static final ResourceLocation BACKGROUND = new ResourceLocation(BibliocraftApi.MOD_ID, "textures/gui/clipboard.png");
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/clipboard.png");
private final ItemStack stack;
private final ClipboardAttachment data;
private final CheckboxButton[] checkboxes = new CheckboxButton[ClipboardPage.LINES];
Expand Down Expand Up @@ -143,8 +143,8 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float par
}

private static class CheckboxButton extends Button {
private static final ResourceLocation CHECK_TEXTURE = new ResourceLocation(BibliocraftApi.MOD_ID, "check");
private static final ResourceLocation X_TEXTURE = new ResourceLocation(BibliocraftApi.MOD_ID, "x");
private static final ResourceLocation CHECK_TEXTURE = BCUtil.modLoc("check");
private static final ResourceLocation X_TEXTURE = BCUtil.modLoc("x");
private CheckboxState state = CheckboxState.EMPTY;

public CheckboxButton(int x, int y, OnPress onPress) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.minecraftschurlimods.bibliocraft.content.clipboard;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.init.BCAttachments;
import com.github.minecraftschurlimods.bibliocraft.init.BCItems;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
Expand All @@ -14,7 +14,7 @@
import java.util.Objects;

public record ClipboardItemSyncPacket(CompoundTag tag) implements CustomPacketPayload {
public static final ResourceLocation ID = new ResourceLocation(BibliocraftApi.MOD_ID, "clipboard_item_sync");
public static final ResourceLocation ID = BCUtil.modLoc("clipboard_item_sync");

public ClipboardItemSyncPacket(FriendlyByteBuf buf) {
this(Objects.requireNonNull(buf.readNbt()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCEntityBlock;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCWaterloggedBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BarrelBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.ContainerOpenersCounter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.github.minecraftschurlimods.bibliocraft.init.BCBlockEntities;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.WoolCarpetBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.model.data.ModelData;
import net.neoforged.neoforge.client.model.data.ModelProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import net.minecraft.world.level.block.Block;
import net.neoforged.neoforge.registries.DeferredItem;

import java.util.function.Supplier;

public interface BCItems {
Item.Properties PROPERTIES = new Item.Properties();

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

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import net.minecraft.resources.ResourceLocation;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.sounds.SoundEvent;

import java.util.function.Supplier;

public interface BCSoundEvents {
Supplier<SoundEvent> DESK_BELL = BCRegistries.SOUND_EVENTS.register("desk_bell", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(BibliocraftApi.MOD_ID, "desk_bell")));
Supplier<SoundEvent> DESK_BELL = BCRegistries.SOUND_EVENTS.register("desk_bell", () -> SoundEvent.createVariableRangeEvent(BCUtil.modLoc("desk_bell")));

/**
* Empty method, called by {@link BCRegistries#init(net.neoforged.bus.api.IEventBus)} to classload this class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.github.minecraftschurlimods.bibliocraft.init;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
Expand All @@ -26,7 +25,7 @@ interface Blocks {
* @return A {@link TagKey<Block>} with this mod's namespace and the given path.
*/
static TagKey<Block> tag(String name) {
return TagKey.create(BuiltInRegistries.BLOCK.key(), new ResourceLocation(BibliocraftApi.MOD_ID, name));
return TagKey.create(BuiltInRegistries.BLOCK.key(), BCUtil.modLoc(name));
}
}

Expand Down Expand Up @@ -58,7 +57,7 @@ interface Items {
* @return A {@link TagKey<Item>} with this mod's namespace and the given path.
*/
static TagKey<Item> tag(String name) {
return TagKey.create(BuiltInRegistries.ITEM.key(), new ResourceLocation(BibliocraftApi.MOD_ID, name));
return TagKey.create(BuiltInRegistries.ITEM.key(), BCUtil.modLoc(name));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
Expand All @@ -23,6 +24,22 @@ public final class BCUtil {
private static final String TAG_COLOR = "color";
private static final String TAG_DISPLAY = "display";

/**
* @param path The path to use.
* @return A {@link ResourceLocation} with the "minecraft" namespace and the given path.
*/
public static ResourceLocation mcLoc(String path) {
return new ResourceLocation("minecraft", path);
}

/**
* @param path The path to use.
* @return A {@link ResourceLocation} with the "bibliocraft" namespace and the given path.
*/
public static ResourceLocation modLoc(String path) {
return BCUtil.modLoc(path);
}

/**
* Merges a given collection with the given elements. Does not mutate the original collection.
*
Expand Down

0 comments on commit 1ca02a8

Please sign in to comment.