-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid repeated creation of useless heavy objects
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
- Loading branch information
1 parent
e9c1844
commit 3aa5713
Showing
3 changed files
with
77 additions
and
31 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
64 changes: 64 additions & 0 deletions
64
Common/src/main/java/com/blamejared/contenttweaker/core/resource/RuntimePackResources.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,64 @@ | ||
package com.blamejared.contenttweaker.core.resource; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.PackResources; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.server.packs.metadata.MetadataSectionSerializer; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
final class RuntimePackResources implements PackResources { | ||
private final RuntimePack pack; | ||
|
||
RuntimePackResources(final RuntimePack pack) { | ||
this.pack = Objects.requireNonNull(pack); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public InputStream getRootResource(final String s) throws IOException { | ||
return this.pack.rootResource(s); | ||
} | ||
|
||
@Override | ||
public InputStream getResource(final PackType packType, final ResourceLocation resourceLocation) throws IOException { | ||
return this.pack.resource(packType, resourceLocation); | ||
} | ||
|
||
@Override | ||
public Collection<ResourceLocation> getResources(final PackType packType, final String s, final String s1, final int i, final Predicate<String> predicate) { | ||
return this.pack.resources(packType, s, s1, i, predicate); | ||
} | ||
|
||
@Override | ||
public boolean hasResource(final PackType packType, final ResourceLocation resourceLocation) { | ||
return this.pack.knowsResource(packType, resourceLocation); | ||
} | ||
|
||
@Override | ||
public Set<String> getNamespaces(final PackType packType) { | ||
return this.pack.namespaces(packType); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T> T getMetadataSection(final MetadataSectionSerializer<T> metadataSectionSerializer) throws IOException { | ||
return this.pack.metadataSection(metadataSectionSerializer); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.pack.name(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// Do not close resources: it gets managed automatically on shutdown | ||
} | ||
} |
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