Use java 8 collection functions
This commit is contained in:
parent
9675585891
commit
8581225da8
19 changed files with 45 additions and 142 deletions
|
@ -46,6 +46,7 @@ import net.minecraftforge.common.model.IModelState;
|
|||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -169,15 +170,7 @@ public class ForgeBlockStateV1 extends Marker
|
|||
}
|
||||
}
|
||||
|
||||
Iterator<List<Variant>> iter = v.submodels.values().iterator();
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
List<Variant> submodel = iter.next();
|
||||
|
||||
if (submodel == null)
|
||||
iter.remove();
|
||||
}
|
||||
v.submodels.values().removeIf(Objects::isNull);
|
||||
|
||||
if (v.textures != null)
|
||||
{
|
||||
|
|
|
@ -645,13 +645,7 @@ public final class ModelLoader extends ModelBakery
|
|||
//Remove any faces that use a null texture, this is for performance reasons, also allows some cool layering stuff.
|
||||
for (BlockPart part : newModel.getElements())
|
||||
{
|
||||
Iterator<Entry<EnumFacing, BlockPartFace>> itr = part.mapFaces.entrySet().iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
Entry<EnumFacing, BlockPartFace> entry = itr.next();
|
||||
if (removed.contains(entry.getValue().texture))
|
||||
itr.remove();
|
||||
}
|
||||
part.mapFaces.entrySet().removeIf(entry -> removed.contains(entry.getValue().texture));
|
||||
}
|
||||
|
||||
return new VanillaModelWrapper(location, newModel, uvlock, animation);
|
||||
|
|
|
@ -138,14 +138,7 @@ public final class MultiLayerModel implements IModel
|
|||
this.models = models;
|
||||
this.cameraTransforms = cameraTransforms;
|
||||
this.missing = missing;
|
||||
if(models.containsKey(Optional.empty()))
|
||||
{
|
||||
base = models.get(Optional.empty());
|
||||
}
|
||||
else
|
||||
{
|
||||
base = missing;
|
||||
}
|
||||
base = models.getOrDefault(Optional.empty(), missing);
|
||||
ImmutableMap.Builder<Optional<EnumFacing>, ImmutableList<BakedQuad>> quadBuilder = ImmutableMap.builder();
|
||||
quadBuilder.put(Optional.empty(), buildQuads(models, Optional.empty()));
|
||||
for(EnumFacing side: EnumFacing.values())
|
||||
|
@ -174,13 +167,9 @@ public final class MultiLayerModel implements IModel
|
|||
{
|
||||
return quads.get(Optional.ofNullable(side));
|
||||
}
|
||||
else if(!models.containsKey(Optional.of(layer)))
|
||||
{
|
||||
model = missing;
|
||||
}
|
||||
else
|
||||
{
|
||||
model = models.get(Optional.of(layer));
|
||||
model = models.getOrDefault(Optional.of(layer), missing);
|
||||
}
|
||||
// assumes that child model will handle this state properly. FIXME?
|
||||
return model.getQuads(state, side, rand);
|
||||
|
|
|
@ -360,13 +360,7 @@ public class BiomeDictionary
|
|||
//Internal implementation
|
||||
private static BiomeInfo getBiomeInfo(Biome biome)
|
||||
{
|
||||
BiomeInfo info = biomeInfoMap.get(biome.getRegistryName());
|
||||
if (info == null)
|
||||
{
|
||||
info = new BiomeInfo();
|
||||
biomeInfoMap.put(biome.getRegistryName(), info);
|
||||
}
|
||||
return info;
|
||||
return biomeInfoMap.computeIfAbsent(biome.getRegistryName(), k -> new BiomeInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -401,14 +401,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
|||
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/')))
|
||||
all.add(asm.getClassName());
|
||||
|
||||
Iterator<String> itr = all.iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
String cls = itr.next();
|
||||
if (!cls.startsWith("net/minecraft/") &&
|
||||
!cls.startsWith("net/minecraftforge/"))
|
||||
itr.remove();
|
||||
}
|
||||
all.removeIf(cls -> !cls.startsWith("net/minecraft/") && !cls.startsWith("net/minecraftforge/"));
|
||||
|
||||
log.debug("Preloading CrashReport Classes");
|
||||
Collections.sort(all); //Sort it because I like pretty output ;)
|
||||
|
|
|
@ -114,12 +114,7 @@ public enum CapabilityManager
|
|||
}
|
||||
final String capabilityName = type.getInternalName().replace('/', '.').intern();
|
||||
|
||||
List<Function<Capability<?>, Object>> list = callbacks.get(capabilityName);
|
||||
if (list == null)
|
||||
{
|
||||
list = Lists.newArrayList();
|
||||
callbacks.put(capabilityName, list);
|
||||
}
|
||||
List<Function<Capability<?>, Object>> list = callbacks.computeIfAbsent(capabilityName, k -> Lists.newArrayList());
|
||||
|
||||
if (entry.getObjectName().indexOf('(') > 0)
|
||||
{
|
||||
|
|
|
@ -108,12 +108,7 @@ public class ConfigManager
|
|||
for (ASMData target : data.getAll(Config.class.getName()))
|
||||
{
|
||||
String modid = (String)target.getAnnotationInfo().get("modid");
|
||||
Multimap<Config.Type, ASMData> map = asm_data.get(modid);
|
||||
if (map == null)
|
||||
{
|
||||
map = ArrayListMultimap.create();
|
||||
asm_data.put(modid, map);
|
||||
}
|
||||
Multimap<Config.Type, ASMData> map = asm_data.computeIfAbsent(modid, k -> ArrayListMultimap.create());
|
||||
|
||||
EnumHolder tholder = (EnumHolder)target.getAnnotationInfo().get("type");
|
||||
Config.Type type = tholder == null ? Config.Type.INSTANCE : Config.Type.valueOf(tholder.getValue());
|
||||
|
@ -164,9 +159,8 @@ public class ConfigManager
|
|||
{
|
||||
Class<?> cls = Class.forName(targ.getClassName(), true, mcl);
|
||||
|
||||
if (MOD_CONFIG_CLASSES.get(modid) == null)
|
||||
MOD_CONFIG_CLASSES.put(modid, Sets.<Class<?>>newHashSet());
|
||||
MOD_CONFIG_CLASSES.get(modid).add(cls);
|
||||
Set<Class<?>> modConfigClasses = MOD_CONFIG_CLASSES.computeIfAbsent(modid, k -> Sets.<Class<?>>newHashSet());
|
||||
modConfigClasses.add(cls);
|
||||
|
||||
String name = (String)targ.getAnnotationInfo().get("name");
|
||||
if (name == null)
|
||||
|
|
|
@ -435,7 +435,7 @@ public class CraftingHelper {
|
|||
throw new JsonSyntaxException("Or condition values must be an array of JsonObjects");
|
||||
children.add(CraftingHelper.getCondition(j.getAsJsonObject(), context));
|
||||
}
|
||||
return () -> children.stream().anyMatch(c -> c.getAsBoolean());
|
||||
return () -> children.stream().anyMatch(BooleanSupplier::getAsBoolean);
|
||||
});
|
||||
registerC("forge:and", (context, json) -> {
|
||||
JsonArray values = JsonUtils.getJsonArray(json, "values");
|
||||
|
@ -610,8 +610,8 @@ public class CraftingHelper {
|
|||
GameData.revert(RegistryManager.FROZEN, GameData.RECIPES, false);
|
||||
//ModContainer old = Loader.instance().activeModContainer();
|
||||
Loader.instance().setActiveModContainer(null);
|
||||
Loader.instance().getActiveModList().forEach((mod) -> loadFactories(mod));
|
||||
Loader.instance().getActiveModList().forEach((mod) -> loadRecipes(mod));
|
||||
Loader.instance().getActiveModList().forEach(CraftingHelper::loadFactories);
|
||||
Loader.instance().getActiveModList().forEach(CraftingHelper::loadRecipes);
|
||||
Loader.instance().setActiveModContainer(null);
|
||||
//reg.freeze();
|
||||
FMLCommonHandler.instance().resetClientRecipeBook();
|
||||
|
|
|
@ -108,13 +108,7 @@ public class CompoundDataFixer extends DataFixer
|
|||
|
||||
private List<IDataWalker> getWalkers(IFixType type)
|
||||
{
|
||||
List<IDataWalker> ret = walkers.get(type);
|
||||
if (ret == null)
|
||||
{
|
||||
ret = Lists.newArrayList();
|
||||
walkers.put(type, ret);
|
||||
}
|
||||
return ret;
|
||||
return walkers.computeIfAbsent(type, k -> Lists.newArrayList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,14 +67,6 @@ public class FakePlayerFactory
|
|||
|
||||
public static void unloadWorld(WorldServer world)
|
||||
{
|
||||
Iterator<Entry<GameProfile, FakePlayer>> itr = fakePlayers.entrySet().iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
Entry<GameProfile, FakePlayer> entry = itr.next();
|
||||
if (entry.getValue().world == world)
|
||||
{
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
fakePlayers.entrySet().removeIf(entry -> entry.getValue().world == world);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,13 +45,7 @@ public class ModFixs
|
|||
|
||||
public List<IFixableData> getFixes(IFixType type)
|
||||
{
|
||||
List<IFixableData> ret = this.fixes.get(type);
|
||||
if (ret == null)
|
||||
{
|
||||
ret = Lists.newArrayList();
|
||||
this.fixes.put(type, ret);
|
||||
}
|
||||
return ret;
|
||||
return this.fixes.computeIfAbsent(type, k -> Lists.newArrayList());
|
||||
}
|
||||
|
||||
public void registerFix(IFixType type, IFixableData fixer)
|
||||
|
|
|
@ -494,12 +494,7 @@ public class FMLDeobfuscatingRemapper extends Remapper {
|
|||
{
|
||||
return fType;
|
||||
}
|
||||
Map<String,String> newClassMap = fieldDescriptions.get(newType);
|
||||
if (newClassMap == null)
|
||||
{
|
||||
newClassMap = Maps.newHashMap();
|
||||
fieldDescriptions.put(newType, newClassMap);
|
||||
}
|
||||
Map<String, String> newClassMap = fieldDescriptions.computeIfAbsent(newType, k -> Maps.newHashMap());
|
||||
newClassMap.put(newName, fType);
|
||||
return fType;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -71,8 +71,8 @@ public class FMLModIdMappingEvent extends FMLEvent
|
|||
remaps.forEach((name, rm) ->
|
||||
{
|
||||
List<ModRemapping> tmp = Lists.newArrayList();
|
||||
rm.entrySet().forEach(e -> tmp.add(new ModRemapping(name, e.getKey(), e.getValue()[0], e.getValue()[1])));
|
||||
Collections.sort(tmp, (o1, o2) -> (o1.newId < o2.newId) ? -1 : ((o1.newId == o2.newId) ? 0 : 1));
|
||||
rm.forEach((key, value) -> tmp.add(new ModRemapping(name, key, value[0], value[1])));
|
||||
tmp.sort(Comparator.comparingInt(o -> o.newId));
|
||||
this.remaps.put(name, ImmutableList.copyOf(tmp));
|
||||
});
|
||||
this.keys = ImmutableSet.copyOf(this.remaps.keySet());
|
||||
|
|
|
@ -150,12 +150,7 @@ public class EventBus implements IEventExceptionHandler
|
|||
|
||||
event.getListenerList().register(busID, asm.getPriority(), listener);
|
||||
|
||||
ArrayList<IEventListener> others = listeners.get(target);
|
||||
if (others == null)
|
||||
{
|
||||
others = new ArrayList<IEventListener>();
|
||||
listeners.put(target, others);
|
||||
}
|
||||
ArrayList<IEventListener> others = listeners.computeIfAbsent(target, k -> new ArrayList<>());
|
||||
others.add(listener);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -284,16 +284,7 @@ public class EntityRegistry
|
|||
{
|
||||
for (Biome biome : biomes)
|
||||
{
|
||||
Iterator<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature).iterator();
|
||||
|
||||
while (spawns.hasNext())
|
||||
{
|
||||
SpawnListEntry entry = spawns.next();
|
||||
if (entry.entityClass == entityClass)
|
||||
{
|
||||
spawns.remove();
|
||||
}
|
||||
}
|
||||
biome.getSpawnableList(typeOfCreature).removeIf(entry -> entry.entityClass == entityClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -709,12 +709,7 @@ public class OreDictionary
|
|||
{
|
||||
hash |= ((ore.getItemDamage() + 1) << 16); // +1 so meta 0 is significant
|
||||
}
|
||||
List<Integer> ids = stackToId.get(hash);
|
||||
if (ids == null)
|
||||
{
|
||||
ids = Lists.newArrayList();
|
||||
stackToId.put(hash, ids);
|
||||
}
|
||||
List<Integer> ids = stackToId.computeIfAbsent(hash, k -> Lists.newArrayList());
|
||||
ids.add(id);
|
||||
//System.out.println(id + " " + getOreName(id) + " " + Integer.toHexString(hash) + " " + ore);
|
||||
}
|
||||
|
|
|
@ -469,7 +469,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
|||
this.min = from.min;
|
||||
*/
|
||||
this.aliases.clear();
|
||||
from.aliases.forEach((f, t) -> this.addAlias(f, t));
|
||||
from.aliases.forEach(this::addAlias);
|
||||
|
||||
this.ids.clear();
|
||||
this.names.clear();
|
||||
|
@ -517,7 +517,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
|||
|
||||
//Needs to be below add so that dummies are persisted
|
||||
this.dummies.clear();
|
||||
from.dummies.forEach(dummy -> this.addDummy(dummy));
|
||||
from.dummies.forEach(this::addDummy);
|
||||
|
||||
if (errored)
|
||||
throw new RuntimeException("One of more entry values did not copy to the correct id. Check log for details!");
|
||||
|
@ -718,9 +718,9 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
|||
{
|
||||
Snapshot ret = new Snapshot();
|
||||
this.ids.forEach((id, value) -> ret.ids.put(getKey(value), id));
|
||||
this.aliases.forEach((from, to) -> ret.aliases.put(from, to));
|
||||
this.blocked.forEach(id -> ret.blocked.add(id));
|
||||
this.dummies.forEach(name -> ret.dummied.add(name));
|
||||
ret.aliases.putAll(this.aliases);
|
||||
ret.blocked.addAll(this.blocked);
|
||||
ret.dummied.addAll(this.dummies);
|
||||
ret.overrides.putAll(getOverrideOwners());
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -469,20 +469,20 @@ public class GameData
|
|||
final Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps = Maps.newHashMap();
|
||||
final LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing = Maps.newLinkedHashMap();
|
||||
// Load the snapshot into the "STAGING" registry
|
||||
snapshot.entrySet().forEach(e ->
|
||||
snapshot.forEach((key, value) ->
|
||||
{
|
||||
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(e.getKey());
|
||||
remaps.put(e.getKey(), Maps.newLinkedHashMap());
|
||||
missing.put(e.getKey(), Maps.newHashMap());
|
||||
loadPersistentDataToStagingRegistry(RegistryManager.ACTIVE, STAGING, remaps.get(e.getKey()), missing.get(e.getKey()), e.getKey(), e.getValue(), clazz);
|
||||
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(key);
|
||||
remaps.put(key, Maps.newLinkedHashMap());
|
||||
missing.put(key, Maps.newHashMap());
|
||||
loadPersistentDataToStagingRegistry(RegistryManager.ACTIVE, STAGING, remaps.get(key), missing.get(key), key, value, clazz);
|
||||
});
|
||||
|
||||
snapshot.entrySet().forEach(e ->
|
||||
snapshot.forEach((key, value) ->
|
||||
{
|
||||
snapshot.get(e.getKey()).dummied.forEach(dummy ->
|
||||
value.dummied.forEach(dummy ->
|
||||
{
|
||||
Map<ResourceLocation, Integer> m = missing.get(e.getKey());
|
||||
ForgeRegistry<?> reg = STAGING.getRegistry(e.getKey());
|
||||
Map<ResourceLocation, Integer> m = missing.get(key);
|
||||
ForgeRegistry<?> reg = STAGING.getRegistry(key);
|
||||
|
||||
// Currently missing locally, we just inject and carry on
|
||||
if (m.containsKey(dummy))
|
||||
|
@ -493,20 +493,20 @@ public class GameData
|
|||
else if (isLocalWorld)
|
||||
{
|
||||
if (ForgeRegistry.DEBUG)
|
||||
FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", e.getKey(), dummy);
|
||||
FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", key, dummy);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The server believes this is a dummy block identity, but we seem to have one locally. This is likely a conflict
|
||||
// in mod setup - Mark this entry as a dummy
|
||||
int id = reg.getID(dummy);
|
||||
FMLLog.log.warn("Registry {}: The ID {} is currently locally mapped - it will be replaced with a dummy for this session", e.getKey(), id);
|
||||
FMLLog.log.warn("Registry {}: The ID {} is currently locally mapped - it will be replaced with a dummy for this session", key, id);
|
||||
reg.markDummy(dummy, id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
int count = missing.values().stream().mapToInt(e -> e.size()).sum();
|
||||
int count = missing.values().stream().mapToInt(Map::size).sum();
|
||||
if (count > 0)
|
||||
{
|
||||
FMLLog.log.debug("There are {} mappings missing - attempting a mod remap", count);
|
||||
|
@ -635,10 +635,10 @@ public class GameData
|
|||
if (active == null)
|
||||
return; // We've already asked the user if they wish to continue. So if the reg isnt found just assume the user knows and accepted it.
|
||||
ForgeRegistry<T> _new = to.getRegistry(name, RegistryManager.ACTIVE);
|
||||
snap.aliases.forEach((f, t) -> _new.addAlias(f, t));
|
||||
snap.blocked.forEach(id -> _new.block(id));
|
||||
snap.aliases.forEach(_new::addAlias);
|
||||
snap.blocked.forEach(_new::block);
|
||||
// Load current dummies BEFORE the snapshot is loaded so that add() will remove from the list.
|
||||
snap.dummied.forEach(key -> _new.addDummy(key));
|
||||
snap.dummied.forEach(_new::addDummy);
|
||||
_new.loadIds(snap.ids, snap.overrides, missing, remaps, active, name);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,12 +83,7 @@ public class ForgeTimeTracker {
|
|||
// race, exit
|
||||
return;
|
||||
}
|
||||
int[] timings = tileEntityTimings.get(tileEntity);
|
||||
if (timings == null)
|
||||
{
|
||||
timings = new int[101];
|
||||
tileEntityTimings.put(tileEntity, timings);
|
||||
}
|
||||
int[] timings = tileEntityTimings.computeIfAbsent(tileEntity, k -> new int[101]);
|
||||
int idx = timings[100] = (timings[100] + 1) % 100;
|
||||
timings[idx] = (int) (nanoTime - timing);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue