Skip to content

Commit

Permalink
Some more porting
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Aug 19, 2024
1 parent 553e595 commit afe909e
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.client.resources.IndexedAssetSource;
import net.minecraft.data.DataProvider;
import net.minecraft.server.packs.FilePackResources;
import net.minecraft.server.packs.PackLocationInfo;
import net.minecraft.server.packs.PathPackResources;
import net.minecraft.server.packs.repository.ServerPacksSource;
import net.minecraft.server.packs.resources.MultiPackResourceManager;
Expand Down Expand Up @@ -173,7 +174,7 @@ private ResourceManager getManager(PackType packType) {
}

private ResourceLocation getLocation(ResourceLocation base, String suffix, String prefix) {
return new ResourceLocation(base.getNamespace(), prefix + "/" + base.getPath() + suffix);
return ResourceLocation.fromNamespaceAndPath(base.getNamespace(), prefix + "/" + base.getPath() + suffix);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import com.google.common.collect.Sets;

import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;
Expand All @@ -15,24 +17,24 @@
import net.minecraft.world.level.storage.loot.LootTable;

public abstract class ModdedBlockLootSubProvider extends BlockLootSubProvider {
protected ModdedBlockLootSubProvider(Set<Item> set, FeatureFlagSet featureFlagSet) {
super(set, featureFlagSet);
protected ModdedBlockLootSubProvider(Set<Item> set, FeatureFlagSet featureFlagSet, HolderLookup.Provider provider) {
super(set, featureFlagSet, provider);
}

@Override
public void generate(BiConsumer<ResourceLocation, LootTable.Builder> biConsumer) {
public void generate(BiConsumer<ResourceKey<LootTable>, LootTable.Builder> biConsumer) {
this.generate();
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
Set<ResourceKey<LootTable>> set = Sets.newHashSet();

for(Block block : getKnownBlocks()) {
ResourceLocation resourceLocation = block.getLootTable();
if (resourceLocation != BuiltInLootTables.EMPTY && set.add(resourceLocation)) {
LootTable.Builder builder6 = map.remove(resourceLocation);
ResourceKey<LootTable> resourceKey = block.getLootTable();
if (resourceKey != BuiltInLootTables.EMPTY && set.add(resourceKey)) {
LootTable.Builder builder6 = map.remove(resourceKey);
if (builder6 == null) {
throw new IllegalStateException(String.format("Missing loottable '%s' for '%s'", resourceLocation, BuiltInRegistries.BLOCK.getKey(block)));
throw new IllegalStateException(String.format("Missing loottable '%s' for '%s'", resourceKey, BuiltInRegistries.BLOCK.getKey(block)));
}

biConsumer.accept(resourceLocation, builder6);
biConsumer.accept(resourceKey, builder6);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected static SoundDefinition.Sound sound(final ResourceLocation name) {
* @param type The type of sound to create.
*/
protected static SoundDefinition.Sound sound(final String name, final SoundDefinition.SoundType type) {
return sound(new ResourceLocation(name), type);
return sound(ResourceLocation.parse(name), type);
}

/**
Expand All @@ -112,7 +112,7 @@ protected static SoundDefinition.Sound sound(final String name, final SoundDefin
* @param name The name of the sound to create.
*/
protected static SoundDefinition.Sound sound(final String name) {
return sound(new ResourceLocation(name));
return sound(ResourceLocation.parse(name));
}

// Addition methods
Expand Down Expand Up @@ -169,7 +169,7 @@ protected void add(final ResourceLocation soundEvent, final SoundDefinition defi
* @param definition The {@link SoundDefinition} that defines the given event.
*/
protected void add(final String soundEvent, final SoundDefinition definition) {
this.add(new ResourceLocation(soundEvent), definition);
this.add(ResourceLocation.parse(soundEvent), definition);
}

private void addSounds(final String soundEvent, final SoundDefinition definition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
* atlases used in vanilla Minecraft</p>
*/
public abstract class SpriteSourceProvider extends JsonCodecProvider<List<SpriteSource>> {
protected static final ResourceLocation BLOCKS_ATLAS = new ResourceLocation("blocks");
protected static final ResourceLocation BANNER_PATTERNS_ATLAS = new ResourceLocation("banner_patterns");
protected static final ResourceLocation BEDS_ATLAS = new ResourceLocation("beds");
protected static final ResourceLocation CHESTS_ATLAS = new ResourceLocation("chests");
protected static final ResourceLocation SHIELD_PATTERNS_ATLAS = new ResourceLocation("shield_patterns");
protected static final ResourceLocation SHULKER_BOXES_ATLAS = new ResourceLocation("shulker_boxes");
protected static final ResourceLocation SIGNS_ATLAS = new ResourceLocation("signs");
protected static final ResourceLocation MOB_EFFECTS_ATLAS = new ResourceLocation("mob_effects");
protected static final ResourceLocation PAINTINGS_ATLAS = new ResourceLocation("paintings");
protected static final ResourceLocation PARTICLES_ATLAS = new ResourceLocation("particles");
protected static final ResourceLocation BLOCKS_ATLAS = ResourceLocation.withDefaultNamespace("blocks");
protected static final ResourceLocation BANNER_PATTERNS_ATLAS = ResourceLocation.withDefaultNamespace("banner_patterns");
protected static final ResourceLocation BEDS_ATLAS = ResourceLocation.withDefaultNamespace("beds");
protected static final ResourceLocation CHESTS_ATLAS = ResourceLocation.withDefaultNamespace("chests");
protected static final ResourceLocation SHIELD_PATTERNS_ATLAS = ResourceLocation.withDefaultNamespace("shield_patterns");
protected static final ResourceLocation SHULKER_BOXES_ATLAS = ResourceLocation.withDefaultNamespace("shulker_boxes");
protected static final ResourceLocation SIGNS_ATLAS = ResourceLocation.withDefaultNamespace("signs");
protected static final ResourceLocation MOB_EFFECTS_ATLAS = ResourceLocation.withDefaultNamespace("mob_effects");
protected static final ResourceLocation PAINTINGS_ATLAS = ResourceLocation.withDefaultNamespace("paintings");
protected static final ResourceLocation PARTICLES_ATLAS = ResourceLocation.withDefaultNamespace("particles");

private final Map<ResourceLocation, SourceList> atlases = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;

import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerEntity;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -37,25 +38,25 @@ public CustomSlime(EntityType<? extends Slime> entityType, Level level) {

@Override
public void writeSpawnData(RegistryFriendlyByteBuf buf) {
buf.writeItem(item.stack);
ItemStack.STREAM_CODEC.encode(buf, item.stack);
}

@Override
public void readSpawnData(RegistryFriendlyByteBuf buf) {
item.stack = buf.readItem();
item.stack = ItemStack.STREAM_CODEC.decode(buf);
}

@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
nbt.put("Item", item.stack.save(new CompoundTag()));
nbt.put("Item", item.stack.save(registryAccess()));
}

@Override
public void readAdditionalSaveData(CompoundTag nbt) {
super.readAdditionalSaveData(nbt);
if (nbt.contains("Item", Tag.TAG_COMPOUND))
item.stack = ItemStack.of(nbt.getCompound("Item"));
item.stack = ItemStack.parseOptional(registryAccess(), nbt.getCompound("Item"));
}

@Override
Expand All @@ -67,7 +68,7 @@ public void tick() {

@Override
public boolean spawnCustomParticles() {
playSound(SoundEvents.GENERIC_EXPLODE, this.getSoundVolume(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F);
playSound(SoundEvents.GENERIC_EXPLODE.value(), this.getSoundVolume(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F);
return true;
}

Expand All @@ -89,7 +90,7 @@ public OrbitingItem(CustomSlime parent, Item item) {
}

@Override
protected void defineSynchedData() {
protected void defineSynchedData(SynchedEntityData.Builder builder) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PortingLibEntityTestmod implements ModInitializer {
public void onInitialize() {
Registry.register(
BuiltInRegistries.ENTITY_TYPE,
new ResourceLocation("porting_lib", "custom_slime"),
ResourceLocation.fromNamespaceAndPath("porting_lib", "custom_slime"),
CUSTOM_SLIME
);
FabricDefaultAttributeRegistry.register(CUSTOM_SLIME, Monster.createMonsterAttributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public DynamicFluidContainerModel read(JsonObject jsonObject, JsonDeserializatio
if (!jsonObject.has("fluid"))
throw new RuntimeException("Bucket model requires 'fluid' value.");

ResourceLocation fluidName = new ResourceLocation(jsonObject.get("fluid").getAsString());
ResourceLocation fluidName = ResourceLocation.parse(jsonObject.get("fluid").getAsString());

Fluid fluid = BuiltInRegistries.FLUID.get(fluidName);

Expand Down Expand Up @@ -223,7 +223,7 @@ public BakedModel resolve(BakedModel originalModel, ItemStack stack, @Nullable C

if (!cache.containsKey(name)) {
DynamicFluidContainerModel unbaked = this.parent.withFluid(fluid);
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0, this, new ResourceLocation("forge:bucket_override"), false);
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0, this, ResourceLocation.parse("neoforge:bucket_override"), false);
cache.put(name, bakedModel);
return bakedModel;
}
Expand All @@ -240,7 +240,7 @@ public static class Colors implements ItemColor {
public int getColor(@NotNull ItemStack stack, int tintIndex) {
if (tintIndex != 1) return 0xFFFFFFFF;
return TransferUtil.getFluidContained(stack)
.map(fluidStack -> FluidVariantRendering.getColor(fluidStack.getType()))
.map(fluidStack -> FluidVariantRendering.getColor(fluidStack.getVariant()))
.orElse(0xFFFFFFFF);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void onInitializeClient() {

loaders.put(PortingLib.id("fluid_container"), DynamicFluidContainerModel.Loader.INSTANCE);

loaders.put(new ResourceLocation("forge", "bucket"), DynamicFluidContainerModel.Loader.INSTANCE_DEPRECATED);
loaders.put(ResourceLocation.fromNamespaceAndPath("neoforge", "bucket"), DynamicFluidContainerModel.Loader.INSTANCE_DEPRECATED);
});
BlockModel.GSON = BlockModel.GSON.newBuilder()
.registerTypeAdapter(Transformation.class, new TransformationHelper.Deserializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public RenderMaterial deserialize(JsonElement json, Type typeOfT, JsonDeserializ
throw new JsonParseException("The Fabric Rendering API is not available. If you have Sodium, install Indium!");
MaterialFinder finder = renderer.materialFinder();
JsonObject obj = json.getAsJsonObject();
forEachSpriteIndex(obj, "blendMode", (spriteIndex, jsonElement) -> finder.blendMode(spriteIndex, BlendMode.fromRenderLayer(RenderTypeUtil.get(new ResourceLocation(jsonElement.getAsString())))));
forEachSpriteIndex(obj, "blendMode", (spriteIndex, jsonElement) -> finder.blendMode(spriteIndex, BlendMode.fromRenderLayer(RenderTypeUtil.get(ResourceLocation.parse(jsonElement.getAsString())))));
forEachSpriteIndex(obj, "disableColorIndex", (spriteIndex, jsonElement) -> finder.disableColorIndex(spriteIndex, jsonElement.getAsBoolean()));
forEachSpriteIndex(obj, "disableDiffuse", (spriteIndex, jsonElement) -> finder.disableDiffuse(spriteIndex, jsonElement.getAsBoolean()));
forEachSpriteIndex(obj, "disableAo", (spriteIndex, jsonElement) -> finder.disableAo(spriteIndex, jsonElement.getAsBoolean()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ResourceLocation getUncheckedLocation() {
public static class UncheckedModelFile extends ModelFile {

public UncheckedModelFile(String location) {
this(new ResourceLocation(location));
this(ResourceLocation.parse(location));
}
public UncheckedModelFile(ResourceLocation location) {
super(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public ItemModelProvider itemModels() {
}

public ResourceLocation modLoc(String name) {
return new ResourceLocation(modid, name);
return ResourceLocation.fromNamespaceAndPath(modid, name);
}

public ResourceLocation mcLoc(String name) {
return new ResourceLocation(name);
return ResourceLocation.withDefaultNamespace(name);
}

private ResourceLocation key(Block block) {
Expand All @@ -161,11 +161,11 @@ private String name(Block block) {

public ResourceLocation blockTexture(Block block) {
ResourceLocation name = key(block);
return new ResourceLocation(name.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + name.getPath());
return ResourceLocation.fromNamespaceAndPath(name.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + name.getPath());
}

private ResourceLocation extend(ResourceLocation rl, String suffix) {
return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix);
return ResourceLocation.fromNamespaceAndPath(rl.getNamespace(), rl.getPath() + suffix);
}

public ModelFile cubeAll(Block block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ItemModelBuilder basicItem(ResourceLocation item)
{
return getBuilder(item.toString())
.parent(new ModelFile.UncheckedModelFile("item/generated"))
.texture("layer0", new ResourceLocation(item.getNamespace(), "item/" + item.getPath()));
.texture("layer0", ResourceLocation.fromNamespaceAndPath(item.getNamespace(), "item/" + item.getPath()));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private BlockModel addModelRenderType(BlockModel model, JsonElement jsonElement,
Renderer renderer = RendererAccess.INSTANCE.getRenderer();
if (renderer != null) {
String typeName = GsonHelper.getAsString(modelJson, "render_type");
BlendMode blendMode = BlendMode.fromRenderLayer(RenderTypeUtil.get(new ResourceLocation(typeName)));
BlendMode blendMode = BlendMode.fromRenderLayer(RenderTypeUtil.get(ResourceLocation.parse(typeName)));
((BlockModelExtensions) model).port_lib$setBlendMode(blendMode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public static RenderType get(ResourceLocation name) {

static {
var renderTypes = new HashMap<ResourceLocation, RenderType>();
renderTypes.put(new ResourceLocation("solid"), RenderType.solid());
renderTypes.put(new ResourceLocation("cutout"), RenderType.cutout());
renderTypes.put(ResourceLocation.withDefaultNamespace("solid"), RenderType.solid());
renderTypes.put(ResourceLocation.withDefaultNamespace("cutout"), RenderType.cutout());
// Generally entity/item rendering shouldn't use mipmaps, so cutout_mipped has them off by default. To enforce them, use cutout_mipped_all.
renderTypes.put(new ResourceLocation("cutout_mipped"), RenderType.cutoutMipped());
renderTypes.put(new ResourceLocation("cutout_mipped_all"), RenderType.cutoutMipped());
renderTypes.put(new ResourceLocation("translucent"), RenderType.translucent());
renderTypes.put(new ResourceLocation("tripwire"), RenderType.tripwire());
renderTypes.put(ResourceLocation.withDefaultNamespace("cutout_mipped"), RenderType.cutoutMipped());
renderTypes.put(ResourceLocation.withDefaultNamespace("cutout_mipped_all"), RenderType.cutoutMipped());
renderTypes.put(ResourceLocation.withDefaultNamespace("translucent"), RenderType.translucent());
renderTypes.put(ResourceLocation.withDefaultNamespace("tripwire"), RenderType.tripwire());
RENDER_TYPES = ImmutableMap.copyOf(renderTypes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import io.github.fabricators_of_create.porting_lib.core.PortingLib;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.item.v1.EquipmentSlotProvider;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class PortingLibModelsTestmod implements ModInitializer {
public static final Item DERPY_HELMET = new Item(new FabricItemSettings().equipmentSlot(stack -> EquipmentSlot.HEAD));
public static final Item STONE_2 = new Item(new FabricItemSettings());
public static final Block NOT_GLASS = new Block(FabricBlockSettings.copyOf(Blocks.GLASS));
public static final Item DERPY_HELMET = new Item(new Item.Properties().equipmentSlot((entity, stack) -> EquipmentSlot.HEAD));
public static final Item STONE_2 = new Item(new Item.Properties());
public static final Block NOT_GLASS = new Block(BlockBehaviour. Properties. ofFullCopy(Blocks.GLASS));

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PortingLibModelsTestmodClient implements ClientModInitializer {
public void onInitializeClient() {
ModelResourceLocation location = new ModelResourceLocation(BuiltInRegistries.ITEM.getKey(PortingLibModelsTestmod.DERPY_HELMET), "inventory");
ModelLoadingPlugin.register(pluginCtx -> pluginCtx.modifyModelAfterBake().register(
(model, ctx) -> ctx.id().equals(location) ? new DerpyItemModel(model) : model
(model, ctx) -> ctx.topLevelId().equals(location) ? new DerpyItemModel(model) : model
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private JsonObject tryLoadModelJson(ResourceLocation id, Resource resource) {

private Either<ModelSettings, RuntimeException> tryReadSettings(JsonObject json) {
try {
ResourceLocation objLocation = new ResourceLocation(GsonHelper.getAsString(json, "model"));
ResourceLocation objLocation = ResourceLocation.parse(GsonHelper.getAsString(json, "model"));
return Either.left(new ModelSettings(objLocation,
GsonHelper.getAsBoolean(json, "automaticCulling", true),
GsonHelper.getAsBoolean(json, "shadeQuads", true),
Expand Down Expand Up @@ -151,7 +151,7 @@ public UnbakedModel resolveModel(Context context) {
if (json != null) {
return tryReadSettings(json).map(settings -> {
try {
return loadModel(resourceManager.getResourceOrThrow(new ResourceLocation(GsonHelper.getAsString(json, "model"))), settings);
return loadModel(resourceManager.getResourceOrThrow(ResourceLocation.parse(GsonHelper.getAsString(json, "model"))), settings);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ObjMaterialLibrary(ObjTokenizer reader) throws IOException {
break;
}
case "texture":
currentMaterial.texture = new ResourceLocation(line[1]);
currentMaterial.texture = ResourceLocation.parse(line[1]);
break;

case "Ka":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static ObjModel parse(ObjTokenizer tokenizer, ModelSettings settings) thr
if (materialLibraryOverrideLocation != null) {
String lib = materialLibraryOverrideLocation;
if (lib.contains(":")) {
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(lib));
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.parse(lib));
} else {
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(modelDomain, modelPath + lib));
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.withDefaultNamespace(modelDomain, modelPath + lib));
}
}

Expand All @@ -64,9 +64,9 @@ public static ObjModel parse(ObjTokenizer tokenizer, ModelSettings settings) thr

String lib = line[1];
if (lib.contains(":")) {
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(lib));
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.parse(lib));
} else {
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(modelDomain, modelPath + lib));
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.withDefaultNamespace(modelDomain, modelPath + lib));
}
break;
}
Expand Down
Loading

0 comments on commit afe909e

Please sign in to comment.