Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
PTOM76 committed Dec 10, 2022
2 parents 3151b93 + 9a5a7cb commit c13e0eb
Showing 9 changed files with 136 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ repositories {
}
dependencies {
modImplementation("net.devtech:arrp:0.6.2")
modImplementation("net.devtech:arrp:0.6.4")
// I never break backwards compatibility, so just fetching the latest version should be fine
// modImplementation("net.devtech:arrp:0.+")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ loader_version=0.14.11
fabric_version=0.68.1+1.19.3

# Mod Properties
mod_version=0.6.2
mod_version=0.6.4
maven_group=net.devtech
archives_base_name=arrp
# Dependencies
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
52 changes: 52 additions & 0 deletions src/main/java/net/devtech/arrp/api/SidedRRPCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.devtech.arrp.api;

import java.util.List;

import net.devtech.arrp.util.IrremovableList;

import net.minecraft.resource.LifecycledResourceManagerImpl;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Util;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

public interface SidedRRPCallback {
/**
* Register your resource pack at a higher priority than minecraft and mod resources, this is actually done by passing a reversed view of the
* resource pack list, such that List#add will actually add to the beginning of the list instead of the end.
*/
Event<SidedRRPCallback> BEFORE_VANILLA = EventFactory.createArrayBacked(SidedRRPCallback.class, r -> (type, rs) -> {
IrremovableList<ResourcePack> packs = new IrremovableList<>(rs, $ -> {
});
for(SidedRRPCallback callback : r) {
callback.insert(type, packs);
}
});

/**
* Register your resource pack at a lower priority than minecraft and mod resources. This is actually done by passing a view of the resource pack
* list, such that List#add will add to the end of the list, after default resource packs.
*
* If you want to override a vanilla resource
*/
Event<SidedRRPCallback> AFTER_VANILLA = EventFactory.createArrayBacked(SidedRRPCallback.class, r -> (type, rs) -> {
IrremovableList<ResourcePack> packs = new IrremovableList<>(rs, $ -> {
});
for(SidedRRPCallback callback : r) {
callback.insert(type, packs);
}
});

/**
* @see LifecycledResourceManagerImpl#LifecycledResourceManagerImpl(ResourceType, List)
*/
void insert(ResourceType type, List<ResourcePack> resources);

static Void INIT_ = Util.make(() -> {
BEFORE_VANILLA.register((type, resources) -> RRPCallback.BEFORE_VANILLA.invoker().insert(resources));
AFTER_VANILLA.register((type, resources) -> RRPCallback.AFTER_VANILLA.invoker().insert(resources));
return null;
});
}
Original file line number Diff line number Diff line change
@@ -199,8 +199,9 @@ public void mergeLang(Identifier identifier, JLang lang) {
this.langMergable.compute(identifier, (identifier1, lang1) -> {
if(lang1 == null) {
lang1 = new JLang();
JLang finalLang = lang1;
this.addLazyResource(ResourceType.CLIENT_RESOURCES, identifier, (pack, identifier2) -> {
return pack.addLang(identifier, lang);
return pack.addLang(identifier, finalLang);
});
}
lang1.getLang().putAll(lang.getLang());
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public JMultipart when(JWhen when) {
this.when = when;
return this;
}

public JMultipart addModel(JBlockModel model) {
this.apply.add(model);
return this;
4 changes: 4 additions & 0 deletions src/main/java/net/devtech/arrp/json/blockstate/JState.java
Original file line number Diff line number Diff line change
@@ -88,6 +88,10 @@ public static JMultipart multipart(JBlockModel... models) {
public static JWhen when() {
return new JWhen();
}

public static JWhen.StateBuilder whenStateBuilder() {
return new JWhen.StateBuilder();
}

@Override
public JState clone() {
68 changes: 59 additions & 9 deletions src/main/java/net/devtech/arrp/json/blockstate/JWhen.java
Original file line number Diff line number Diff line change
@@ -11,21 +11,68 @@
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import net.minecraft.state.property.Property;
import net.minecraft.util.Pair;

public class JWhen implements Cloneable {
private final List<Pair<String, String[]>> OR = new ArrayList<>();
private final List<List<Pair<String, String[]>>> state = new ArrayList<>();

/**
* @see JState#when()
*/
public JWhen() {}


@SafeVarargs
public final <T extends Comparable<T>> JWhen add(Property<T> property, T... values) {
String[] states = new String[values.length];
for(int i = 0; i < values.length; i++) {
states[i] = property.name(values[i]);
}

return this.add(property.getName(), states);
}

public JWhen add(String condition, String... states) {
this.OR.add(new Pair<>(condition, states));
this.state.add(List.of(new Pair<>(condition, states)));
return this;
}


public JWhen add(StateBuilder builder) {
this.state.add(List.copyOf(builder.state));
return this;
}

/**
* @see JState#whenStateBuilder()
*/
public static class StateBuilder implements Cloneable {
final List<Pair<String, String[]>> state = new ArrayList<>();

@SafeVarargs
public final <T extends Comparable<T>> StateBuilder add(Property<T> property, T... values) {
String[] states = new String[values.length];
for(int i = 0; i < values.length; i++) {
states[i] = property.name(values[i]);
}

return this.add(property.getName(), states);
}

public StateBuilder add(String condition, String... states) {
this.state.add(new Pair<>(condition, states));
return this;
}

@Override
protected StateBuilder clone() {
try {
return (StateBuilder) super.clone();
} catch(CloneNotSupportedException e) {
throw new InternalError(e);
}
}
}

@Override
public JWhen clone() {
try {
@@ -38,17 +85,20 @@ public JWhen clone() {
public static class Serializer implements JsonSerializer<JWhen> {
@Override
public JsonElement serialize(JWhen src, Type typeOfSrc, JsonSerializationContext context) {
if (src.OR.size() == 1) {
if (src.state.size() == 1) {
JsonObject json = new JsonObject();
Pair<String, String[]> val = src.OR.get(0);
json.addProperty(val.getLeft(), String.join("|", Arrays.asList(val.getRight())));
for(Pair<String, String[]> pair : src.state.get(0)) {
json.addProperty(pair.getLeft(), String.join("|", Arrays.asList(pair.getRight())));
}
return json;
} else {
JsonObject or = new JsonObject();
JsonArray array = new JsonArray();
for (Pair<String, String[]> val : src.OR) {
for(List<Pair<String, String[]>> pairs : src.state) {
JsonObject json = new JsonObject();
json.addProperty(val.getLeft(), String.join("|", Arrays.asList(val.getRight())));
for(Pair<String, String[]> pair : pairs) {
json.addProperty(pair.getLeft(), String.join("|", Arrays.asList(pair.getRight())));
}
array.add(json);
}
or.add("OR", array);
Original file line number Diff line number Diff line change
@@ -4,40 +4,36 @@
import java.util.List;
import java.util.concurrent.ExecutionException;

import com.google.common.collect.Lists;
import net.devtech.arrp.ARRP;
import net.devtech.arrp.api.RRPCallback;
import net.devtech.arrp.api.SidedRRPCallback;
import net.devtech.arrp.util.IrremovableList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.resource.LifecycledResourceManagerImpl;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;

@Mixin (LifecycledResourceManagerImpl.class)
@Mixin(LifecycledResourceManagerImpl.class)
public abstract class LifecycledResourceManagerImplMixin {
private static final Logger ARRP_LOGGER = LogManager.getLogger("ARRP/ReloadableResourceManagerImplMixin");

@ModifyVariable(method = "<init>",
at = @At (value = "HEAD"),
argsOnly = true)
private static List<ResourcePack> registerARRPs(List<ResourcePack> packs) throws ExecutionException, InterruptedException {

@ModifyVariable(method = "<init>", at = @At("HEAD"), argsOnly = true)
private static List<ResourcePack> registerARRPs(List<ResourcePack> packs, ResourceType type, List<ResourcePack> packs0) throws ExecutionException, InterruptedException {
List<ResourcePack> copy = new ArrayList<>(packs);
ARRP.waitForPregen();

ARRP_LOGGER.info("ARRP register - before vanilla");
List<ResourcePack> before = new ArrayList<>();
RRPCallback.BEFORE_VANILLA.invoker().insert(before);

before.addAll(packs);

SidedRRPCallback.BEFORE_VANILLA.invoker().insert(type, Lists.reverse(copy));

ARRP_LOGGER.info("ARRP register - after vanilla");
List<ResourcePack> after = new ArrayList<>();
RRPCallback.AFTER_VANILLA.invoker().insert(after);

before.addAll(after);


return before;
SidedRRPCallback.AFTER_VANILLA.invoker().insert(type, copy);
return copy;
}
}

0 comments on commit c13e0eb

Please sign in to comment.