-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
741a835
commit c1e3766
Showing
4 changed files
with
53 additions
and
28 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
42 changes: 31 additions & 11 deletions
42
src/main/java/net/earthcomputer/clientcommands/render/RenderSettings.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,32 +1,52 @@ | ||
package net.earthcomputer.clientcommands.render; | ||
|
||
import java.util.Set; | ||
import java.util.*; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.google.common.collect.Maps; | ||
|
||
import net.earthcomputer.clientcommands.EventManager; | ||
import net.minecraft.command.CommandBase; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.nbt.NBTUtil; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
public class RenderSettings { | ||
|
||
public static void registerEvents() { | ||
EventManager.addDisconnectExceptRelogListener(e -> { | ||
entitiesDisabled.clear(); | ||
filters.clear(); | ||
}); | ||
} | ||
|
||
private static Set<Class<? extends Entity>> entitiesDisabled = Sets.newIdentityHashSet(); | ||
private static Map<Class<? extends Entity>, List<Pair<NBTTagCompound, Boolean>>> filters = Maps.newHashMap(); | ||
|
||
public static boolean isEntityRenderingDisabled(Class<? extends Entity> clazz) { | ||
return entitiesDisabled.contains(clazz); | ||
} | ||
public static boolean shouldRender(Entity entity) { | ||
List<Pair<NBTTagCompound, Boolean>> filters = RenderSettings.filters.get(entity.getClass()); | ||
if (filters == null) | ||
return true; | ||
|
||
NBTTagCompound nbt = CommandBase.entityToNBT(entity); | ||
boolean shouldRender = true; | ||
|
||
public static void enableEntityRendering(Class<? extends Entity> clazz) { | ||
entitiesDisabled.remove(clazz); | ||
for (Pair<NBTTagCompound, Boolean> filter : filters) { | ||
if (NBTUtil.areNBTEquals(filter.getLeft(), nbt, true)) { | ||
shouldRender = filter.getRight(); | ||
} | ||
} | ||
|
||
return shouldRender; | ||
} | ||
|
||
public static void disableEntityRendering(Class<? extends Entity> clazz) { | ||
entitiesDisabled.add(clazz); | ||
public static void addRenderingFilter(Class<? extends Entity> clazz, NBTTagCompound filter, boolean shouldRender) { | ||
if (filter.hasNoTags() && shouldRender) { | ||
RenderSettings.filters.remove(clazz); | ||
return; | ||
} | ||
|
||
List<Pair<NBTTagCompound, Boolean>> filters = RenderSettings.filters.computeIfAbsent(clazz, k -> new ArrayList<>()); | ||
filters.removeIf(existingFilter -> NBTUtil.areNBTEquals(filter, existingFilter.getLeft(), true)); | ||
filters.add(Pair.of(filter, shouldRender)); | ||
} | ||
|
||
} |
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