Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite <init> of ResourceLocation and add ResourceLocationInitEvent #95

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions patches/minecraft/net/minecraft/util/ResourceLocation.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--- before/net/minecraft/util/ResourceLocation.java
+++ after/net/minecraft/util/ResourceLocation.java
@@ -9,6 +9,8 @@
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.Locale;
+import java.util.Objects;
+
import org.apache.commons.lang3.Validate;

public class ResourceLocation implements Comparable<ResourceLocation>
@@ -18,9 +20,7 @@

protected ResourceLocation(int p_i45928_1_, String... p_i45928_2_)
{
- this.field_110626_a = org.apache.commons.lang3.StringUtils.isEmpty(p_i45928_2_[0]) ? "minecraft" : p_i45928_2_[0].toLowerCase(Locale.ROOT);
- this.field_110625_b = p_i45928_2_[1].toLowerCase(Locale.ROOT);
- Validate.notNull(this.field_110625_b);
+ this(org.apache.commons.lang3.StringUtils.isEmpty(p_i45928_2_[0]) ? "minecraft" : p_i45928_2_[0].toLowerCase(Locale.ROOT), Objects.requireNonNull(p_i45928_2_[1].toLowerCase(Locale.ROOT), "the path of ResourceLocation is non-null!"));
}

public ResourceLocation(String p_i1293_1_)
@@ -30,7 +30,9 @@

public ResourceLocation(String p_i1292_1_, String p_i1292_2_)
{
- this(0, p_i1292_1_, p_i1292_2_);
+ String[] s = net.minecraftforge.common.ForgeHooks.onResourceLocationInit(p_i1292_1_, p_i1292_2_);
+ this.field_110626_a = s[0];
+ this.field_110625_b = s[1];
}

public static String[] func_177516_a(String p_177516_0_)
8 changes: 8 additions & 0 deletions src/main/java/net/minecraftforge/common/ForgeHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.AdvancementEvent;
import net.minecraftforge.event.utils.ResourceLocationInitEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.fluids.IFluidBlock;
Expand Down Expand Up @@ -1487,6 +1488,13 @@ public static boolean onFarmlandTrample(World world, BlockPos pos, IBlockState s
return false;
}

public static String[] onResourceLocationInit(String namespace, String path){
ResourceLocationInitEvent evt = new ResourceLocationInitEvent(namespace, path);
MinecraftForge.EVENT_BUS.post(evt);
return new String[]{evt.getNamespace(), evt.getPath()};
}


private static final Map<DataSerializer<?>, DataSerializerEntry> serializerEntries = GameData.getSerializerMap();
private static final ForgeRegistry<DataSerializerEntry> serializerRegistry = (ForgeRegistry<DataSerializerEntry>) ForgeRegistries.DATA_SERIALIZERS;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.minecraftforge.event.utils;

import net.minecraftforge.fml.common.eventhandler.Event;

/**
* ResourceLocationInitEvent is fired whenever a {@link net.minecraft.util.ResourceLocation} is to be init.
* <br>
* This event is not {@link net.minecraftforge.fml.common.eventhandler.Cancelable}. <br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.<br>
**/
public class ResourceLocationInitEvent extends Event {
private String namespace;
private String path;
public ResourceLocationInitEvent(String namespace, String path){
this.namespace = namespace;
this.path = path;
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}
}
Loading