use of gnu.trove.map.hash.TObjectIntHashMap in project Charset by CharsetMC.
the class BlockStacks method getDrops.
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, @Nullable TileEntity te, int fortune, boolean silkTouch) {
if (te instanceof TileEntityStacks) {
TObjectIntMap<ItemMaterial> materials = new TObjectIntHashMap<>();
for (ItemMaterial material : ((TileEntityStacks) te).stacks) {
materials.adjustOrPutValue(material, 1, 1);
}
for (ItemMaterial material : materials.keySet()) {
ItemStack stack = material.getStack();
if (!stack.isEmpty()) {
int count = materials.get(material);
for (int i = 0; i < count; i += stack.getMaxStackSize()) {
stack = stack.copy();
stack.setCount(Math.min(count - i, stack.getMaxStackSize()));
drops.add(stack);
}
}
}
}
}
use of gnu.trove.map.hash.TObjectIntHashMap in project Tropicraft by Tropicraft.
the class ItemFishBucket method addInformation.
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flagIn) {
NBTTagList fishList = getFishList(stack);
TObjectIntMap<String> fishCounts = new TObjectIntHashMap<>();
for (int i = 0; i < fishList.tagCount(); i++) {
// TODO this is awful
String color = EntityTropicalFish.names[fishList.getCompoundTagAt(i).getInteger("Color")];
fishCounts.adjustOrPutValue(color, 1, 1);
}
for (String s : fishCounts.keySet()) {
String line = s;
int count = fishCounts.get(s);
if (count > 1) {
line += " (x" + count + ")";
}
tooltip.add(line);
}
super.addInformation(stack, world, tooltip, flagIn);
}
use of gnu.trove.map.hash.TObjectIntHashMap in project OpenTripPlanner by opentripplanner.
the class PointSet method buildIdIndexMapIfNeeded.
/**
* Build the ID - Index map if needed.
*/
private synchronized void buildIdIndexMapIfNeeded() {
// by this method in another thread while this instantiation was blocked.
if (idIndexMap == null) {
// make a local object, don't expose to public view until it's built
TObjectIntMap idIndexMap = new TObjectIntHashMap<String>(this.capacity, 1f, -1);
for (int i = 0; i < this.capacity; i++) {
if (ids[i] != null) {
if (idIndexMap.containsKey(ids[i])) {
LOG.error("Duplicate ID {} in pointset.", ids[i]);
} else {
idIndexMap.put(ids[i], i);
}
}
}
// now expose to public view; reference assignment is an atomic operation
this.idIndexMap = idIndexMap;
}
}
use of gnu.trove.map.hash.TObjectIntHashMap in project DynamicSurroundings by OreCruncher.
the class SoundEngine method diagnostics.
/**
* Event handler for the diagnostic event.
*
* @param event
* Event that has been raised.
*/
@SubscribeEvent(priority = EventPriority.LOW)
public void diagnostics(final DiagnosticEvent.Gather event) {
final int soundCount = currentSoundCount();
final int maxCount = maxSounds;
event.output.add("SoundSystem: " + soundCount + "/" + maxCount);
final TObjectIntHashMap<ResourceLocation> counts = new TObjectIntHashMap<>();
final Iterator<Entry<String, ISound>> iterator = getPlayingSounds().entrySet().iterator();
while (iterator.hasNext()) {
final Entry<String, ISound> entry = iterator.next();
final ISound isound = entry.getValue();
counts.adjustOrPutValue(isound.getSound().getSoundLocation(), 1, 1);
}
final List<String> results = new ArrayList<>();
final TObjectIntIterator<ResourceLocation> itr = counts.iterator();
while (itr.hasNext()) {
itr.advance();
results.add(String.format(TextFormatting.GOLD + "%s: %d", itr.key().toString(), itr.value()));
}
Collections.sort(results);
event.output.addAll(results);
}
use of gnu.trove.map.hash.TObjectIntHashMap in project BuildCraft by BuildCraft.
the class WorkbenchCrafting method hasExactStacks.
private boolean hasExactStacks() {
TObjectIntMap<ItemStackKey> required = new TObjectIntHashMap<>(getSizeInventory());
for (int s = 0; s < getSizeInventory(); s++) {
ItemStack req = invBlueprint.getStackInSlot(s);
if (!req.isEmpty()) {
int count = req.getCount();
if (count != 1) {
req = req.copy();
req.setCount(1);
}
ItemStackKey key = new ItemStackKey(req);
required.adjustOrPutValue(key, count, count);
}
}
return required.forEachEntry((stack, count) -> {
ArrayStackFilter filter = new ArrayStackFilter(stack.baseStack);
ItemStack inInventory = invMaterials.extract(filter, count, count, true);
return !inInventory.isEmpty() && inInventory.getCount() == count;
});
}
Aggregations