-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove dim data fix jar in jar. fix dynamic dimension not removed fro…
…m registry
- Loading branch information
Showing
10 changed files
with
142 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
q_misc_util/src/main/java/qouteall/q_misc_util/ducks/IEMappedRegistry2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package qouteall.q_misc_util.ducks; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
// TODO merge it with IEMappedRegistry | ||
public interface IEMappedRegistry2 { | ||
public boolean ip_forceRemove(ResourceLocation id); | ||
} |
106 changes: 88 additions & 18 deletions
106
q_misc_util/src/main/java/qouteall/q_misc_util/mixin/MixinMappedRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,95 @@ | ||
package qouteall.q_misc_util.mixin; | ||
|
||
import com.mojang.serialization.Lifecycle; | ||
import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
import it.unimi.dsi.fastutil.objects.ObjectList; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.MappedRegistry; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import qouteall.q_misc_util.ducks.IEMappedRegistry2; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Mixin(MappedRegistry.class) | ||
public class MixinMappedRegistry<T> { | ||
// @ModifyVariable( | ||
// method = "registerMapping(ILnet/minecraft/resources/ResourceKey;Ljava/lang/Object;Lcom/mojang/serialization/Lifecycle;Z)Lnet/minecraft/core/Holder;", | ||
// at = @At("HEAD"), | ||
// argsOnly = true, | ||
// index = 4 | ||
// ) | ||
// private Lifecycle modifyLifecycle( | ||
// Lifecycle value, | ||
// int i, ResourceKey<T> resourceKey, T object, Lifecycle lifecycle, boolean bl | ||
// ) { | ||
// if (MiscGlobals.stableNamespaces.contains(resourceKey.location().getNamespace())) { | ||
// return Lifecycle.stable(); | ||
// } | ||
// else { | ||
// return lifecycle; | ||
// } | ||
// } | ||
public abstract class MixinMappedRegistry<T> implements IEMappedRegistry2 { | ||
@Shadow | ||
@Final | ||
private Map<ResourceLocation, Holder.Reference<T>> byLocation; | ||
|
||
@Shadow | ||
@Final | ||
private static Logger LOGGER; | ||
|
||
@Shadow | ||
public abstract @Nullable T byId(int id); | ||
|
||
@Shadow | ||
@Final | ||
private ObjectList<Holder.Reference<T>> byId; | ||
|
||
@Shadow | ||
@Final | ||
private Object2IntMap<T> toId; | ||
|
||
@Shadow | ||
@Final | ||
private Map<ResourceKey<T>, Holder.Reference<T>> byKey; | ||
|
||
@Shadow | ||
@Final | ||
private ResourceKey<? extends Registry<T>> key; | ||
|
||
@Shadow | ||
@Final | ||
private Map<T, Holder.Reference<T>> byValue; | ||
|
||
@Shadow | ||
@Final | ||
private Map<T, Lifecycle> lifecycles; | ||
|
||
@Shadow | ||
private @Nullable List<Holder.Reference<T>> holdersInOrder; | ||
|
||
@Override | ||
public boolean ip_forceRemove(ResourceLocation id) { | ||
Holder.Reference<T> holder = byLocation.remove(id); | ||
|
||
if (holder == null) { | ||
return false; | ||
} | ||
|
||
T value = holder.value(); | ||
|
||
if (value == null) { | ||
LOGGER.error("[ImmPtl] missing value in holder {}", holder); | ||
return false; | ||
} | ||
|
||
int intId = toId.getInt(value); | ||
|
||
if (intId == -1) { | ||
LOGGER.error("[ImmPtl] missing integer id for {}", value); | ||
} | ||
else { | ||
toId.removeInt(value); | ||
byId.set(intId, null); | ||
} | ||
|
||
byKey.remove(ResourceKey.create(key, id)); | ||
byValue.remove(value); | ||
lifecycles.remove(value); | ||
|
||
holdersInOrder = null; | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters