Skip to content

Commit

Permalink
Optimize stats reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
Runemoro committed Jun 7, 2018
1 parent a49ed36 commit 0f1cceb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ String fullVersion = version
if (System.getenv("TRAVIS_BUILD_NUMBER") != null) {
fullVersion += "+${System.getenv("TRAVIS_BUILD_NUMBER")}"
} else {
fullVersion += "+UNOFFICIAL"
fullVersion += "+SNAPSHOT"
}
String jarVersion = fullVersion.replace("+", "-") // Github/Travis doesn't seem to support + in filenames

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ private void writePaletteNBT(Chunk chunk, World worldIn, NBTTagCompound nbt, Cal
ExtendedBlockStorage[] ignored0, NBTTagList ignored1, boolean ignored2, ExtendedBlockStorage[] ignored3, int ignored4, int ignored5,
ExtendedBlockStorage extendedBlockStorage, NBTTagCompound storageNBT, byte[] blocks, NibbleArray data, NibbleArray add) {
int[] palette = ((IPatchedBlockStateContainer) extendedBlockStorage.getData()).getTemporaryPalette();
storageNBT.setIntArray("Palette", palette);
if (palette != null) storageNBT.setIntArray("Palette", palette);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.dimdev.vanillafix.idlimit.mixins;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
Expand All @@ -21,10 +20,7 @@
import org.spongepowered.asm.mixin.Shadow;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

/** Rewrite most of the class to support an unlimited number of IDs (map rather than array). **/
@Mixin(value = StatList.class, priority = 500)
Expand Down Expand Up @@ -123,11 +119,11 @@ private static void initCraftableStats() {
private static void initItemDepleteStats() {
for (Item item : Item.REGISTRY) {
if (item != null && getItemName(item) != null && item.isDamageable()) {
StatCrafting stat = (new StatCrafting(
StatCrafting stat = new StatCrafting(
"stat.breakItem.",
getItemName(item),
new TextComponentTranslation("stat.breakItem", new ItemStack(item).getTextComponent()),
item));
item);

VF_OBJECT_BREAK_STATS.put(item, stat);
stat.registerStat();
Expand Down Expand Up @@ -170,24 +166,30 @@ public static void reinit() { // Forge
USE_ITEM_STATS.clear();
MINE_BLOCK_STATS.clear();

// TODO: Optimize this, it hangs on server shutdown for a few seconds with
ALL_STATS.removeAll(VF_BLOCK_STATS.values());
ALL_STATS.removeAll(VF_CRAFTS_STATS.values());
ALL_STATS.removeAll(VF_OBJECT_USE_STATS.values());
ALL_STATS.removeAll(VF_OBJECT_BREAK_STATS.values());
ALL_STATS.removeAll(VF_OBJECTS_PICKED_UP_STATS.values());
ALL_STATS.removeAll(VF_OBJECTS_DROPPED_STATS.values());
HashSet<StatBase> knownStats = new HashSet<>();
knownStats.addAll(VF_BLOCK_STATS.values());
knownStats.addAll(VF_CRAFTS_STATS.values());
knownStats.addAll(VF_OBJECT_USE_STATS.values());
knownStats.addAll(VF_OBJECT_BREAK_STATS.values());
knownStats.addAll(VF_OBJECTS_PICKED_UP_STATS.values());
knownStats.addAll(VF_OBJECTS_DROPPED_STATS.values());

List<StatBase> unknownStats = new ArrayList<>();
for (StatBase stat : ALL_STATS) {
if (!knownStats.contains(stat)) {
unknownStats.add(stat);
}
}

VF_BLOCK_STATS.clear();
VF_CRAFTS_STATS.clear();
VF_OBJECT_USE_STATS.clear();
VF_OBJECT_BREAK_STATS.clear();
VF_OBJECTS_PICKED_UP_STATS.clear();
VF_OBJECTS_DROPPED_STATS.clear();

List<StatBase> stats = Lists.newArrayList(ALL_STATS);
ALL_STATS.clear();
for (StatBase stat : stats) stat.registerStat();

for (StatBase unknownStat : unknownStats) unknownStat.registerStat();

init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Pseudo
@Mixin(GuiUtil.class)
public class MixinGuiUtil {
@Inject(method = "renderTiledTextureAtlas", at = @At("HEAD"))
@Inject(method = "renderTiledTextureAtlas", at = @At("HEAD"), remap = false)
private static void onRenderTiledTextureAtlas(int x, int y, int width, int height, float depth, TextureAtlasSprite sprite, boolean upsideDown, CallbackInfo ci) {
((IPatchedTextureAtlasSprite) sprite).markNeedsAnimationUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
@Pseudo
@Mixin(RenderUtil.class)
public class MixinRenderUtil {
@Inject(method = "putTexturedQuad(Lnet/minecraft/client/renderer/BufferBuilder;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;DDDDDDLnet/minecraft/util/EnumFacing;IIIIIIZZ)V", at = @At("HEAD"))
@Inject(method = "putTexturedQuad(Lnet/minecraft/client/renderer/BufferBuilder;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;DDDDDDLnet/minecraft/util/EnumFacing;IIIIIIZZ)V", at = @At("HEAD"), remap = false)
private static void onRenderQuad(BufferBuilder renderer, TextureAtlasSprite sprite, double x, double y, double z, double w, double h, double d, EnumFacing face, int r, int g, int b, int a, int light1, int light2, boolean flowing, boolean flipHorizontally, CallbackInfo ci) {
((IPatchedTextureAtlasSprite) sprite).markNeedsAnimationUpdate();
}

@Inject(method = "putRotatedQuad(Lnet/minecraft/client/renderer/BufferBuilder;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;DDDDDLnet/minecraft/util/EnumFacing;IIIIIIZ)V", at = @At("HEAD"))
@Inject(method = "putRotatedQuad(Lnet/minecraft/client/renderer/BufferBuilder;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;DDDDDLnet/minecraft/util/EnumFacing;IIIIIIZ)V", at = @At("HEAD"), remap = false)
private static void onRenderRotatedQuad(BufferBuilder renderer, TextureAtlasSprite sprite, double x, double y, double z, double w, double d, EnumFacing rotation, int r, int g, int b, int a, int light1, int light2, boolean flowing, CallbackInfo ci) {
((IPatchedTextureAtlasSprite) sprite).markNeedsAnimationUpdate();
}
Expand Down

0 comments on commit 0f1cceb

Please sign in to comment.