Skip to content

Commit

Permalink
Merge pull request Devan-Kerman#79 from PTOM76/1.19.3
Browse files Browse the repository at this point in the history
Port to 1.19.3
  • Loading branch information
Devan-Kerman authored Dec 16, 2022
2 parents 6a41b8b + 38011e3 commit c6ed7d0
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 115 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'maven-publish'
id "me.shedaniel.unified-publishing" version "0.1.+"
}
Expand Down Expand Up @@ -72,7 +72,7 @@ if(file.exists()) {

unifiedPublishing {
project {
gameVersions = ["1.19"]
gameVersions = ["1.19.3"]
gameLoaders = ["fabric"]

mainPublication tasks.remapJar // Declares the publicated jar
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.19-rc2
yarn_mappings=1.19-rc2+build.1
loader_version=0.14.6
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.2
loader_version=0.14.11

# Fabric API
fabric_version=0.55.1+1.19
#Fabric api
fabric_version=0.68.1+1.19.3

# Mod Properties
mod_version=0.6.5
Expand Down
159 changes: 69 additions & 90 deletions src/main/java/net/devtech/arrp/impl/RuntimeResourcePackImpl.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
package net.devtech.arrp.impl;

import static java.lang.String.valueOf;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.IntUnaryOperator;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import javax.imageio.ImageIO;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -57,23 +17,41 @@
import net.devtech.arrp.json.loot.JPool;
import net.devtech.arrp.json.models.JModel;
import net.devtech.arrp.json.models.JTextures;
import net.devtech.arrp.json.recipe.JIngredient;
import net.devtech.arrp.json.recipe.JIngredients;
import net.devtech.arrp.json.recipe.JKeys;
import net.devtech.arrp.json.recipe.JPattern;
import net.devtech.arrp.json.recipe.JRecipe;
import net.devtech.arrp.json.recipe.*;
import net.devtech.arrp.json.tags.JTag;
import net.devtech.arrp.util.CallableFunction;
import net.devtech.arrp.util.CountingInputStream;
import net.devtech.arrp.util.UnsafeByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.jetbrains.annotations.ApiStatus;

import net.minecraft.resource.AbstractFileResourcePack;
import net.minecraft.resource.InputSupplier;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.resource.metadata.ResourceMetadataReader;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.jetbrains.annotations.ApiStatus;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.IntUnaryOperator;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import static java.lang.String.valueOf;


/**
Expand Down Expand Up @@ -151,7 +129,7 @@ public class RuntimeResourcePackImpl implements RuntimeResourcePack, ResourcePac
private final Lock waiting = new ReentrantLock();
private final Map<Identifier, Supplier<byte[]>> data = new ConcurrentHashMap<>();
private final Map<Identifier, Supplier<byte[]>> assets = new ConcurrentHashMap<>();
private final Map<String, Supplier<byte[]>> root = new ConcurrentHashMap<>();
private final Map<List<String>, Supplier<byte[]>> root = new ConcurrentHashMap<>();
private final Map<Identifier, JLang> langMergable = new ConcurrentHashMap<>();

public RuntimeResourcePackImpl(Identifier id) {
Expand Down Expand Up @@ -241,7 +219,7 @@ public byte[] addResource(ResourceType type, Identifier path, byte[] data) {
@Override
public Future<byte[]> addAsyncRootResource(String path, CallableFunction<String, byte[]> data) {
Future<byte[]> future = EXECUTOR_SERVICE.submit(() -> data.get(path));
this.root.put(path, () -> {
this.root.put(Arrays.asList(path.split("/")), () -> {
try {
return future.get();
} catch(InterruptedException | ExecutionException e) {
Expand All @@ -253,12 +231,12 @@ public Future<byte[]> addAsyncRootResource(String path, CallableFunction<String,

@Override
public void addLazyRootResource(String path, BiFunction<RuntimeResourcePack, String, byte[]> data) {
this.root.put(path, new Memoized<>(data, path));
this.root.put(Arrays.asList(path.split("/")), new Memoized<>(data, path));
}

@Override
public byte[] addRootResource(String path, byte[] data) {
this.root.put(path, () -> data);
this.root.put(Arrays.asList(path.split("/")), () -> data);
return data;
}

Expand Down Expand Up @@ -322,8 +300,8 @@ public void dumpDirect(Path output) {
LOGGER.info("dumping " + this.id + "'s assets and data");
// data dump time
try {
for(Map.Entry<String, Supplier<byte[]>> e : this.root.entrySet()) {
Path root = output.resolve(e.getKey());
for(Map.Entry<List<String>, Supplier<byte[]>> e : this.root.entrySet()) {
Path root = output.resolve(String.join("/", e.getKey()));
Files.createDirectories(root.getParent());
Files.write(root, e.getValue().get());
}
Expand Down Expand Up @@ -357,7 +335,7 @@ public void load(Path dir) throws IOException {
this.load(path, this.data, Files.readAllBytes(file));
} else {
byte[] data = Files.readAllBytes(file);
this.root.put(s, () -> data);
this.root.put(Arrays.asList(s.split("/")), () -> data);
}
}
}
Expand All @@ -370,8 +348,8 @@ public void dump(File output) {
@Override
public void dump(ZipOutputStream zos) throws IOException {
this.lock();
for(Map.Entry<String, Supplier<byte[]>> entry : this.root.entrySet()) {
zos.putNextEntry(new ZipEntry(entry.getKey()));
for(Map.Entry<List<String>, Supplier<byte[]>> entry : this.root.entrySet()) {
zos.putNextEntry(new ZipEntry(String.join("/", entry.getKey())));
zos.write(entry.getValue().get());
zos.closeEntry();
}
Expand Down Expand Up @@ -405,7 +383,7 @@ public void load(ZipInputStream stream) throws IOException {
this.load(path, this.data, this.read(entry, stream));
} else {
byte[] data = this.read(entry, stream);
this.root.put(s, () -> data);
this.root.put(Arrays.asList(s.split("/")), () -> data);
}
}
}
Expand All @@ -418,27 +396,23 @@ public Identifier getId() {
/**
* pack.png and that's about it I think/hope
*
* @param fileName the name of the file, can't be a path tho
* @param segments the name of the file, can't be a path tho
* @return the pack.png image as a stream
*/
@Override
public InputStream openRoot(String fileName) {
if(!fileName.contains("/") && !fileName.contains("\\")) {
this.lock();
Supplier<byte[]> supplier = this.root.get(fileName);
if(supplier == null) {
this.waiting.unlock();
return null;
}
public InputSupplier<InputStream> openRoot(String... segments) {
this.lock();
Supplier<byte[]> supplier = this.root.get(Arrays.asList(segments));
if(supplier == null) {
this.waiting.unlock();
return new ByteArrayInputStream(supplier.get());
} else {
throw new IllegalArgumentException("File name can't be a path");
return null;
}
this.waiting.unlock();
return () -> new ByteArrayInputStream(supplier.get());
}

@Override
public InputStream open(ResourceType type, Identifier id) {
public InputSupplier<InputStream> open(ResourceType type, Identifier id) {
this.lock();
Supplier<byte[]> supplier = this.getSys(type).get(id);
if(supplier == null) {
Expand All @@ -447,31 +421,28 @@ public InputStream open(ResourceType type, Identifier id) {
return null;
}
this.waiting.unlock();
return new ByteArrayInputStream(supplier.get());
return () -> new ByteArrayInputStream(supplier.get());
}

@Override
public Collection<Identifier> findResources(
ResourceType type, String namespace, String prefix, Predicate<Identifier> allowedPathPredicate) {
public void findResources(
ResourceType type, String namespace, String prefix, ResultConsumer consumer) {
this.lock();
Set<Identifier> identifiers = new HashSet<>();
for(Identifier identifier : this.getSys(type).keySet()) {
if(identifier.getNamespace().equals(namespace) && identifier.getPath().startsWith(prefix) && allowedPathPredicate.test(identifier)) {
identifiers.add(identifier);
Supplier<byte[]> supplier = this.getSys(type).get(identifier);
if(supplier == null) {
LOGGER.warn("No resource found for " + identifier);
this.waiting.unlock();
continue;
}
InputSupplier<InputStream> inputSupplier = () -> new ByteArrayInputStream(supplier.get());
if(identifier.getNamespace().equals(namespace) && identifier.getPath().startsWith(prefix)) {
consumer.accept(identifier, inputSupplier);
}
}
this.waiting.unlock();
return identifiers;
}

@Override
public boolean contains(ResourceType type, Identifier id) {
this.lock();
boolean contains = this.getSys(type).containsKey(id);
this.waiting.unlock();
return contains;
}


@Override
public Set<String> getNamespaces(ResourceType type) {
this.lock();
Expand All @@ -485,7 +456,15 @@ public Set<String> getNamespaces(ResourceType type) {

@Override
public <T> T parseMetadata(ResourceMetadataReader<T> metaReader) {
InputStream stream = this.openRoot("pack.mcmeta");
InputStream stream = null;
try {
InputSupplier<InputStream> supplier = this.openRoot("pack.mcmeta");
if (supplier != null) {
stream = supplier.get();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
if(stream != null) {
return AbstractFileResourcePack.parseMetadata(metaReader, stream);
} else {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/net/devtech/arrp/json/lang/JLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -76,7 +77,7 @@ public JLang item(ItemStack stack, String name) {
*/
@Deprecated
public JLang item(Item item, String name) {
return this.object(Registry.ITEM, "item", item, name);
return this.object(Registries.ITEM, "item", item, name);
}

/**
Expand All @@ -92,11 +93,11 @@ public JLang blockRespect(Block block, String name) {
*/
@Deprecated
public JLang block(Block block, String name) {
return this.object(Registry.BLOCK, "block", block, name);
return this.object(Registries.BLOCK, "block", block, name);
}

public JLang fluid(Fluid fluid, String name) {
return this.object(Registry.FLUID, "fluid", fluid, name);
return this.object(Registries.FLUID, "fluid", fluid, name);
}

/**
Expand All @@ -112,7 +113,7 @@ public JLang entityRespect(EntityType<?> type, String name) {
*/
@Deprecated
public JLang entity(EntityType<?> type, String name) {
return this.object(Registry.ENTITY_TYPE, "entity_type", type, name);
return this.object(Registries.ENTITY_TYPE, "entity_type", type, name);
}

/**
Expand All @@ -128,7 +129,7 @@ public JLang enchantmentRespect(Enchantment enchantment, String name) {
*/
@Deprecated
public JLang enchantment(Enchantment enchantment, String name) {
return this.object(Registry.ENCHANTMENT, "enchantment", enchantment, name);
return this.object(Registries.ENCHANTMENT, "enchantment", enchantment, name);
}

public JLang item(Identifier item, String name) {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/net/devtech/arrp/json/recipe/JIngredient.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package net.devtech.arrp.json.recipe;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import net.minecraft.item.Item;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class JIngredient implements Cloneable {
protected String item;
Expand All @@ -24,7 +23,7 @@ public static JIngredient ingredient() {
}

public JIngredient item(Item item) {
return this.item(Registry.ITEM.getId(item).toString());
return this.item(Registries.ITEM.getId(item).toString());
}

public JIngredient item(String id) {
Expand Down
Loading

0 comments on commit c6ed7d0

Please sign in to comment.